package parse import ( "strings" "testing" ) func TestComment(t *testing.T) { for _, test := range []parseTest{ {``, `{}`, ``}, {`#`, `{}`, ``}, {`# `, `{}`, ``}, {`# aaaaaa`, `{}`, ``}, {"# ending in EOL & EOF\r\n", `{}`, ``}, {`# \xxx/ \u can't escape/`, `{}`, ``}, {"# \tlexe\r accepts embedded ca\r\riage \returns\r\n", `{}`, ``}, {" # multiple\n#lines\n \t\n\n\t#with\n ### comments!", `{}`, ``}, {"# with data and newline\ncode continues here", `{}`, `unexpected input (expected a value assignment) at line 2, column 6`}, } { p := newParser() testParse(t, p, p.startDocument, test) } } func TestInvalidDocument(t *testing.T) { for _, test := range []parseTest{ {`!false!`, `{}`, `unexpected input (expected key/value pair, table or array of tables) at start of file`}, } { p := newParser() testParse(t, p, p.startDocument, test) } } func TestBufferRelatedBug(t *testing.T) { text := strings.Repeat("#", 2040) + "\n# a bug\n" ast, err := Run(text) if len(text) != 2049 { t.Fatalf("Test input is not 2049 bytes, but %d", len(text)) } if err != nil { t.Fatalf("Unexpected error from parser: %s", err) } if ast.String() != "{}" { t.Fatalf("Unexpected TOML document structure returned:\nexpected: {}\nactual: %s", ast) } }