From 9a77de31dc9759708ce9c2d14ea7c0876c214e71 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Wed, 16 Sep 2026 00:53:52 +0200 Subject: config and engine can load with unsaved text --- internal/config/load_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'internal/config/load_test.go') diff --git a/internal/config/load_test.go b/internal/config/load_test.go index 1cc3ac9..13ef9d8 100644 --- a/internal/config/load_test.go +++ b/internal/config/load_test.go @@ -115,3 +115,30 @@ func TestLockFile(t *testing.T) { t.Errorf("LockFile = %q, want %q", got, want) } } + +// TestLoadWithOverriddenText: LoadWith reads the text the caller supplies +// instead of a file's own, so an editor can check what it has not saved yet +// (GUI design ยง1.3); the files on disk are neither read differently nor +// changed. +func TestLoadWithOverriddenText(t *testing.T) { + h := t.TempDir() + t.Setenv("HOME", h) + main := filepath.Join(h, "krino.conf") + if err := os.MkdirAll(filepath.Join(h, "dirs"), 0o755); err != nil { + t.Fatal(err) + } + os.WriteFile(main, []byte("(include \"dl\")\n"), 0o644) + os.WriteFile(filepath.Join(h, "dirs", "dl.conf"), []byte("(path \"/tmp\")\n"), 0o644) + + over := map[string][]byte{filepath.Join(h, "dirs", "dl.conf"): []byte("(path \"/tmp\")\n(rule \"r\" (move \"Out\"))\n")} + cfg, errs := LoadWith(main, over) + if len(errs) > 0 || len(cfg.Dirs) != 1 || len(cfg.Dirs[0].Rules) != 1 { + t.Fatalf("overridden text not used: %v %+v", errs, cfg.Dirs) + } + if _, errs := LoadWith(main, map[string][]byte{main: []byte("(include \"dl\"")}); len(errs) == 0 { + t.Error("a mistake in the overridden main file was not reported") + } + if cfg, errs := Load(main); len(errs) > 0 || len(cfg.Dirs[0].Rules) != 0 { + t.Errorf("the files on disk were read differently: %v %+v", errs, cfg.Dirs) + } +} -- cgit v1.3