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/facts_test.go | |
| parent | 1d3f2d1e4c59867024470d3444e12698b7ebb22e (diff) | |
| download | krino-0.0.5.tar.gz krino-0.0.5.zip | |
krino: 0.0.5 — keyword cache, t and d in reviewv0.0.5
Diffstat (limited to 'internal/engine/facts_test.go')
| -rw-r--r-- | internal/engine/facts_test.go | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/internal/engine/facts_test.go b/internal/engine/facts_test.go index 7d844a0..9739fa6 100644 --- a/internal/engine/facts_test.go +++ b/internal/engine/facts_test.go @@ -3,79 +3,10 @@ package engine import ( - "context" - "os" "path/filepath" "testing" - "time" - - "krino/internal/cond" - "krino/internal/extract" - "krino/internal/scan" ) -// contentFacts builds a *facts for a real text file, under a Dir whose -// ContentVariants is variants, for exercising B2's raw-release directly. -func contentFacts(t *testing.T, body string, variants []cond.Options) *facts { - t.Helper() - p := filepath.Join(t.TempDir(), "a.txt") - if err := os.WriteFile(p, []byte(body), 0o644); err != nil { - t.Fatal(err) - } - fi, err := os.Stat(p) - if err != nil { - t.Fatal(err) - } - e := &Engine{Extract: extract.New(), Now: time.Now} - d := &Dir{Name: "d", ContentVariants: variants} - file := scan.File{Path: p, Rel: "a.txt", Name: "a.txt", Size: fi.Size(), ModTime: fi.ModTime()} - run := newMatchRun(e, d, context.Background(), time.Now(), []scan.File{file}) - return newFacts(run, file) -} - -// TestContentReleasesRawWithOneVariant: B2. A directory whose rules use -// exactly one (ignoreCase, fold) variant releases the raw extracted text -// once that variant's normalised copy exists. -func TestContentReleasesRawWithOneVariant(t *testing.T) { - f := contentFacts(t, "Hello World", []cond.Options{{IgnoreCase: true, Fold: false}}) - const want = "hello world" - got, err := f.Content(true, false) - if err != nil { - t.Fatal(err) - } - if got != want { - t.Fatalf("got %q, want %q", got, want) - } - if f.content != "" { - t.Errorf("raw text not released with a single content variant: %q", f.content) - } - // A second call for the same (already cached) variant must still work - // from normCache, without needing the released raw text. - if got, err := f.Content(true, false); err != nil || got != want { - t.Errorf("second call for the cached variant: got %q, %v, want %q", got, err, want) - } -} - -// TestContentKeepsRawWithTwoVariants: B2. A directory whose rules use two -// distinct variants must not release the raw text after the first: the -// second variant still needs it, and normalising it correctly (not from an -// emptied string) is the proof the raw text was kept. -func TestContentKeepsRawWithTwoVariants(t *testing.T) { - f := contentFacts(t, "Hello World", []cond.Options{ - {IgnoreCase: true, Fold: false}, - {IgnoreCase: false, Fold: false}, - }) - if got, err := f.Content(true, false); err != nil || got != "hello world" { - t.Fatalf("first variant: got %q, %v", got, err) - } - if f.content == "" { - t.Fatal("raw text released after only the first of two variants") - } - if got, err := f.Content(false, false); err != nil || got != "Hello World" { - t.Fatalf("second variant: got %q, %v, want the unfolded original (raw text must still be available)", got, err) - } -} - // TestDisplayOriginalAbbreviatesHome: a duplicate's original is shown // root-relative inside the root, and home-abbreviated outside it, the way // every other user-visible path is; a path outside $HOME stays absolute. |
