test(agent): the orientation matrix iterated maps, so its 36 cells shuffled
CI / Tidy (pull_request) Successful in 9m26s
CI / Build & Test (pull_request) Successful in 9m51s

Caught on the sibling mort PR (gadfly/sonnet) and the same mistake was
here: map iteration is randomised, so the matrix printed its cells in a
different order every run and two failing runs could not be diffed. The
"which placements are bare" lookup was a second map keyed by name, which
also let a placement and its expectation drift apart by a typo.

Both are now one slice of {name, bare, build}, so the expectation sits
on the row it belongs to and the order is fixed.
This commit is contained in:
2026-08-22 00:37:48 -04:00
parent 285789c89b
commit bb2196ecb2
+36 -34
View File
@@ -161,50 +161,52 @@ func TestPointsAbove(t *testing.T) {
// //
// The rule under test is a single line: bare IFF there is no content. // The rule under test is a single line: bare IFF there is no content.
func TestBareAbovePointerOrientations(t *testing.T) { func TestBareAbovePointerOrientations(t *testing.T) {
// Each pointer form, written so it reads naturally both as a whole // Slices, not maps: map iteration is randomised, so the 36 cells would
// print in a different order every run and two failing runs could not be
// diffed against each other.
//
// Each pointer form is written so it reads naturally both as a whole
// sentence and as a trailing clause. // sentence and as a trailing clause.
pointers := map[string]struct{ sentence, clause string }{ type pointerForm struct{ name, sentence, clause string }
"demonstrative": {"That's the chain above.", "as shown above"}, pointers := []pointerForm{
"imperative": {"See the note above.", "per the note above"}, {"demonstrative", "That's the chain above.", "as shown above"},
"copular": {"The breakdown is above.", "which is above"}, {"imperative", "See the note above.", "per the note above"},
{"copular", "The breakdown is above.", "which is above"},
} }
// Where the answer can sit relative to the pointer. "" = nowhere: the // Where the answer can sit relative to the pointer. "" = nowhere: the
// pointer is alone, which is the only bare case. // pointer is alone, which is the only bare case.
const answer = "Ship Tuesday" const answer = "Ship Tuesday"
placements := map[string]func(p struct{ sentence, clause string }) string{ // bare records whether the built terminal contains NO answer — the only
"alone": func(p struct{ sentence, clause string }) string { return p.sentence }, // case the rule may treat as disposable.
"alone as a clause": func(p struct{ sentence, clause string }) string { return p.clause }, placements := []struct {
"before, same sentence": func(p struct{ sentence, clause string }) string { return answer + ", " + p.clause + "." }, name string
"before, own sentence": func(p struct{ sentence, clause string }) string { return answer + ". " + p.sentence }, bare bool
"before, own line": func(p struct{ sentence, clause string }) string { return answer + "\n" + p.sentence }, build func(p pointerForm) string
"before, list item": func(p struct{ sentence, clause string }) string { return "- " + answer + "\n- " + p.sentence }, }{
"after, same sentence": func(p struct{ sentence, clause string }) string { return p.clause + ", " + answer + "." }, {"alone", true, func(p pointerForm) string { return p.sentence }},
"after, own sentence": func(p struct{ sentence, clause string }) string { return p.sentence + " " + answer + "." }, {"alone as a clause", true, func(p pointerForm) string { return p.clause }},
"after, own line": func(p struct{ sentence, clause string }) string { return p.sentence + "\n" + answer + "." }, {"filler then pointer", true, func(p pointerForm) string { return "OK. " + p.sentence }},
"after a filler opener": func(p struct{ sentence, clause string }) string { return "OK. " + answer + ", " + p.clause + "." }, {"done-dash then pointer", true, func(p pointerForm) string { return "Done — " + p.clause + "." }},
"filler then pointer": func(p struct{ sentence, clause string }) string { return "OK. " + p.sentence },
"done-dash then pointer": func(p struct{ sentence, clause string }) string { {"before, same sentence", false, func(p pointerForm) string { return answer + ", " + p.clause + "." }},
return "Done — " + p.clause + "." {"before, own sentence", false, func(p pointerForm) string { return answer + ". " + p.sentence }},
}, {"before, own line", false, func(p pointerForm) string { return answer + "\n" + p.sentence }},
} {"before, list item", false, func(p pointerForm) string { return "- " + answer + "\n- " + p.sentence }},
// The only terminals with no answer in them. {"after, same sentence", false, func(p pointerForm) string { return p.clause + ", " + answer + "." }},
bare := map[string]bool{ {"after, own sentence", false, func(p pointerForm) string { return p.sentence + " " + answer + "." }},
"alone": true, {"after, own line", false, func(p pointerForm) string { return p.sentence + "\n" + answer + "." }},
"alone as a clause": true, {"after a filler opener", false, func(p pointerForm) string { return "OK. " + answer + ", " + p.clause + "." }},
"filler then pointer": true,
"done-dash then pointer": true,
} }
for pname, p := range pointers { for _, p := range pointers {
for placement, build := range placements { for _, pl := range placements {
t.Run(pname+"/"+placement, func(t *testing.T) { t.Run(p.name+"/"+pl.name, func(t *testing.T) {
in := build(p) in := pl.build(p)
if !pointsAbove(in) { if !pointsAbove(in) {
t.Fatalf("setup is not a pointer at all, so the case proves nothing: %q", in) t.Fatalf("setup is not a pointer at all, so the case proves nothing: %q", in)
} }
want := bare[placement] if got := bareAbovePointer(in); got != pl.bare {
if got := bareAbovePointer(in); got != want { t.Errorf("bareAbovePointer(%q) = %v, want %v", in, got, pl.bare)
t.Errorf("bareAbovePointer(%q) = %v, want %v", in, got, want)
} }
}) })
} }