-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcursor_test.go
More file actions
56 lines (48 loc) · 1.96 KB
/
Copy pathcursor_test.go
File metadata and controls
56 lines (48 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"strings"
"testing"
)
func TestInsertCursorPreservesColor(t *testing.T) {
// Simulate what lipgloss outputs: \x1b[1;38;5;42mfeat\x1b[m\x1b[1;38;5;241m:\x1b[m\x1b[38;5;254m add stuff\x1b[m
highlighted := "\x1b[1;38;5;42mfeat\x1b[m\x1b[1;38;5;241m:\x1b[m\x1b[38;5;254m add stuff\x1b[m"
// Insert cursor at col 4 (the ':')
result := insertCursorInColored(highlighted, 4)
// After the cursor's \x1b[27m, the SGR state should be re-emitted.
// The ':' is in a separate styled segment after a full reset, so
// currentSGR should be empty at that point (reset was consumed).
// The ' add stuff' part has its own \x1b[38;5;254m prefix, so it
// should still be present in the output.
if !strings.Contains(result, "\x1b[38;5;254m") {
t.Errorf("color for 'add stuff' was lost after cursor insertion\nresult: %q", result)
}
// The 'feat' color should also be preserved
if !strings.Contains(result, "\x1b[1;38;5;42m") {
t.Errorf("color for 'feat' was lost\nresult: %q", result)
}
}
func TestInsertCursorAtEnd(t *testing.T) {
highlighted := "\x1b[1;38;5;42mfeat\x1b[m"
result := insertCursorInColored(highlighted, 4)
// Should have reverse-video space at end
if !strings.Contains(result, "\x1b[7m") {
t.Errorf("expected reverse-video at end\nresult: %q", result)
}
}
func TestInsertCursorReEmitsSGR(t *testing.T) {
// When cursor is in the middle of a styled segment (no reset between),
// the SGR should be re-emitted after \x1b[27m.
// Simulate: \x1b[38;5;254mhello world\x1b[m
// Cursor at col 5 (after "hello", on " ")
highlighted := "\x1b[38;5;254mhello world\x1b[m"
result := insertCursorInColored(highlighted, 5)
// After \x1b[27m, the \x1b[38;5;254m should be re-emitted
idx := strings.Index(result, "\x1b[27m")
if idx < 0 {
t.Fatal("expected \\x1b[27m in result")
}
afterCursor := result[idx:]
if !strings.Contains(afterCursor, "\x1b[38;5;254m") {
t.Errorf("expected SGR re-emitted after cursor\nafter cursor: %q", afterCursor)
}
}