package main import ( "slices" "testing" ) // The shape of the compatibility table and its handlers in Config.zig 1.4. const compatZig = `pub const compatibility = std.StaticStringMap( cli.CompatibilityHandler(Config), ).initComptime(&.{ // Ghostty 1.4 renamed ` + "`scrollback-limit`" + `. .{ "scrollback-limit", cli.compatibilityRenamed(Config, "scrollback-limit-bytes") }, .{ "bold-is-bright", compatBoldIsBright }, .{ "copy-on-select", compatCopyOnSelect }, }); fn compatBoldIsBright( self: *Config, value_: ?[]const u8, ) bool { const isset = cli.args.parseBool(value_ orelse "t") catch return false; if (isset) { self.@"bold-color" = .bright; } return true; } fn compatCopyOnSelect( self: *Config, value: ?[]const u8, ) bool { if (std.mem.eql(u8, value orelse "", "true")) { self.@"copy-on-select" = .clipboard; return true; } if (std.mem.eql(u8, value orelse "", "false")) { self.@"copy-on-select" = .none; return true; } return false; } ` func TestParseCompat(t *testing.T) { got := parseCompat(compatZig) if len(got) != 3 { t.Fatalf("%d entries, want 3: %+v", len(got), got) } if c := got[0]; c.Key != "scrollback-limit" || c.RenamedTo != "scrollback-limit-bytes" { t.Errorf("renamed: %+v", c) } if c := got[1]; c.Key != "bold-is-bright" || !slices.Equal(c.Sets, []string{"bold-color"}) || len(c.Values) != 0 { t.Errorf("replaced: %+v", c) } if c := got[2]; !slices.Equal(c.Values, []string{"true", "false"}) || len(c.Sets) != 0 { t.Errorf("old values: %+v", c) } } func TestLimitType(t *testing.T) { o := optionForType("Limit(usize, 64 * 1024 * 1024)", nil) if o.Kind != "int" || !slices.Equal(o.Values, []string{"unlimited"}) || o.Min == nil || *o.Min != 0 { t.Errorf("Limit: %+v", o) } }