| 1 | package persistentshell |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "reasonix/internal/shellrun" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | "unicode/utf8" |
| 9 | ) |
| 10 | |
| 11 | func TestCaptureProgressPreservesUTF8AcrossMarkerHold(t *testing.T) { |
| 12 | var received strings.Builder |
| 13 | w := shellrun.NewProgressWriter(func(s string) { |
| 14 | if !utf8.ValidString(s) { |
| 15 | t.Fatalf("invalid event: %x", []byte(s)) |
| 16 | } |
| 17 | encoded, _ := json.Marshal(s) |
| 18 | var decoded string |
| 19 | if err := json.Unmarshal(encoded, &decoded); err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | received.WriteString(decoded) |
| 23 | }) |
| 24 | c := newCapture("START", "END:", w) |
| 25 | want := "中" + strings.Repeat("a", markerOverlap-2) |
| 26 | c.push("START\n" + want) |
| 27 | c.push("END:0\n") |
| 28 | w.Flush() |
| 29 | if !c.done || c.body() != want || received.String() != want { |
| 30 | t.Fatalf("stream=%q final=%q", received.String(), c.body()) |
| 31 | } |
| 32 | } |
| 33 |