mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-24 01:08:10 +02:00
Port test
This commit is contained in:
@@ -16,26 +16,34 @@ var _ = fmt.Print
|
|||||||
func TestConfigParsing(t *testing.T) {
|
func TestConfigParsing(t *testing.T) {
|
||||||
tdir := t.TempDir()
|
tdir := t.TempDir()
|
||||||
conf_file := filepath.Join(tdir, "a.conf")
|
conf_file := filepath.Join(tdir, "a.conf")
|
||||||
os.Mkdir(filepath.Join(tdir, "sub"), 0o700)
|
if err := os.Mkdir(filepath.Join(tdir, "sub"), 0o700); err != nil {
|
||||||
os.WriteFile(conf_file, []byte(
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
w := func(path string, data []byte) {
|
||||||
|
if err := os.WriteFile(path, data, 0o600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w(conf_file, []byte(
|
||||||
`error main
|
`error main
|
||||||
# igno
|
# igno
|
||||||
\re me
|
\re me
|
||||||
a one
|
a one
|
||||||
#: other
|
#: other
|
||||||
include
|
include
|
||||||
\ sub/b.conf
|
\ sub/b.conf
|
||||||
b
|
b x
|
||||||
include non-exis
|
include non-exis
|
||||||
\tent
|
\tent
|
||||||
globin
|
globin
|
||||||
\clude sub/c?.c
|
\clude sub/c?.c
|
||||||
\onf
|
\onf
|
||||||
`), 0o600)
|
badline
|
||||||
os.WriteFile(filepath.Join(tdir, "sub/b.conf"), []byte("incb cool\ninclude a.conf"), 0o600)
|
`))
|
||||||
os.WriteFile(filepath.Join(tdir, "sub/c1.conf"), []byte("inc1 cool"), 0o600)
|
w(filepath.Join(tdir, "sub/b.conf"), []byte("incb cool\ninclude a.conf"))
|
||||||
os.WriteFile(filepath.Join(tdir, "sub/c2.conf"), []byte("inc2 cool\nenvinclude ENVINCLUDE"), 0o600)
|
w(filepath.Join(tdir, "sub/c1.conf"), []byte("inc1 cool"))
|
||||||
os.WriteFile(filepath.Join(tdir, "sub/c.conf"), []byte("inc notcool\nerror sub"), 0o600)
|
w(filepath.Join(tdir, "sub/c2.conf"), []byte("inc2 cool\nenvinclude ENVINCLUDE"))
|
||||||
|
w(filepath.Join(tdir, "sub/c.conf"), []byte("inc notcool\nerror sub"))
|
||||||
|
|
||||||
var parsed_lines []string
|
var parsed_lines []string
|
||||||
pl := func(key, val string) error {
|
pl := func(key, val string) error {
|
||||||
@@ -54,7 +62,7 @@ globin
|
|||||||
if err = p.ParseOverrides("over one", "over two"); err != nil {
|
if err = p.ParseOverrides("over one", "over two"); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
diff := cmp.Diff([]string{"a one", "incb cool", "b ", "inc1 cool", "inc2 cool", "env cool", "inc notcool", "over one", "over two"}, parsed_lines)
|
diff := cmp.Diff([]string{"a one", "incb cool", "b x", "inc1 cool", "inc2 cool", "env cool", "inc notcool", "over one", "over two"}, parsed_lines)
|
||||||
if diff != "" {
|
if diff != "" {
|
||||||
t.Fatalf("Unexpected parsed config values:\n%s", diff)
|
t.Fatalf("Unexpected parsed config values:\n%s", diff)
|
||||||
}
|
}
|
||||||
@@ -62,7 +70,7 @@ globin
|
|||||||
for _, bl := range p.BadLines() {
|
for _, bl := range p.BadLines() {
|
||||||
bad_lines = append(bad_lines, fmt.Sprintf("%s: %d", filepath.Base(bl.Src_file), bl.Line_number))
|
bad_lines = append(bad_lines, fmt.Sprintf("%s: %d", filepath.Base(bl.Src_file), bl.Line_number))
|
||||||
}
|
}
|
||||||
diff = cmp.Diff([]string{"a.conf: 1", "c.conf: 2"}, bad_lines)
|
diff = cmp.Diff([]string{"a.conf: 1", "c.conf: 2", "a.conf: 14"}, bad_lines)
|
||||||
if diff != "" {
|
if diff != "" {
|
||||||
t.Fatalf("Unexpected bad lines:\n%s", diff)
|
t.Fatalf("Unexpected bad lines:\n%s", diff)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user