ScuttleBot

scuttlebot / pkg / toon / toon_test.go
Blame History Raw 66 lines
1
package toon
2
3
import (
4
"strings"
5
"testing"
6
"time"
7
)
8
9
func TestFormatEmpty(t *testing.T) {
10
if got := Format(nil, Options{}); got != "" {
11
t.Errorf("expected empty, got %q", got)
12
}
13
}
14
15
func TestFormatBasic(t *testing.T) {
16
base := time.Date(2026, 4, 5, 12, 0, 0, 0, time.UTC)
17
entries := []Entry{
18
{Nick: "alice", Type: "op", Text: "let's ship it", At: base},
19
{Nick: "claude-abc", Type: "orch", MessageType: "task.create", Text: "editing main.go", At: base.Add(2 * time.Minute)},
20
{Nick: "claude-abc", Type: "orch", MessageType: "task.complete", Text: "done", At: base.Add(5 * time.Minute)},
21
}
22
out := Format(entries, Options{Channel: "#fleet"})
23
24
// Header.
25
if !strings.HasPrefix(out, "#fleet 3msg") {
26
t.Errorf("header mismatch: %q", out)
27
}
28
// Grouped consecutive messages from claude-abc.
29
if strings.Count(out, "claude-abc") != 1 {
30
t.Errorf("expected nick grouping, got:\n%s", out)
31
}
32
// Contains message types.
33
if !strings.Contains(out, "task.create") || !strings.Contains(out, "task.complete") {
34
t.Errorf("missing message types:\n%s", out)
35
}
36
}
37
38
func TestFormatPrompt(t *testing.T) {
39
entries := []Entry{{Nick: "a", Text: "hello"}}
40
out := FormatPrompt("#test", entries)
41
if !strings.Contains(out, "Summarize") {
42
t.Errorf("prompt missing instruction:\n%s", out)
43
}
44
if !strings.Contains(out, "#test") {
45
t.Errorf("prompt missing channel:\n%s", out)
46
}
47
}
48
49
func TestCompactDuration(t *testing.T) {
50
tests := []struct {
51
d time.Duration
52
want string
53
}{
54
{30 * time.Second, "30s"},
55
{5 * time.Minute, "5m"},
56
{2 * time.Hour, "2h"},
57
{2*time.Hour + 30*time.Minute, "2h30m"},
58
{48 * time.Hour, "2d"},
59
}
60
for _, tt := range tests {
61
if got := compactDuration(tt.d); got != tt.want {
62
t.Errorf("compactDuration(%v) = %q, want %q", tt.d, got, tt.want)
63
}
64
}
65
}
66

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button