gitstack

grindlemire/go-tui code browser

1.6 KB Go 79 lines 2026-01-31 · 3130a1f 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
package provider

import (
	"testing"
)

func TestFormat_FixesIndentation(t *testing.T) {
	fp := NewFormattingProvider()

	src := `package test

templ Hello() {
<div class="p-1">
<span>Hello</span>
</div>
}
`
	doc := &Document{
		URI:     "file:///test.gsx",
		Content: src,
		Version: 1,
	}

	edits, err := fp.Format(doc, FormattingOptions{TabSize: 4, InsertSpaces: false})
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}

	if len(edits) == 0 {
		t.Fatal("expected at least one edit for badly indented document")
	}

	// The edit should replace the full document
	if edits[0].Range.Start.Line != 0 || edits[0].Range.Start.Character != 0 {
		t.Error("expected edit to start at 0:0")
	}

	// The formatted content should not equal the original
	if edits[0].NewText == src {
		t.Error("expected formatted content to differ from original")
	}
}

func TestFormat_ReturnsFullDocumentEdit(t *testing.T) {
	fp := NewFormattingProvider()

	src := `package test

templ Hello() {
<div class="p-1">
<span>Hello</span>
</div>
}
`
	doc := &Document{
		URI:     "file:///test.gsx",
		Content: src,
		Version: 1,
	}

	edits, err := fp.Format(doc, FormattingOptions{TabSize: 4, InsertSpaces: false})
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}

	if len(edits) != 1 {
		t.Fatalf("expected 1 edit (full document replace), got %d", len(edits))
	}

	// The edit should start at 0:0
	if edits[0].Range.Start.Line != 0 || edits[0].Range.Start.Character != 0 {
		t.Error("expected edit to start at 0:0")
	}

	// The edit end should cover the last line
	if edits[0].Range.End.Line == 0 {
		t.Error("expected edit to cover multiple lines")
	}
}