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
|
package formatter
import (
"testing"
)
func TestFormat_EdgeCases(t *testing.T) {
type tc struct {
input string
wantErr bool
}
tests := map[string]tc{
"empty file": {
input: "",
wantErr: true,
},
"package only": {
input: "package test\n",
},
"deeply nested elements": {
input: `package test
templ Deep() {
<div>
<div>
<div>
<div>
<span>Deep</span>
</div>
</div>
</div>
</div>
}
`,
},
"multiple components": {
input: `package test
templ A() {
<span>A</span>
}
templ B() {
<span>B</span>
}
`,
},
"component with many attributes": {
input: `package test
templ Styled() {
<div class="flex-col gap-2 p-2 border-rounded text-cyan bg-black">
<span>Styled</span>
</div>
}
`,
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
f := New()
_, err := f.Format("test.gsx", tt.input)
if (err != nil) != tt.wantErr {
t.Errorf("Format() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
|