@@ -0,0 +1,98 @@
1+package gamestate
2+
3+import (
4+ "strings"
5+ "testing"
6+)
7+
8+func TestSnapshotLinesTUI_CompactFormat(t *testing.T) {
9+ testJSON := `{
10+ "ship": {
11+ "id": "ship-123",
12+ "position": {
13+ "x": 100,
14+ "y": 200,
15+ "z": 50
16+ }
17+ },
18+ "cargo": [
19+ {"item": "ore", "qty": 10},
20+ {"item": "fuel", "qty": 5}
21+ ],
22+ "status": "docked"
23+ }`
24+
25+ llmLines := SnapshotLines(testJSON)
26+ tuiLines := SnapshotLinesTUI(testJSON)
27+
28+ // LLM format should have full dotted paths
29+ llmOutput := strings.Join(llmLines, "\n")
30+ if !strings.Contains(llmOutput, "ship.position.x: 100") {
31+ t.Errorf("LLM format should contain full dotted paths, got:\n%s", llmOutput)
32+ }
33+
34+ // TUI format should be more compact
35+ tuiOutput := strings.Join(tuiLines, "\n")
36+
37+ // Should preserve some context (dotted paths are OK, just more compact than LLM format)
38+ if !strings.Contains(tuiOutput, "ship.position.x: 100") {
39+ t.Errorf("TUI format should preserve minimal context paths, got:\n%s", tuiOutput)
40+ }
41+
42+ // Should show array counts instead of expanding
43+ if !strings.Contains(tuiOutput, "[2 items]") {
44+ t.Errorf("TUI format should show array counts, got:\n%s", tuiOutput)
45+ }
46+
47+ // Should contain simple top-level keys
48+ if !strings.Contains(tuiOutput, "status: docked") {
49+ t.Errorf("TUI format should contain simple key-value pairs, got:\n%s", tuiOutput)
50+ }
51+
52+ // Key difference: arrays should NOT be expanded in TUI format
53+ if strings.Contains(tuiOutput, "cargo[0].item") {
54+ t.Errorf("TUI format should not expand arrays, got:\n%s", tuiOutput)
55+ }
56+
57+ t.Logf("LLM format (%d lines):\n%s", len(llmLines), llmOutput)
58+ t.Logf("\nTUI format (%d lines):\n%s", len(tuiLines), tuiOutput)
59+}
60+
61+func TestSnapshotLinesTUI_EmptyAndInvalid(t *testing.T) {
62+ tests := []struct {
63+ name string
64+ input string
65+ expected []string
66+ }{
67+ {
68+ name: "empty string",
69+ input: "",
70+ expected: nil,
71+ },
72+ {
73+ name: "whitespace only",
74+ input: " \n\t ",
75+ expected: nil,
76+ },
77+ {
78+ name: "invalid JSON",
79+ input: "{not valid json}",
80+ expected: []string{"(invalid JSON)"},
81+ },
82+ }
83+
84+ for _, tt := range tests {
85+ t.Run(tt.name, func(t *testing.T) {
86+ result := SnapshotLinesTUI(tt.input)
87+ if len(result) != len(tt.expected) {
88+ t.Errorf("expected %d lines, got %d", len(tt.expected), len(result))
89+ return
90+ }
91+ for i := range result {
92+ if result[i] != tt.expected[i] {
93+ t.Errorf("line %d: expected %q, got %q", i, tt.expected[i], result[i])
94+ }
95+ }
96+ })
97+ }
98+}