diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 16:48:53 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 16:48:53 +0200 |
| commit | e64f162bffa6ced845bac4d3015954c41c4b4a3e (patch) | |
| tree | 87b8fb52b476644ec99cd091bb34ac6521ae9b33 /cmd/krino/review_test.go | |
| parent | 0b5d0eb92c5be2f0ddb2fa73990f31e5654e57fe (diff) | |
| download | krino-0.0.6.tar.gz krino-0.0.6.zip | |
krino: 0.0.6 — w applies and quits, choices echoed in redv0.0.6
Diffstat (limited to 'cmd/krino/review_test.go')
| -rw-r--r-- | cmd/krino/review_test.go | 71 |
1 files changed, 66 insertions, 5 deletions
diff --git a/cmd/krino/review_test.go b/cmd/krino/review_test.go index 19a1d01..a1fbba7 100644 --- a/cmd/krino/review_test.go +++ b/cmd/krino/review_test.go @@ -46,10 +46,17 @@ func TestApplyAllAndSkip(t *testing.T) { } func TestPerFileWriteStopsAsking(t *testing.T) { - // c, y for the first, then w: apply what was chosen so far. - approved, _, _, _ := reviewChains(strings.NewReader("cyw"), new(strings.Builder), chains("a", "b", "c"), "", palette{}) - if !approved["a"] || approved["b"] || approved["c"] { - t.Errorf("approved = %v; want only a", approved) + // c, y for the first, n for the second, then w: apply what was chosen so + // far and quit. Only the files reached are decided; c was never reviewed. + decided, _, action, _ := reviewChains(strings.NewReader("cynw"), new(strings.Builder), chains("a", "b", "c"), "", palette{}) + if action != 'w' { + t.Errorf("action = %q, want 'w'", action) + } + if got, ok := decided["b"]; !ok || got { + t.Errorf("b should be decided as declined: %v", decided) + } + if _, ok := decided["c"]; ok || !decided["a"] { + t.Errorf("decided = %v; want a approved, b declined, c not reviewed", decided) } } @@ -162,7 +169,7 @@ func TestPerFileWrapsToTheTerminal(t *testing.T) { if n := utf8.RuneCountInString(l); n > 60 { t.Errorf("line of %d runes exceeds width 60: %q", n, l) } - if strings.HasPrefix(l, " [y] yes") || (prompt != "" && strings.HasPrefix(l, " ") && !strings.HasPrefix(l, " ")) { + if strings.HasPrefix(l, " [y] yes") || (prompt != "" && strings.HasPrefix(l, " ") && !strings.HasPrefix(l, " ") && !strings.HasPrefix(l, " →")) { prompt += strings.TrimPrefix(l, " ") } } @@ -234,3 +241,57 @@ func TestReplaceChains(t *testing.T) { t.Errorf("replaceChains changed its input: %+v", cs[0].Steps) } } + +// TestPerFileEchoesChoiceInRed: every choice is confirmed on its own line, +// red when colour is on. +func TestPerFileEchoesChoiceInRed(t *testing.T) { + out := new(strings.Builder) + if _, _, _, err := reviewChains(strings.NewReader("cyntdya"), out, chains("a", "b", "c", "d", "e", "f"), "", palette{on: true}); err != nil { + t.Fatal(err) + } + for _, want := range []string{"yes", "no", "trash", "DELETE permanently", "yes, and all remaining"} { + if line := " \x1b[31m→ " + want + "\x1b[0m\n"; !strings.Contains(out.String(), line) { + t.Errorf("no red %q line in:\n%q", want, out) + } + } + plain := new(strings.Builder) + reviewChains(strings.NewReader("cn"), plain, chains("a"), "", palette{}) + if !strings.Contains(plain.String(), "\n → no\n") { + t.Errorf("without colour the choice should still be shown:\n%s", plain) + } +} + +// TestEnterIsIgnored: Enter, at either prompt, is not a key krino +// complains about. +func TestEnterIsIgnored(t *testing.T) { + out := new(strings.Builder) + decided, _, action, err := reviewChains(strings.NewReader("\rc\ry\n"), out, chains("a"), "", palette{}) + if err != nil { + t.Fatal(err) + } + if action != 'c' || !decided["a"] { + t.Errorf("decided = %v action = %q", decided, action) + } + if strings.Contains(out.String(), "is not") { + t.Errorf("Enter was reported as a bad key:\n%s", out) + } +} + +// TestReviewedChains: after [w], only the files decided in review go to +// Apply; the rest are neither applied nor logged. +func TestReviewedChains(t *testing.T) { + got := reviewedChains(chains("a", "b", "c"), map[string]bool{"a": true, "b": false}) + if len(got) != 2 || got[0].File.Rel != "a" || got[1].File.Rel != "b" { + t.Errorf("reviewedChains = %+v; want a and b", got) + } +} + +// TestNotReviewedOutcome: the outcome line counts files [w] left unreviewed. +func TestNotReviewedOutcome(t *testing.T) { + if got := withNotReviewed("2 applied · 0 failed · 1 declined", 139); got != "2 applied · 0 failed · 1 declined · 139 not reviewed" { + t.Errorf("got %q", got) + } + if got := withNotReviewed("2 applied · 0 failed · 1 declined", 0); got != "2 applied · 0 failed · 1 declined" { + t.Errorf("got %q", got) + } +} |
