hcl/scanner: test \r\n endings

This commit is contained in:
Mitchell Hashimoto 2016-11-30 19:39:16 -05:00
parent b97feebd3d
commit ae25c981c1
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A

View File

@ -476,6 +476,36 @@ EOF
}
func TestScan_crlf(t *testing.T) {
complexHCL := "foo {\r\n bar = \"baz\"\r\n}\r\n"
literals := []struct {
tokenType token.Type
literal string
}{
{token.IDENT, `foo`},
{token.LBRACE, `{`},
{token.IDENT, `bar`},
{token.ASSIGN, `=`},
{token.STRING, `"baz"`},
{token.RBRACE, `}`},
{token.EOF, ``},
}
s := New([]byte(complexHCL))
for _, l := range literals {
tok := s.Scan()
if l.tokenType != tok.Type {
t.Errorf("got: %s want %s for %s\n", tok, l.tokenType, tok.String())
}
if l.literal != tok.Text {
t.Errorf("got:\n%+v\n%s\n want:\n%+v\n%s\n", []byte(tok.String()), tok, []byte(l.literal), l.literal)
}
}
}
func TestError(t *testing.T) {
testError(t, "\x80", "1:1", "illegal UTF-8 encoding", token.ILLEGAL)
testError(t, "\xff", "1:1", "illegal UTF-8 encoding", token.ILLEGAL)