From 729de62012692f3ee99b69a6fe9ca8b9a642b641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Mon, 11 May 2026 15:51:53 +0200 Subject: [PATCH] test: add keywordSyntax and isAllUpper tests Adds unit tests for command keyword parsing and string casing. Also removes the unused `history_path` field from the `Terminal` struct. --- src/agent/Command.zig | 20 ++++++++++++++++++++ src/agent/Terminal.zig | 2 -- src/string.zig | 12 ++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/agent/Command.zig b/src/agent/Command.zig index 61240d1a..47aa8263 100644 --- a/src/agent/Command.zig +++ b/src/agent/Command.zig @@ -620,6 +620,26 @@ test "parse GOTO missing url" { try std.testing.expect(cmd == .natural_language); } +test "keywordSyntax: argful keyword without args returns its shape" { + const k = keywordSyntax("CLICK").?; + try std.testing.expectEqualStrings("CLICK", k.name); + try std.testing.expectEqualStrings("''", k.args.?); +} + +test "keywordSyntax: trailing whitespace tolerated" { + try std.testing.expect(keywordSyntax(" GOTO ") != null); +} + +test "keywordSyntax: argless keyword returns null" { + try std.testing.expect(keywordSyntax("LOGIN") == null); + try std.testing.expect(keywordSyntax("TREE") == null); +} + +test "keywordSyntax: unknown word returns null" { + try std.testing.expect(keywordSyntax("FOOBAR") == null); + try std.testing.expect(keywordSyntax("click the button") == null); +} + test "parse CLICK quoted" { const cmd = parse("CLICK \"Login\""); try std.testing.expectEqualStrings("Login", cmd.click); diff --git a/src/agent/Terminal.zig b/src/agent/Terminal.zig index 04e402ee..4c7d01e2 100644 --- a/src/agent/Terminal.zig +++ b/src/agent/Terminal.zig @@ -38,7 +38,6 @@ fn atLeast(level: Verbosity, min: Verbosity) bool { } allocator: std.mem.Allocator, -history_path: ?[:0]const u8, verbosity: Verbosity, /// Non-null in REPL mode. Doubles as scratch arena for the pretty-printer /// (reset per `printToolResult`, so memory is bounded by the largest single @@ -90,7 +89,6 @@ pub fn init(allocator: std.mem.Allocator, history_path: ?[:0]const u8, verbosity const stderr_is_tty = std.posix.isatty(std.posix.STDERR_FILENO); return .{ .allocator = allocator, - .history_path = history_path, .verbosity = verbosity, .repl_arena = if (is_repl) std.heap.ArenaAllocator.init(allocator) else null, .stderr_is_tty = stderr_is_tty, diff --git a/src/string.zig b/src/string.zig index a04704dc..03c35bc9 100644 --- a/src/string.zig +++ b/src/string.zig @@ -340,6 +340,18 @@ fn asUint(comptime string: anytype) std.meta.Int( } const testing = @import("testing.zig"); + +test "isAllUpper" { + try testing.expectEqual(false, isAllUpper("")); + try testing.expectEqual(true, isAllUpper("GOTO")); + try testing.expectEqual(true, isAllUpper("ACCEPT_COOKIES")); + try testing.expectEqual(true, isAllUpper("X1")); + try testing.expectEqual(true, isAllUpper("_")); + try testing.expectEqual(false, isAllUpper("Goto")); + try testing.expectEqual(false, isAllUpper("goto")); + try testing.expectEqual(false, isAllUpper("GO TO")); +} + test "String" { const other_short = try String.init(undefined, "other_short", .{}); const other_long = try String.init(testing.allocator, "other_long" ** 100, .{});