diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-16 01:34:45 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-16 01:34:45 +0200 |
| commit | ecfaeabf2a92e26c6a521d5fac404a0fff6263b6 (patch) | |
| tree | 4147dd6809a45fe5b773447352354dbee2295900 /internal/config/print_test.go | |
| parent | be4b1275c76b9cad984dfafaa8023db94eb3eecf (diff) | |
| download | krino-ecfaeabf2a92e26c6a521d5fac404a0fff6263b6.tar.gz krino-ecfaeabf2a92e26c6a521d5fac404a0fff6263b6.zip | |
milestone 1 review: claims span the run, explain's chain is opt-in and its own, overrides keyed by clean path, splice and enum guards
Diffstat (limited to 'internal/config/print_test.go')
| -rw-r--r-- | internal/config/print_test.go | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/internal/config/print_test.go b/internal/config/print_test.go index 9b8d479..510fdd9 100644 --- a/internal/config/print_test.go +++ b/internal/config/print_test.go @@ -5,6 +5,8 @@ package config import ( "strings" "testing" + + "krino/internal/sexp" ) func parseOne(t *testing.T, body string) *Dir { @@ -70,7 +72,11 @@ func TestSpliceLeavesTheRestAlone(t *testing.T) { if len(errs) > 0 { t.Fatal(errs) } - got := string(Splice(src, dir.Rules[0].Pos, dir.Rules[0].End, "(rule \"a\"\n (move \"In\"))")) + spliced, err := Splice(src, dir.Rules[0].Pos, dir.Rules[0].End, "(rule \"a\"\n (move \"In\"))") + if err != nil { + t.Fatal(err) + } + got := string(spliced) want := "; keep me\n(path \"/tmp\")\n(rule \"a\"\n (move \"In\"))\n; and me\n" if got != want { t.Errorf("got\n%q\nwant\n%q", got, want) @@ -79,3 +85,19 @@ func TestSpliceLeavesTheRestAlone(t *testing.T) { t.Error("Splice changed the source it was given") } } + +// TestSpliceRefusesOffsetsOutsideTheSource: a stale end offset - the file +// changed since the form was parsed - is an error, not a panic (plan 13 +// review F6). +func TestSpliceRefusesOffsetsOutsideTheSource(t *testing.T) { + src := []byte("(path \"/tmp\")") + for _, c := range []struct{ start, end int }{{0, len(src) + 2}, {8, 4}, {-1, 3}} { + if _, err := Splice(src, sexp.Pos{Offset: c.start}, sexp.Pos{Offset: c.end}, "x"); err == nil { + t.Errorf("Splice(%d, %d) did not refuse", c.start, c.end) + } + } + out, err := Splice(src, sexp.Pos{Offset: 0}, sexp.Pos{Offset: len(src)}, "(path \"/x\")") + if err != nil || string(out) != "(path \"/x\")" { + t.Errorf("Splice over the whole source = %q, %v", out, err) + } +} |
