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
|
// Copyright (c) 2014 TSUYUSATO Kitsune
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php
package heredoc_test
import (
"testing"
)
import "github.com/MakeNowJust/heredoc"
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"},
{`
Foo
Bar
Hoge
`,
"Foo\n\tBar\n\t\tHoge\n\t\t\t"},
{`Foo Bar`, "Foo Bar"},
{
`
Foo
Bar
`, "Foo\nBar\n"},
}
func TestDoc(t *testing.T) {
for i, test := range tests {
result := heredoc.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) {
// test case
str := `
int: %3d
string: %s
`
i := 42
s := "Hello"
expect := "int: 42\nstring: Hello\n"
result := heredoc.Docf(str, i, s)
if result != expect {
t.Errorf("test failed: expected=> %#v, result=> %#v", expect, result)
}
}
|