▍ humdrum codex / glint v1.0.2
license AGPL-3.0
2.5 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package picker

import (
	"os"
	"path/filepath"
	"testing"

	"glint/internal/theme"
)

func TestGoWalkSearchFindsLineMatches(t *testing.T) {
	root := t.TempDir()
	os.WriteFile(filepath.Join(root, "a.md"), []byte("alpha\nfind me here\nbeta"), 0o644)
	os.WriteFile(filepath.Join(root, "b.md"), []byte("nothing relevant"), 0o644)

	hits := goWalkSearch(root, "find me")
	if len(hits) != 1 {
		t.Fatalf("got %d hits, want 1: %+v", len(hits), hits)
	}
	h := hits[0]
	if h.Path != filepath.Join(root, "a.md") {
		t.Errorf("path = %q, want a.md", h.Path)
	}
	if h.Line != 2 {
		t.Errorf("line = %d, want 2", h.Line)
	}
	if h.Text != "find me here" {
		t.Errorf("text = %q, want %q", h.Text, "find me here")
	}
}

func TestGoWalkSearchCaseInsensitive(t *testing.T) {
	root := t.TempDir()
	os.WriteFile(filepath.Join(root, "a.md"), []byte("The Quick Brown Fox"), 0o644)
	hits := goWalkSearch(root, "quick brown")
	if len(hits) != 1 {
		t.Fatalf("case-insensitive search should find 1 hit, got %d", len(hits))
	}
}

func TestParseRgOutput(t *testing.T) {
	out := "/v/a.md:2:find me here\n/v/sub/b.md:10:another match\nmalformed line\n"
	hits := parseRgOutput(out)
	if len(hits) != 2 {
		t.Fatalf("got %d hits, want 2 (malformed skipped): %+v", len(hits), hits)
	}
	if hits[0].Path != "/v/a.md" || hits[0].Line != 2 || hits[0].Text != "find me here" {
		t.Errorf("hit0 = %+v", hits[0])
	}
	if hits[1].Line != 10 {
		t.Errorf("hit1 line = %d, want 10", hits[1].Line)
	}
}

func TestContentSearchEmptyQuery(t *testing.T) {
	if hits := contentSearch(t.TempDir(), "   "); hits != nil {
		t.Errorf("blank query should yield no hits, got %+v", hits)
	}
}

func TestPickerSlashPrefixContentSearch(t *testing.T) {
	root := t.TempDir()
	os.WriteFile(filepath.Join(root, "note.md"), []byte("intro\nthe needle line\noutro"), 0o644)

	m, err := New(root, theme.FlexokiDark(), "", "dark")
	if err != nil {
		t.Fatal(err)
	}
	m.input.SetValue("/needle")
	m.recompute()

	if got := m.Selected(); got != filepath.Join(root, "note.md") {
		t.Errorf("Selected() = %q, want note.md", got)
	}
	if got := m.SelectedLine(); got != 2 {
		t.Errorf("SelectedLine() = %d, want 2", got)
	}
}

func TestPickerFilenameModeHasNoLine(t *testing.T) {
	root := t.TempDir()
	os.WriteFile(filepath.Join(root, "note.md"), []byte("body"), 0o644)

	m, err := New(root, theme.FlexokiDark(), "", "dark")
	if err != nil {
		t.Fatal(err)
	}
	m.input.SetValue("note")
	m.recompute()

	if m.SelectedLine() != 0 {
		t.Errorf("filename match should have line 0, got %d", m.SelectedLine())
	}
}