-
Notifications
You must be signed in to change notification settings - Fork 6
/
heredoc_test.go
67 lines (59 loc) · 1.04 KB
/
heredoc_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
// Copyright (c) 2014-2024 TSUYUSATO Kitsune
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php
package heredoc
import (
"testing"
)
type testCase struct {
raw, expect string
}
var tests = []testCase{
{"", ""},
{`
Foo
Bar
`,
"Foo\nBar\n"},
{`Foo
Bar`,
"Foo\nBar"},
{`Foo
Bar
`,
"Foo\n\t\nBar\n"}, // Second line contains two tabs.
{`
Foo
Bar
Hoge
`,
"Foo\n\tBar\n\t\tHoge\n\t\t\t"},
{`Foo Bar`, "Foo Bar"},
{
`
Foo
Bar
`, "Foo\nBar\n"},
{"\n\u3000zenkaku space", "\u3000zenkaku space"},
}
func TestDoc(t *testing.T) {
for i, test := range tests {
result := Doc(test.raw)
if result != test.expect {
t.Errorf("tests[%d] failed: expected=> %#v, result=> %#v", i, test.expect, result)
}
}
}
func TestDocf(t *testing.T) {
tc := `
int: %3d
string: %s
`
i := 42
s := "Hello"
expect := "int: 42\nstring: Hello\n"
result := Docf(tc, i, s)
if result != expect {
t.Errorf("test failed: expected=> %#v, result=> %#v", expect, result)
}
}