refactor(night_mode): Phase B language-advantage pass — dichotomy wave
CI Pipeline / best-practices (push) Successful in 9s
CI Pipeline / documentation (push) Successful in 4s
CI Pipeline / rust-surface (push) Failing after 18s
CI Pipeline / go-surface (push) Failing after 21s
CI Pipeline / gitea-offline (push) Successful in 17s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
deploy / deploy (push) Canceled after 59s
Auto-version and Release / release (push) Canceled after 1m2s
CI Pipeline / type-check (push) Canceled after 47s
CI Pipeline / canary (push) Canceled after 1m3s
CI Pipeline / lint (push) Canceled after 1m5s
CI Pipeline / unit-tests (push) Canceled after 1m6s
CI Pipeline / best-practices (push) Successful in 9s
CI Pipeline / documentation (push) Successful in 4s
CI Pipeline / rust-surface (push) Failing after 18s
CI Pipeline / go-surface (push) Failing after 21s
CI Pipeline / gitea-offline (push) Successful in 17s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
deploy / deploy (push) Canceled after 59s
Auto-version and Release / release (push) Canceled after 1m2s
CI Pipeline / type-check (push) Canceled after 47s
CI Pipeline / canary (push) Canceled after 1m3s
CI Pipeline / lint (push) Canceled after 1m5s
CI Pipeline / unit-tests (push) Canceled after 1m6s
This commit is contained in:
1 parent
150f5b86cb
commit
709c2ca4e5
2 files changed
+40
-1
No files matched your search
@@ -141,8 +141,21 @@ func envOr(key, def string) string {
|
||||
return def
|
||||
}
|
||||
|
||||
// trunc — Python s[:n] (character semantics, not bytes).
|
||||
// trunc — Python s[:n] (character semantics, not bytes). Phase B
|
||||
// (language advantage): the common case — an ASCII string no longer than
|
||||
// n bytes — slices in place with zero allocation; only longer or
|
||||
// non-ASCII input pays for the rune walk. Python's s[:n] is always a
|
||||
// char walk, so results are identical on every input.
|
||||
func trunc(s string, n int) string {
|
||||
if len(s) <= n {
|
||||
for i := 0; i < len(s); i++ {
|
||||
if s[i] >= 0x80 {
|
||||
goto runes
|
||||
}
|
||||
}
|
||||
return s
|
||||
}
|
||||
runes:
|
||||
r := []rune(s)
|
||||
if len(r) > n {
|
||||
return string(r[:n])
|
||||
|
||||
@@ -455,6 +455,32 @@ func TestRunLoop(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestTruncPhaseB — the ASCII fast path returns identical results to the
|
||||
// rune walk on every shape: short ASCII, exact-length ASCII, long ASCII,
|
||||
// multi-byte at and across the cut point.
|
||||
func TestTruncPhaseB(t *testing.T) {
|
||||
cases := []struct {
|
||||
in string
|
||||
n int
|
||||
want string
|
||||
}{
|
||||
{"abc", 5, "abc"}, // short ASCII: zero-alloc path
|
||||
{"abcde", 5, "abcde"}, // exact length: no cut
|
||||
{"abcdef", 5, "abcde"}, // long ASCII: byte cut == rune cut
|
||||
{"", 3, ""},
|
||||
{"héllo", 3, "hél"}, // multi-byte before the cut
|
||||
{"héllo", 5, "héllo"}, // multi-byte, no cut
|
||||
{"abécd", 3, "abé"}, // cut lands right after multi-byte rune
|
||||
{"ééé", 2, "éé"}, // all multi-byte
|
||||
{"x" + strings.Repeat("é", 200), 100, "x" + strings.Repeat("é", 99)},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if got := trunc(c.in, c.n); got != c.want {
|
||||
t.Errorf("trunc(%q, %d) = %q, want %q", c.in, c.n, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestStatusReportShapes — non-empty state through the shared status core
|
||||
// and the report view.
|
||||
func TestStatusReportShapes(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user