41 lines
1.8 KiB
Go
41 lines
1.8 KiB
Go
package toml
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestArray(t *testing.T) {
|
|
for _, test := range []parseTest{
|
|
{"", []string{`Error: unexpected end of file (expected an array) at start of file`}},
|
|
{"[ape", []string{`Error: unexpected input (expected a value) at line 1, column 2`}},
|
|
{"[1", []string{`Error: unexpected end of file (expected an array separator) at line 1, column 3`}},
|
|
{"[]", []string{`[]`}},
|
|
{"[\n]", []string{`[]`}},
|
|
{"[,]", []string{`[]`}},
|
|
{"[ , ]", []string{`[]`}},
|
|
{"[ \n , \r\n ]", []string{`[]`}},
|
|
{"[ \t , \t ]", []string{`[]`}},
|
|
{"[\r\n\r\n , \r\n \t\n]", []string{`[]`}},
|
|
{"[\n#comment on its own line\n]", []string{`[]`}},
|
|
{"[#comment before close\n]", []string{`[]`}},
|
|
{"[,#comment after separator\n]", []string{`[]`}},
|
|
{"[#comment before separator\n,]", []string{`[]`}},
|
|
{"[#comment before value\n1]", []string{`[1]`}},
|
|
{"[1#comment after value\n]", []string{`[1]`}},
|
|
{"[1\n#comment on its own line after value\n]", []string{`[1]`}},
|
|
{"[1#comment 1\n#comment 2\n#comment 3\n , \n2]", []string{`[1, 2]`}},
|
|
{"[1]", []string{`[1]`}},
|
|
{"[1,0x2, 0b11, 0o4]", []string{`[1, 2, 3, 4]`}},
|
|
{"[0.1,0.2,3e-1,0.04e+1, nan, inf]", []string{`[0.1, 0.2, 0.3, 0.4, NaN, +Inf]`}},
|
|
{"[\n\t 'a', \"b\", '''c''', \"\"\"d\ne\"\"\",\n \t]", []string{`["a", "b", "c", "d\ne"]`}},
|
|
{`[1, 2, 3, "four"]`, []string{`Error: type mismatch in array of integers: found an item of type string at line 1, column 17`}},
|
|
{`[[1],['a']]`, []string{`[[1], ["a"]]`}},
|
|
{`[[[],[]],[]]`, []string{`[[[], []], []]`}},
|
|
{"[\r\n\r\n \t\n [\r\n\r\n\t [],[\t]],\t\n[]\t \t \n ]", []string{`[[[], []], []]`}},
|
|
{`[[1],'a']`, []string{`Error: type mismatch in array of static arrays: found an item of type string at line 1, column 9`}},
|
|
} {
|
|
p := newParser()
|
|
testParseHandler(t, p, p.startArray, test)
|
|
}
|
|
}
|