▍ humdrum codex / glint v1.0.2
license AGPL-3.0
1.9 KB raw
 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package app

import (
	"strings"
	"testing"

	tea "github.com/charmbracelet/bubbletea"
	"github.com/charmbracelet/lipgloss"
	"glint/internal/editor"
)

func statusApp() *App {
	a := newApp()
	a.width = 120
	a.height = 24
	return a
}

func TestStatusBarShowsLnCol(t *testing.T) {
	a := statusApp()
	a.editor.SetContent([]byte("hello\nworld"))
	a.editor.Cursor = editor.Position{Row: 1, Col: 2}
	if got := a.statusBar(); !strings.Contains(got, "Ln 2:3") {
		t.Fatalf("status bar missing Ln 2:3:\n%s", got)
	}
}

func TestStatusBarShowsWordCount(t *testing.T) {
	a := statusApp()
	a.editor.SetContent([]byte("one two three"))
	if got := a.statusBar(); !strings.Contains(got, "3 words") {
		t.Fatalf("status bar missing word count:\n%s", got)
	}
}

func TestStatusBarShowsThemeName(t *testing.T) {
	a := statusApp()
	if got := a.statusBar(); !strings.Contains(got, a.theme.Name) {
		t.Fatalf("status bar missing theme %q:\n%s", a.theme.Name, got)
	}
}

func TestStatusBarShowsHelpIndicator(t *testing.T) {
	a := statusApp()
	if got := a.statusBar(); !strings.Contains(got, "?") {
		t.Fatalf("status bar missing help indicator:\n%s", got)
	}
}

func TestStatusBarShowsSelectionStats(t *testing.T) {
	a := statusApp()
	a.editor.SetContent([]byte("one two three"))
	for i := 0; i < 7; i++ { // select "one two" via Shift+Right
		a.editor.HandleKey(tea.KeyMsg{Type: tea.KeyShiftRight})
	}
	got := a.statusBar()
	if !strings.Contains(got, "7 chars") || !strings.Contains(got, "2 words selected") {
		t.Fatalf("status bar missing selection stats:\n%s", got)
	}
}

func TestStatusBarNarrowNoOverflow(t *testing.T) {
	a := statusApp()
	a.width = 20
	a.editor.SetContent([]byte("one two three four five"))
	a.editor.Cursor = editor.Position{Row: 0, Col: 3}
	for _, line := range strings.Split(a.statusBar(), "\n") {
		if w := lipgloss.Width(line); w > 20 {
			t.Fatalf("status line width %d > 20: %q", w, line)
		}
	}
}