diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 15:16:55 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 15:16:55 +0200 |
| commit | 0b5d0eb92c5be2f0ddb2fa73990f31e5654e57fe (patch) | |
| tree | 358e331945b8206ed4a72703e3aedfe8ea7cdcdb /internal/engine/engine_test.go | |
| parent | 1d3f2d1e4c59867024470d3444e12698b7ebb22e (diff) | |
| download | krino-0b5d0eb92c5be2f0ddb2fa73990f31e5654e57fe.tar.gz krino-0b5d0eb92c5be2f0ddb2fa73990f31e5654e57fe.zip | |
krino: 0.0.5 — keyword cache, t and d in reviewv0.0.5
Diffstat (limited to 'internal/engine/engine_test.go')
| -rw-r--r-- | internal/engine/engine_test.go | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/internal/engine/engine_test.go b/internal/engine/engine_test.go index 18b35e7..c38c1fc 100644 --- a/internal/engine/engine_test.go +++ b/internal/engine/engine_test.go @@ -46,14 +46,14 @@ func writeConfig(t *testing.T, home, main string, dirs map[string]string) string // fakeFacts is a minimal cond.Facts for checking compiled rules. type fakeFacts struct{ name string } -func (f fakeFacts) Name() string { return f.name } -func (f fakeFacts) Rel() string { return f.name } -func (f fakeFacts) Size() int64 { return 1 } -func (f fakeFacts) ModTime() time.Time { return time.Time{} } -func (f fakeFacts) Now() time.Time { return time.Time{} } -func (f fakeFacts) Content(bool, bool) (string, error) { return "", nil } -func (f fakeFacts) Duplicate([]string) (string, bool, error) { return "", false, nil } -func (f fakeFacts) Matched() bool { return false } +func (f fakeFacts) Name() string { return f.name } +func (f fakeFacts) Rel() string { return f.name } +func (f fakeFacts) Size() int64 { return 1 } +func (f fakeFacts) ModTime() time.Time { return time.Time{} } +func (f fakeFacts) Now() time.Time { return time.Time{} } +func (f fakeFacts) ContentContains(cond.Options, []string) (int, error) { return -1, nil } +func (f fakeFacts) Duplicate([]string) (string, bool, error) { return "", false, nil } +func (f fakeFacts) Matched() bool { return false } var _ cond.Facts = fakeFacts{} @@ -187,12 +187,10 @@ func TestLoadAcceptsSuppliedCaptures(t *testing.T) { } } -// TestContentVariantsComputedAtLoad: B2 plumbing. Load computes each -// directory's distinct (ignoreCase, fold) content-test variants from its -// rules' resolved settings: a rule with no content test contributes -// nothing; two rules sharing a variant fold into one; a rule-level (case -// ignore) override adds a second. -func TestContentVariantsComputedAtLoad(t *testing.T) { +// TestContentKeywordsComputedAtLoad: Load collects every content keyword +// of a directory's rules, once per (options, normalised keyword), sorted by +// key: a rule-level (case ignore) makes the same word a second keyword. +func TestContentKeywordsComputedAtLoad(t *testing.T) { h := sandbox(t) os.Mkdir(filepath.Join(h, "dl"), 0o755) main := writeConfig(t, h, `(include "dl")`, map[string]string{"dl": ` @@ -207,10 +205,11 @@ func TestContentVariantsComputedAtLoad(t *testing.T) { if len(errs) > 0 { t.Fatal(errs) } - got := e.Dirs[0].ContentVariants - want := []cond.Options{{IgnoreCase: false, Fold: true}, {IgnoreCase: true, Fold: true}} + got := e.Dirs[0].ContentKeywords + strict, loose := cond.Options{IgnoreCase: false, Fold: true}, cond.Options{IgnoreCase: true, Fold: true} + want := []cond.Keyword{{Opt: loose, Norm: "acme"}, {Opt: strict, Norm: "acme"}, {Opt: strict, Norm: "other"}} if !reflect.DeepEqual(got, want) { - t.Fatalf("ContentVariants = %+v, want %+v", got, want) + t.Fatalf("ContentKeywords = %+v, want %+v", got, want) } } |
