Download internal/panel/ring_test.go from a3216/gcli2api: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/spaces/a3216/gcli2api/resolve/main/internal/panel/ring_test.go
- Command line
-
hf download hf://spaces/a3216/gcli2api/internal/panel/ring_test.go
-
curl -L -o ring_test.go https://huggingface.co/spaces/a3216/gcli2api/resolve/main/internal/panel/ring_test.go
1.8 kB
| package panel | |
| import ( | |
| "strings" | |
| "testing" | |
| "time" | |
| ) | |
| func TestClassifyLine(t *testing.T) { | |
| cases := map[string]string{ | |
| "| #001 | glm-5.2 | stream | 200 | uid=c8a3e793 | TTFB=120ms |": ChChat, | |
| "school c8a3e793: ★ 分享任务完成": ChTask, | |
| "streak-bonus 5c162cc9: 🎊 新手礼包 +100c": ChTask, | |
| "blackcat c8a3e793: 完成 3 次夜间对话": ChTask, | |
| "checkin 5c162cc9: 已签到": ChTask, | |
| "panel: 任务动作 uid=x code=chat_5": ChTask, | |
| "panel: 队列启动:6 项(并发 2)": ChTask, | |
| "panel: revive uid=x": ChSys, | |
| "workbuddy2api listening on :7863": ChSys, | |
| "scheduler: 余额后台刷新每 5m0s": ChSys, | |
| } | |
| for line, want := range cases { | |
| if got := classifyLine(line); got != want { | |
| t.Errorf("classifyLine(%q)=%q want %q", line, got, want) | |
| } | |
| } | |
| } | |
| func TestRingWriteStripsTimestamp(t *testing.T) { | |
| r := NewRing(4) | |
| if _, err := r.Write([]byte("2026/09/14 00:12:34 school x: done\n")); err != nil { | |
| t.Fatal(err) | |
| } | |
| if _, err := r.Write([]byte("| #002 | glm | stream | 200 | ok |")); err != nil { | |
| t.Fatal(err) | |
| } | |
| es := r.Snapshot() | |
| if len(es) != 2 { | |
| t.Fatalf("entries=%d want 2", len(es)) | |
| } | |
| if strings.HasPrefix(es[0].Text, "2026/") { | |
| t.Errorf("timestamp not stripped: %q", es[0].Text) | |
| } | |
| if es[0].Ch != ChTask || es[1].Ch != ChChat { | |
| t.Errorf("channels: %q %q", es[0].Ch, es[1].Ch) | |
| } | |
| if time.Since(es[0].TS) > 5*time.Second { | |
| t.Errorf("stale ts: %v", es[0].TS) | |
| } | |
| } | |