42 lines
1.4 KiB
Go
42 lines
1.4 KiB
Go
package parser_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.makaay.nl/mauricem/go-toml"
|
|
)
|
|
|
|
func TestEmptyInput(t *testing.T) {
|
|
runStatesT(t, statesT{"empty string", "", "", ""})
|
|
}
|
|
|
|
func TestErrorFullIncludesLineAndRowPosition(t *testing.T) {
|
|
p := parser.NewParser("# 12345 abcde\t\n\n\n# 67890\r\n# 12345\n +")
|
|
_, err := parseItemsToArray(p)
|
|
actual := err.ErrorFull()
|
|
expected := "unexpected character '+' (expected end of file) after line 6, column 3"
|
|
if actual != expected {
|
|
t.Errorf("Unexpected error message:\nexpected: %s\nactual: %s\n", expected, actual)
|
|
}
|
|
}
|
|
|
|
func TestInvalidUtf8Data(t *testing.T) {
|
|
runStatesTs(t, []statesT{
|
|
{"inside comment", "# \xbc", "", "invalid UTF8 character in input (expected end of file)"},
|
|
{"bare key 1", "\xbc", "", "invalid UTF8 character in input (expected end of file)"},
|
|
{"bare key 2", "key\xbc", "[key]", "invalid UTF8 character in input (expected a value assignment)"},
|
|
{"start of value", "key=\xbc", "[key]=", "invalid UTF8 character in input (expected a value)"},
|
|
{"basic string value", "a=\"\xbc\"", "[a]=", "invalid UTF8 character in input (expected string contents)"},
|
|
})
|
|
}
|
|
|
|
func TestWhiteSpaceAndNewlines(t *testing.T) {
|
|
runStatesTs(t, []statesT{
|
|
{"space", " ", "", ""},
|
|
{"tab", "\t", "", ""},
|
|
{"newline", "\n", "", ""},
|
|
{"carriage return", "\r", "", ""},
|
|
{"all whitespace and newlines", " \t \t \r\r\n\n \n \t", "", ""},
|
|
})
|
|
}
|