initial commit [141.14.140.180,mike]

This commit is contained in:
mike committed 2026-10-22 13:21:28 +02:00
commit 156bb18c91
50 files changed
+13466

No files matched your search

+176
View File
@@ -0,0 +1,176 @@
package schema
import (
"strings"
"testing"
)
func TestEmbeddedSchema(t *testing.T) {
s, err := Embedded()
if err != nil {
t.Fatal(err)
}
if len(s.Options) < 150 {
t.Fatalf("only %d options in embedded schema", len(s.Options))
}
for _, o := range s.Options {
if o.Kind == "" {
t.Errorf("%s has no kind", o.Key)
}
if o.Category == "" {
t.Errorf("%s has no category", o.Key)
}
if (o.Kind == KindEnum || o.Kind == KindChoice) && len(o.Values) == 0 {
t.Errorf("%s has no values", o.Key)
}
if o.Kind == KindEnum && o.Default() != "" && !contains(o.Values, o.Default()) {
t.Errorf("%s: default %q is not a valid value", o.Key, o.Default())
}
if !o.Repeatable && o.Default() != "" {
if err := o.Validate(o.Default()); err != nil {
t.Errorf("%s: default %q does not validate: %v", o.Key, o.Default(), err)
}
}
}
for _, key := range []string{"font-family", "keybind", "palette", "theme", "cursor-style", "shell-integration-features"} {
if s.Lookup(key) == nil {
t.Errorf("missing %s", key)
}
}
}
func TestParseDocs(t *testing.T) {
out := `# Font families.
#
# Can be repeated.
font-family =
font-family-bold =
# The palette.
palette = 0=#000000
palette = 1=#ff0000
selection-word-chars = '"
`
got := ParseDocs(out)
if len(got) != 4 {
t.Fatalf("got %d entries", len(got))
}
if got[0].Doc != "Font families.\n\nCan be repeated." {
t.Errorf("doc = %q", got[0].Doc)
}
if got[1].Doc != got[0].Doc {
t.Errorf("font-family-bold should share the font-family docs")
}
if len(got[2].Defaults) != 2 {
t.Errorf("palette defaults = %v", got[2].Defaults)
}
if got[3].Defaults[0] != " \t'\"" {
t.Errorf("leading whitespace must be kept, got %q", got[3].Defaults[0])
}
}
func TestValidate(t *testing.T) {
opt := func(k Kind) *Option {
return &Option{Kind: k, Values: []string{"cell-foreground"}, Flags: []string{"cursor", "sudo"}}
}
cases := []struct {
kind Kind
value string
ok bool
}{
{KindBool, "true", true},
{KindBool, "yes", false},
{KindColor, "#1e1e2e", true},
{KindColor, "fff", true},
{KindColor, "dark slate gray", true},
{KindColor, "cell-foreground", true},
{KindColor, "#12345", false},
{KindMetric, "-10%", true},
{KindMetric, "2", true},
{KindMetric, "1.5", false},
{KindDuration, "750ms", true},
{KindDuration, "1h 30m", true},
{KindDuration, "0", true},
{KindDuration, "5", false},
{KindPadding, "2,4", true},
{KindPadding, "a", false},
{KindFlags, "no-cursor,sudo", true},
{KindFlags, "false", true},
{KindFlags, "bogus", false},
{KindKeybind, "ctrl+==reset_font_size", true},
{KindKeybind, "clear", true},
{KindKeybind, "ctrl+a", false},
{KindPalette, "4=#89b4fa", true},
{KindPalette, "256=#000000", false},
{KindFloat, "0.5", true},
{KindFloat, "x", false},
}
for _, c := range cases {
err := opt(c.kind).Validate(c.value)
if (err == nil) != c.ok {
t.Errorf("%s %q: err = %v, want ok=%v", c.kind, c.value, err, c.ok)
}
}
}
func TestFlags(t *testing.T) {
o := &Option{Kind: KindFlags, Flags: []string{"cursor", "sudo", "title"}, Defaults: []string{"cursor,no-sudo,title"}}
st := o.ParseFlags("no-cursor")
if st["cursor"] || st["sudo"] || !st["title"] {
t.Fatalf("state = %v", st)
}
if got := o.FormatFlags(st); got != "no-cursor,no-sudo,title" {
t.Fatalf("format = %q", got)
}
}
func TestSplitKeybind(t *testing.T) {
cases := map[string][2]string{
"ctrl+a=new_tab": {"ctrl+a", "new_tab"},
"==text:=": {"=", "text:="},
"ctrl+==text:=hello": {"ctrl+=", "text:=hello"},
"super+shift+,=reload": {"super+shift+,", "reload"},
"ctrl+a>n=new_window": {"ctrl+a>n", "new_window"},
"§=goto_split:next": {"§", "goto_split:next"},
}
for in, want := range cases {
tr, ac := SplitKeybind(in)
if tr != want[0] || ac != want[1] {
t.Errorf("SplitKeybind(%q) = %q, %q", in, tr, ac)
}
}
}
func TestCategoriesCoverEverything(t *testing.T) {
s, _ := Embedded()
cats := s.Categories()
total := 0
for _, c := range cats {
total += len(s.InCategory(c))
}
if total != len(s.Options) {
t.Fatalf("categories hold %d of %d options", total, len(s.Options))
}
if !strings.Contains(strings.Join(cats, ","), CatFonts) {
t.Fatal("missing Fonts category")
}
}
func TestPlatformDetection(t *testing.T) {
s, _ := Embedded()
want := map[string]string{
"keybind": "",
"fullscreen": "",
"window-theme": "",
"window-step-resize": "macOS",
"undo-timeout": "macOS",
"window-subtitle": "Linux",
"macos-icon": "macOS",
"gtk-wide-tabs": "Linux",
}
for key, p := range want {
if o := s.Lookup(key); o == nil || o.Platform != p {
t.Errorf("%s: platform = %q, want %q", key, o.Platform, p)
}
}
}