bitbucket.org/ai69/amoy@v0.2.3/heredoc_test.go (about)

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