-
Notifications
You must be signed in to change notification settings - Fork 15
/
string_test.go
95 lines (74 loc) · 1.93 KB
/
string_test.go
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
95
package gg
import (
"testing"
)
func TestString(t *testing.T) {
t.Run("simple string", func(t *testing.T) {
buf := pool.Get()
defer buf.Free()
expected := "Hello, World!"
String(expected).render(buf)
compareAST(t, expected, buf.String())
})
t.Run("format string", func(t *testing.T) {
buf := pool.Get()
defer buf.Free()
expected := "Hello, World!"
String("Hello, %s!", "World").render(buf)
compareAST(t, expected, buf.String())
})
}
func TestLineComment(t *testing.T) {
t.Run("simple comment", func(t *testing.T) {
buf := pool.Get()
defer buf.Free()
expected := "// Hello, World!"
LineComment("Hello, World!").render(buf)
compareAST(t, expected, buf.String())
})
t.Run("format comment", func(t *testing.T) {
buf := pool.Get()
defer buf.Free()
expected := "// Hello, World!"
LineComment("Hello, %s!", "World").render(buf)
compareAST(t, expected, buf.String())
})
}
func TestLit(t *testing.T) {
buf := pool.Get()
defer buf.Free()
expected := "true"
Lit(true).render(buf)
compareAST(t, expected, buf.String())
}
func TestFormatComment(t *testing.T) {
cases := []struct {
name string
input string
expect string
}{
{
"short line",
"Value comment",
"// Value comment",
},
{
"long single line",
"These is a long line that we need to do line break at 140. However, this long line is not long enough, so we still need to pollute a lot water in it. After all these jobs, we can test this long line.",
`// These is a long line that we need to do line break at 140. However, this long line is not long enough,
// so we still need to pollute a lot water in it. After all these jobs, we can test this long line.`,
},
{
"multi lines",
`There is line which has
its own line break.`,
`// There is line which has
// its own line break.`,
},
}
for _, v := range cases {
t.Run(v.name, func(t *testing.T) {
compareAST(t, v.expect, formatLineComment(v.input))
})
}
}