...
1
2
3
4
5 package heredoc
6
7 import (
8 "testing"
9 )
10
11 type testCase struct {
12 raw, expect string
13 }
14
15 var tests = []testCase{
16 {"", ""},
17 {`
18 Foo
19 Bar
20 `,
21 "Foo\nBar\n"},
22 {`Foo
23 Bar`,
24 "Foo\nBar"},
25 {`Foo
26
27 Bar
28 `,
29 "Foo\n\t\nBar\n"},
30 {`
31 Foo
32 Bar
33 Hoge
34 `,
35 "Foo\n\tBar\n\t\tHoge\n\t\t\t"},
36 {`Foo Bar`, "Foo Bar"},
37 {
38 `
39 Foo
40 Bar
41 `, "Foo\nBar\n"},
42 }
43
44 func TestDoc(t *testing.T) {
45 for i, test := range tests {
46 result := Doc(test.raw)
47 if result != test.expect {
48 t.Errorf("tests[%d] failed: expected=> %#v, result=> %#v", i, test.expect, result)
49 }
50 }
51 }
52
53 func TestDocf(t *testing.T) {
54 tc := `
55 int: %3d
56 string: %s
57 `
58 i := 42
59 s := "Hello"
60 expect := "int: 42\nstring: Hello\n"
61
62 result := Docf(tc, i, s)
63 if result != expect {
64 t.Errorf("test failed: expected=> %#v, result=> %#v", expect, result)
65 }
66 }
67
View as plain text