Skip to content

Commit dbc1998

Browse files
session: receipt words keep paths and code words literal
A decided receipt capitalised every answer, so a chosen file src/c.txt read Src/c.txt. Only a plain phrase gains a capital now, matching the desktop tray. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 4086c5f commit dbc1998

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎internal/session/question_outcomes.go‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package session
22

33
import (
4+
"regexp"
45
"sort"
56
"strings"
67
"sync"
@@ -108,11 +109,19 @@ func decidedOutcome(record DecisionRecord) QuestionOutcome {
108109
}
109110
}
110111

112+
// plainPhrase is a run of plain words: a first word of lowercase letters only,
113+
// followed by more words. Only such a phrase gains a capital.
114+
var plainPhrase = regexp.MustCompile(`^[a-z]+\s+\S`)
115+
116+
// sentenceCase capitalises a plain phrase ("not now") and leaves everything
117+
// else literal, because an answer is often a path, a file name or a lone code
118+
// word ("src/c.txt", "json") whose case is part of what it means. The desktop
119+
// tray applies the same rule, so the receipt and the button read alike.
111120
func sentenceCase(text string) string {
112-
first, size := utf8.DecodeRuneInString(text)
113-
if first == utf8.RuneError {
121+
if !plainPhrase.MatchString(text) {
114122
return text
115123
}
124+
first, size := utf8.DecodeRuneInString(text)
116125
return string(unicode.ToUpper(first)) + text[size:]
117126
}
118127

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package session
2+
3+
import "testing"
4+
5+
// A receipt repeats the person's choice. A path or a code word keeps its case,
6+
// because "Src/c.txt" names a different file than the one that was chosen.
7+
func TestReceiptWordsKeepPathsAndCodeWordsLiteral(t *testing.T) {
8+
for in, want := range map[string]string{
9+
"not now": "Not now",
10+
"src/c.txt": "src/c.txt",
11+
"notes.md": "notes.md",
12+
"json": "json",
13+
"Allow once": "Allow once",
14+
"": "",
15+
} {
16+
if got := sentenceCase(in); got != want {
17+
t.Errorf("sentenceCase(%q) = %q, want %q", in, got, want)
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)