diff options
| author | wuhei <wuhei@users.noreply.github.com> | 2026-11-19 18:36:43 +0100 |
|---|---|---|
| committer | wuhei <wuhei@users.noreply.github.com> | 2026-11-19 18:36:43 +0100 |
| commit | b457d19d9b2c634570300d0f73087e18b4ec4a4a (patch) | |
| tree | 36e066cbe7abb486cb215ba9ccab6ba1550bb315 /main_test.go | |
| parent | f5181ead5b0969fc1806fb714097b17b8d62d53b (diff) | |
| download | lilchinese-b457d19d9b2c634570300d0f73087e18b4ec4a4a.tar.gz | |
Enter keeps the sentence: green on screen, appended to a session log
- Enter (kiosk) turns the sentence green and appends it to a Markdown session log,
default sessions/session-<timestamp>.md, -log to override. Written lazily, so a
run that kept nothing leaves no file.
- logs the whole sentence rather than the 9 characters on screen; the snapshot waits
450ms so the model's lookahead has decoded the final syllables
- the English in the log is a fresh translation of that sentence, done on a single
ordered worker off the audio path, so it never delays recognition
- green clears with the next sentence, like the red cut screen
- double Enter within 2s does not duplicate a line
- tests: keep state, sentence selection, log format and dedupe
Diffstat (limited to 'main_test.go')
| -rw-r--r-- | main_test.go | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/main_test.go b/main_test.go index 09ce825..1838cdb 100644 --- a/main_test.go +++ b/main_test.go @@ -1,6 +1,8 @@ package main import ( + "os" + "strings" "testing" "time" ) @@ -170,3 +172,80 @@ func TestContextWindowPrefersClauseBoundary(t *testing.T) { t.Logf("window = %q", got) } } + +func TestKeepTurnsSentenceGreenUntilTheNextOne(t *testing.T) { + b := newBroker() + ch, _, unsub := b.subscribe() + defer unsub() + b.publish("我自学中文已经五年了", time.Now().UnixMilli()) + <-ch // the phrase itself + + b.keepNow() + s := <-ch + if !s.Keep || s.Text != "我自学中文已经五年了" { + t.Fatalf("keep slide = %+v", s) + } + b.keepNow() // idempotent: no second broadcast, no crash + select { + case dup := <-ch: + t.Fatalf("second keep re-broadcast: %+v", dup) + default: + } + + b.publish("下一句话", time.Now().UnixMilli()) + if next := <-ch; next.Keep { + t.Fatalf("green leaked into the next sentence: %+v", next) + } +} + +func TestPresentersentencePrefersTheOneBeingSpoken(t *testing.T) { + b := newBroker() + p := &presenter{max: 9, preview: 3, b: b} + if got := p.sentence(); got != "" { + t.Fatalf("empty presenter returned %q", got) + } + p.update("第一句话结束了", time.Now().UnixMilli(), true) + if got := p.sentence(); got != "第一句话结束了" { + t.Fatalf("after endpoint sentence() = %q", got) + } + p.update("第二句还在说", time.Now().UnixMilli(), false) + if got := p.sentence(); got != "第二句还在说" { + t.Fatalf("while speaking sentence() = %q", got) + } +} + +func TestSessionLogFormat(t *testing.T) { + dir := t.TempDir() + lg, err := newSessionLog(dir + "/") + if err != nil { + t.Fatal(err) + } + defer lg.close() + + if w, err := lg.add("我自学中文已经五年了", "I have been studying Chinese for five years"); err != nil || !w { + t.Fatalf("add returned %v, %v", w, err) + } + // same sentence twice in a row is a double Enter, not two lines + if w, _ := lg.add("我自学中文已经五年了", "I have been studying Chinese for five years"); w { + t.Fatal("duplicate sentence was written") + } + if w, err := lg.add("谢谢大家", ""); err != nil || !w { + t.Fatalf("second add returned %v, %v", w, err) + } + lg.close() + + raw, err := os.ReadFile(lg.path) + if err != nil { + t.Fatal(err) + } + body := string(raw) + if !strings.HasPrefix(body, "# lilchinese session ") { + t.Fatalf("missing header: %q", body) + } + if n := strings.Count(body, "\n- "); n != 2 { + t.Fatalf("want 2 entries, got %d in:\n%s", n, body) + } + if !strings.Contains(body, "我自学中文已经五年了 — I have been studying Chinese") { + t.Fatalf("translation missing:\n%s", body) + } +} |
