Brought test coverage too 100%.
This commit is contained in:
parent
608e68c207
commit
97153fc806
|
@ -5,7 +5,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestComment2(t *testing.T) {
|
func TestComment2(t *testing.T) {
|
||||||
for _, test := range []parseToASTTest{
|
for _, test := range []parseTest{
|
||||||
{``, `{}`, `unexpected end of file (expected comment) at start of file`},
|
{``, `{}`, `unexpected end of file (expected comment) at start of file`},
|
||||||
{`#`, `{}`, ``},
|
{`#`, `{}`, ``},
|
||||||
{`# `, `{}`, ``},
|
{`# `, `{}`, ``},
|
||||||
|
@ -16,6 +16,6 @@ func TestComment2(t *testing.T) {
|
||||||
{"# with data and newline\ncode continues here", `{}`, `unexpected input (expected end of file) at line 2, column 1`},
|
{"# with data and newline\ncode continues here", `{}`, `unexpected input (expected end of file) at line 2, column 1`},
|
||||||
} {
|
} {
|
||||||
p := newParser()
|
p := newParser()
|
||||||
testParseToAST(t, p, p.startComment, test)
|
testParse(t, p, p.startComment, test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,13 +28,13 @@ func testAST(t *testing.T, code func() (error, *parser), expectedError string, e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type parseToASTTest struct {
|
type parseTest struct {
|
||||||
input interface{}
|
input interface{}
|
||||||
expected string
|
expected string
|
||||||
expectedError string
|
expectedError string
|
||||||
}
|
}
|
||||||
|
|
||||||
func testParseToAST(t *testing.T, p *parser, handler parse.Handler, test parseToASTTest) {
|
func testParse(t *testing.T, p *parser, handler parse.Handler, test parseTest) {
|
||||||
var err error
|
var err error
|
||||||
defer func() {
|
defer func() {
|
||||||
recovered := recover()
|
recovered := recover()
|
||||||
|
|
|
@ -3,7 +3,7 @@ package toml
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestKey(t *testing.T) {
|
func TestKey(t *testing.T) {
|
||||||
for _, test := range []parseToASTTest{
|
for _, test := range []parseTest{
|
||||||
// Bare key tests
|
// Bare key tests
|
||||||
{"barekey=0", `{"barekey": 0}`, ``},
|
{"barekey=0", `{"barekey": 0}`, ``},
|
||||||
{"1234567=0", `{"1234567": 0}`, ``},
|
{"1234567=0", `{"1234567": 0}`, ``},
|
||||||
|
@ -24,16 +24,17 @@ func TestKey(t *testing.T) {
|
||||||
{`"double quoted"=0`, `{"double quoted": 0}`, ``},
|
{`"double quoted"=0`, `{"double quoted": 0}`, ``},
|
||||||
{`"escapes are in\terpreted"=0`, `{"escapes are in\terpreted": 0}`, ``},
|
{`"escapes are in\terpreted"=0`, `{"escapes are in\terpreted": 0}`, ``},
|
||||||
{`"using 'inner' \"quotes\""=0`, `{"using 'inner' \"quotes\"": 0}`, ``},
|
{`"using 'inner' \"quotes\""=0`, `{"using 'inner' \"quotes\"": 0}`, ``},
|
||||||
|
{`"invalid \xcd string"=0`, `{}`, "invalid escape sequence at line 1, column 10"},
|
||||||
// Mixed key types
|
// Mixed key types
|
||||||
{`this.'i\s'."madness\t".''=0`, `{"this": {"i\\s": {"madness\t": {"": 0}}}}`, ``},
|
{`this.'i\s'."madness\t".''=0`, `{"this": {"i\\s": {"madness\t": {"": 0}}}}`, ``},
|
||||||
} {
|
} {
|
||||||
p := newParser()
|
p := newParser()
|
||||||
testParseToAST(t, p, p.startKeyValuePair, test)
|
testParse(t, p, p.startKeyValuePair, test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestKeyValuePair(t *testing.T) {
|
func TestKeyValuePair(t *testing.T) {
|
||||||
for _, test := range []parseToASTTest{
|
for _, test := range []parseTest{
|
||||||
{``, `{}`, ``},
|
{``, `{}`, ``},
|
||||||
{` `, `{}`, ``},
|
{` `, `{}`, ``},
|
||||||
{" \t ", `{}`, ``},
|
{" \t ", `{}`, ``},
|
||||||
|
@ -49,12 +50,12 @@ func TestKeyValuePair(t *testing.T) {
|
||||||
{"with=\"comments\"# boring \nanother.cool =\"one\" \t # to the end\r\n", `{"another": {"cool": "one"}, "with": "comments"}`, ``},
|
{"with=\"comments\"# boring \nanother.cool =\"one\" \t # to the end\r\n", `{"another": {"cool": "one"}, "with": "comments"}`, ``},
|
||||||
} {
|
} {
|
||||||
p := newParser()
|
p := newParser()
|
||||||
testParseToAST(t, p, p.startKeyValuePair, test)
|
testParse(t, p, p.startKeyValuePair, test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestKeyValuePair_ForAllTypes(t *testing.T) {
|
func TestKeyValuePair_ForAllTypes(t *testing.T) {
|
||||||
for _, test := range []parseToASTTest{
|
for _, test := range []parseTest{
|
||||||
{"string='literal'", `{"string": "literal"}`, ``},
|
{"string='literal'", `{"string": "literal"}`, ``},
|
||||||
{"string='''literal\nmulti-line'''", `{"string": "literal\nmulti-line"}`, ``},
|
{"string='''literal\nmulti-line'''", `{"string": "literal\nmulti-line"}`, ``},
|
||||||
{`string="basic"`, `{"string": "basic"}`, ``},
|
{`string="basic"`, `{"string": "basic"}`, ``},
|
||||||
|
@ -76,12 +77,12 @@ func TestKeyValuePair_ForAllTypes(t *testing.T) {
|
||||||
{"static_array=['a', 'static', 'array']", `{"static_array": ["a", "static", "array"]}`, ``},
|
{"static_array=['a', 'static', 'array']", `{"static_array": ["a", "static", "array"]}`, ``},
|
||||||
} {
|
} {
|
||||||
p := newParser()
|
p := newParser()
|
||||||
testParseToAST(t, p, p.startKeyValuePair, test)
|
testParse(t, p, p.startKeyValuePair, test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestKeyValuePair_ExamplesFromSpecification(t *testing.T) {
|
func TestKeyValuePair_ExamplesFromSpecification(t *testing.T) {
|
||||||
for _, test := range []parseToASTTest{
|
for _, test := range []parseTest{
|
||||||
{"int1 = +99", `{"int1": 99}`, ``},
|
{"int1 = +99", `{"int1": 99}`, ``},
|
||||||
{"int2 = 42", `{"int2": 42}`, ``},
|
{"int2 = 42", `{"int2": 42}`, ``},
|
||||||
{"int3 = 0", `{"int3": 0}`, ``},
|
{"int3 = 0", `{"int3": 0}`, ``},
|
||||||
|
@ -130,6 +131,6 @@ func TestKeyValuePair_ExamplesFromSpecification(t *testing.T) {
|
||||||
{"arr8 = [\n 1,\n 2, # this is ok\n]", `{"arr8": [1, 2]}`, ``},
|
{"arr8 = [\n 1,\n 2, # this is ok\n]", `{"arr8": [1, 2]}`, ``},
|
||||||
} {
|
} {
|
||||||
p := newParser()
|
p := newParser()
|
||||||
testParseToAST(t, p, p.startKeyValuePair, test)
|
testParse(t, p, p.startKeyValuePair, test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,14 +6,14 @@ import (
|
||||||
"git.makaay.nl/mauricem/go-parsekit/parse"
|
"git.makaay.nl/mauricem/go-parsekit/parse"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestArrayStart(t *testing.T) {
|
func TestStartArray(t *testing.T) {
|
||||||
parser := newParser()
|
parser := newParser()
|
||||||
wrapper := func(p *parse.API) { parser.parseArray(p) }
|
wrapper := func(p *parse.API) { parser.parseArray(p) }
|
||||||
testParseToAST(t, parser, wrapper, parseToASTTest{"INVALID", "{}", "unexpected input (expected an array) at start of file"})
|
testParse(t, parser, wrapper, parseTest{"INVALID", "{}", "unexpected input (expected an array) at start of file"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestArray(t *testing.T) {
|
func TestArray(t *testing.T) {
|
||||||
for _, test := range []parseToASTTest{
|
for _, test := range []parseTest{
|
||||||
{"x=[ape", `{}`, `unexpected input (expected a value) at line 1, column 4`},
|
{"x=[ape", `{}`, `unexpected input (expected a value) at line 1, column 4`},
|
||||||
{"x=[1", `{}`, `unexpected end of file (expected an array separator) at line 1, column 5`},
|
{"x=[1", `{}`, `unexpected end of file (expected an array separator) at line 1, column 5`},
|
||||||
{"x=[]", `{"x": []}`, ``},
|
{"x=[]", `{"x": []}`, ``},
|
||||||
|
@ -42,6 +42,6 @@ func TestArray(t *testing.T) {
|
||||||
{`x=[[1],'a']`, `{}`, `type mismatch in array of static arrays: found an item of type string at line 1, column 11`},
|
{`x=[[1],'a']`, `{}`, `type mismatch in array of static arrays: found an item of type string at line 1, column 11`},
|
||||||
} {
|
} {
|
||||||
p := newParser()
|
p := newParser()
|
||||||
testParseToAST(t, p, p.startKeyValuePair, test)
|
testParse(t, p, p.startKeyValuePair, test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,14 +6,14 @@ import (
|
||||||
"git.makaay.nl/mauricem/go-parsekit/parse"
|
"git.makaay.nl/mauricem/go-parsekit/parse"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBooleanStart(t *testing.T) {
|
func TestStartBoolean(t *testing.T) {
|
||||||
parser := newParser()
|
parser := newParser()
|
||||||
wrapper := func(p *parse.API) { parser.parseBoolean(p) }
|
wrapper := func(p *parse.API) { parser.parseBoolean(p) }
|
||||||
testParseToAST(t, parser, wrapper, parseToASTTest{"INVALID", "{}", "unexpected input (expected true or false) at start of file"})
|
testParse(t, parser, wrapper, parseTest{"INVALID", "{}", "unexpected input (expected true or false) at start of file"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBoolean(t *testing.T) {
|
func TestBoolean(t *testing.T) {
|
||||||
for _, test := range []parseToASTTest{
|
for _, test := range []parseTest{
|
||||||
{`x=true`, `{"x": true}`, ``},
|
{`x=true`, `{"x": true}`, ``},
|
||||||
{`x=false`, `{"x": false}`, ``},
|
{`x=false`, `{"x": false}`, ``},
|
||||||
{`x=yes`, `{}`, `unexpected input (expected a value) at line 1, column 3`},
|
{`x=yes`, `{}`, `unexpected input (expected a value) at line 1, column 3`},
|
||||||
|
@ -22,6 +22,6 @@ func TestBoolean(t *testing.T) {
|
||||||
{`x=0`, `{"x": 0}`, ``},
|
{`x=0`, `{"x": 0}`, ``},
|
||||||
} {
|
} {
|
||||||
p := newParser()
|
p := newParser()
|
||||||
testParseToAST(t, p, p.startKeyValuePair, test)
|
testParse(t, p, p.startKeyValuePair, test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,14 +6,14 @@ import (
|
||||||
"git.makaay.nl/mauricem/go-parsekit/parse"
|
"git.makaay.nl/mauricem/go-parsekit/parse"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDateTimeStart(t *testing.T) {
|
func TestStartDateTime(t *testing.T) {
|
||||||
parser := newParser()
|
parser := newParser()
|
||||||
wrapper := func(p *parse.API) { parser.parseDateTime(p) }
|
wrapper := func(p *parse.API) { parser.parseDateTime(p) }
|
||||||
testParseToAST(t, parser, wrapper, parseToASTTest{"INVALID", "{}", "unexpected input (expected a date and/or time) at start of file"})
|
testParse(t, parser, wrapper, parseTest{"INVALID", "{}", "unexpected input (expected a date and/or time) at start of file"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDateTime(t *testing.T) {
|
func TestDateTime(t *testing.T) {
|
||||||
for _, test := range []parseToASTTest{
|
for _, test := range []parseTest{
|
||||||
{`x=1979-05-27`, `{"x": 1979-05-27}`, ``},
|
{`x=1979-05-27`, `{"x": 1979-05-27}`, ``},
|
||||||
{`x=00:00:00`, `{"x": 00:00:00}`, ``},
|
{`x=00:00:00`, `{"x": 00:00:00}`, ``},
|
||||||
{`x=23:59:59`, `{"x": 23:59:59}`, ``},
|
{`x=23:59:59`, `{"x": 23:59:59}`, ``},
|
||||||
|
@ -35,6 +35,6 @@ func TestDateTime(t *testing.T) {
|
||||||
{`x=25:01:01`, `{}`, `invalid date/time value 25:01:01: parsing time "25:01:01": hour out of range at line 1, column 11`},
|
{`x=25:01:01`, `{}`, `invalid date/time value 25:01:01: parsing time "25:01:01": hour out of range at line 1, column 11`},
|
||||||
} {
|
} {
|
||||||
p := newParser()
|
p := newParser()
|
||||||
testParseToAST(t, p, p.startKeyValuePair, test)
|
testParse(t, p, p.startKeyValuePair, test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,14 +6,14 @@ import (
|
||||||
"git.makaay.nl/mauricem/go-parsekit/parse"
|
"git.makaay.nl/mauricem/go-parsekit/parse"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNumberStart(t *testing.T) {
|
func TestStartNumber(t *testing.T) {
|
||||||
parser := newParser()
|
parser := newParser()
|
||||||
wrapper := func(p *parse.API) { parser.parseNumber(p) }
|
wrapper := func(p *parse.API) { parser.parseNumber(p) }
|
||||||
testParseToAST(t, parser, wrapper, parseToASTTest{"INVALID", "{}", "unexpected input (expected a number) at start of file"})
|
testParse(t, parser, wrapper, parseTest{"INVALID", "{}", "unexpected input (expected a number) at start of file"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInteger(t *testing.T) {
|
func TestInteger(t *testing.T) {
|
||||||
for _, test := range []parseToASTTest{
|
for _, test := range []parseTest{
|
||||||
// Decimal
|
// Decimal
|
||||||
{`x=0`, `{"x": 0}`, ``},
|
{`x=0`, `{"x": 0}`, ``},
|
||||||
{`x=+0`, `{"x": 0}`, ``},
|
{`x=+0`, `{"x": 0}`, ``},
|
||||||
|
@ -75,12 +75,12 @@ func TestInteger(t *testing.T) {
|
||||||
{`x=0b10000000_00000000_00000000_00000000_00000000_00000000_00000000_00000000`, `{}`, `invalid integer value 0b1000000000000000000000000000000000000000000000000000000000000000: strconv.ParseInt: parsing "1000000000000000000000000000000000000000000000000000000000000000": value out of range at line 1, column 76`},
|
{`x=0b10000000_00000000_00000000_00000000_00000000_00000000_00000000_00000000`, `{}`, `invalid integer value 0b1000000000000000000000000000000000000000000000000000000000000000: strconv.ParseInt: parsing "1000000000000000000000000000000000000000000000000000000000000000": value out of range at line 1, column 76`},
|
||||||
} {
|
} {
|
||||||
p := newParser()
|
p := newParser()
|
||||||
testParseToAST(t, p, p.startKeyValuePair, test)
|
testParse(t, p, p.startKeyValuePair, test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFloat(t *testing.T) {
|
func TestFloat(t *testing.T) {
|
||||||
for _, test := range []parseToASTTest{
|
for _, test := range []parseTest{
|
||||||
{`x=0.0`, `{"x": 0}`, ``},
|
{`x=0.0`, `{"x": 0}`, ``},
|
||||||
{`x=+0.0`, `{"x": 0}`, ``},
|
{`x=+0.0`, `{"x": 0}`, ``},
|
||||||
{`x=-0.0`, `{"x": -0}`, ``},
|
{`x=-0.0`, `{"x": -0}`, ``},
|
||||||
|
@ -101,6 +101,6 @@ func TestFloat(t *testing.T) {
|
||||||
{`x=-inf`, `{"x": -Inf}`, ``},
|
{`x=-inf`, `{"x": -Inf}`, ``},
|
||||||
} {
|
} {
|
||||||
p := newParser()
|
p := newParser()
|
||||||
testParseToAST(t, p, p.startKeyValuePair, test)
|
testParse(t, p, p.startKeyValuePair, test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,42 @@ package toml
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"git.makaay.nl/mauricem/go-parsekit/parse"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestStartString(t *testing.T) {
|
||||||
|
parser := newParser()
|
||||||
|
wrapper := func(p *parse.API) { parser.parseString(p) }
|
||||||
|
testParse(t, parser, wrapper, parseTest{"(not a string)", "{}", "unexpected input (expected a string value) at start of file"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStartBasicString(t *testing.T) {
|
||||||
|
parser := newParser()
|
||||||
|
wrapper := func(p *parse.API) { parser.parseBasicString("xyz", p) }
|
||||||
|
testParse(t, parser, wrapper, parseTest{"(not a string)", "{}", "unexpected input (expected opening quotation marks) at start of file"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStartLiteralString(t *testing.T) {
|
||||||
|
parser := newParser()
|
||||||
|
wrapper := func(p *parse.API) { parser.parseLiteralString("xyz", p) }
|
||||||
|
testParse(t, parser, wrapper, parseTest{"(not a string)", "{}", "unexpected input (expected opening single quote) at start of file"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStartMultiLineBasicString(t *testing.T) {
|
||||||
|
parser := newParser()
|
||||||
|
wrapper := func(p *parse.API) { parser.parseMultiLineBasicString(p) }
|
||||||
|
testParse(t, parser, wrapper, parseTest{"(not a string)", "{}", "unexpected input (expected opening three quotation marks) at start of file"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStartMultiLineLiteralString(t *testing.T) {
|
||||||
|
parser := newParser()
|
||||||
|
wrapper := func(p *parse.API) { parser.parseMultiLineLiteralString(p) }
|
||||||
|
testParse(t, parser, wrapper, parseTest{"(not a string)", "{}", "unexpected input (expected opening three single quotes) at start of file"})
|
||||||
|
}
|
||||||
|
|
||||||
func TestString(t *testing.T) {
|
func TestString(t *testing.T) {
|
||||||
for _, test := range []parseToASTTest{
|
for _, test := range []parseTest{
|
||||||
{`x=no start quote"`, `{}`, `unexpected input (expected a value) at line 1, column 3`},
|
{`x=no start quote"`, `{}`, `unexpected input (expected a value) at line 1, column 3`},
|
||||||
{`x="basic s\tring"`, `{"x": "basic s\tring"}`, ``},
|
{`x="basic s\tring"`, `{"x": "basic s\tring"}`, ``},
|
||||||
{"x=\"\"\"\n basic multi-line\n string value\n\"\"\"", `{"x": " basic multi-line\n string value\n"}`, ``},
|
{"x=\"\"\"\n basic multi-line\n string value\n\"\"\"", `{"x": " basic multi-line\n string value\n"}`, ``},
|
||||||
|
@ -14,12 +46,12 @@ func TestString(t *testing.T) {
|
||||||
{"x='''\n literal multi-line\n string value\n'''", `{"x": " literal multi-line\n string value\n"}`, ``},
|
{"x='''\n literal multi-line\n string value\n'''", `{"x": " literal multi-line\n string value\n"}`, ``},
|
||||||
} {
|
} {
|
||||||
p := newParser()
|
p := newParser()
|
||||||
testParseToAST(t, p, p.startKeyValuePair, test)
|
testParse(t, p, p.startKeyValuePair, test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBasipString(t *testing.T) {
|
func TestBasipString(t *testing.T) {
|
||||||
for _, test := range []parseToASTTest{
|
for _, test := range []parseTest{
|
||||||
{`x="no end quote`, `{}`, `unexpected end of file (expected closing quotation marks) at line 1, column 16`},
|
{`x="no end quote`, `{}`, `unexpected end of file (expected closing quotation marks) at line 1, column 16`},
|
||||||
{`x=""`, `{"x": ""}`, ``},
|
{`x=""`, `{"x": ""}`, ``},
|
||||||
{`x="simple string"`, `{"x": "simple string"}`, ``},
|
{`x="simple string"`, `{"x": "simple string"}`, ``},
|
||||||
|
@ -33,12 +65,12 @@ func TestBasipString(t *testing.T) {
|
||||||
{"x=\"Character that must be escaped \x7f\"", `{}`, `invalid character in string value: '\u007f' (must be escaped) at line 1, column 35`},
|
{"x=\"Character that must be escaped \x7f\"", `{}`, `invalid character in string value: '\u007f' (must be escaped) at line 1, column 35`},
|
||||||
} {
|
} {
|
||||||
p := newParser()
|
p := newParser()
|
||||||
testParseToAST(t, p, p.startKeyValuePair, test)
|
testParse(t, p, p.startKeyValuePair, test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMultiLineBasipString(t *testing.T) {
|
func TestMultiLineBasipString(t *testing.T) {
|
||||||
for _, test := range []parseToASTTest{
|
for _, test := range []parseTest{
|
||||||
{`x="""missing close quote""`, `{}`, `unexpected end of file (expected closing three quotation marks) at line 1, column 27`},
|
{`x="""missing close quote""`, `{}`, `unexpected end of file (expected closing three quotation marks) at line 1, column 27`},
|
||||||
{`x=""""""`, `{"x": ""}`, ``},
|
{`x=""""""`, `{"x": ""}`, ``},
|
||||||
{"x=\"\"\"\n\"\"\"", `{"x": ""}`, ``},
|
{"x=\"\"\"\n\"\"\"", `{"x": ""}`, ``},
|
||||||
|
@ -51,12 +83,12 @@ func TestMultiLineBasipString(t *testing.T) {
|
||||||
{"x=\"\"\"Invalid rune \xcd\"\"\"", `{}`, `invalid UTF8 rune at line 1, column 19`},
|
{"x=\"\"\"Invalid rune \xcd\"\"\"", `{}`, `invalid UTF8 rune at line 1, column 19`},
|
||||||
} {
|
} {
|
||||||
p := newParser()
|
p := newParser()
|
||||||
testParseToAST(t, p, p.startKeyValuePair, test)
|
testParse(t, p, p.startKeyValuePair, test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLiteralString(t *testing.T) {
|
func TestLiteralString(t *testing.T) {
|
||||||
for _, test := range []parseToASTTest{
|
for _, test := range []parseTest{
|
||||||
{`x='missing close quote`, `{}`, `unexpected end of file (expected closing single quote) at line 1, column 23`},
|
{`x='missing close quote`, `{}`, `unexpected end of file (expected closing single quote) at line 1, column 23`},
|
||||||
{`x=''`, `{"x": ""}`, ``},
|
{`x=''`, `{"x": ""}`, ``},
|
||||||
{`x='simple'`, `{"x": "simple"}`, ``},
|
{`x='simple'`, `{"x": "simple"}`, ``},
|
||||||
|
@ -69,12 +101,12 @@ func TestLiteralString(t *testing.T) {
|
||||||
{"x='Invalid rune \xcd'", `{}`, `invalid UTF8 rune at line 1, column 17`},
|
{"x='Invalid rune \xcd'", `{}`, `invalid UTF8 rune at line 1, column 17`},
|
||||||
} {
|
} {
|
||||||
p := newParser()
|
p := newParser()
|
||||||
testParseToAST(t, p, p.startKeyValuePair, test)
|
testParse(t, p, p.startKeyValuePair, test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMultiLineLiteralString(t *testing.T) {
|
func TestMultiLineLiteralString(t *testing.T) {
|
||||||
for _, test := range []parseToASTTest{
|
for _, test := range []parseTest{
|
||||||
{`x='''missing close quote''`, `{}`, `unexpected end of file (expected closing three single quotes) at line 1, column 27`},
|
{`x='''missing close quote''`, `{}`, `unexpected end of file (expected closing three single quotes) at line 1, column 27`},
|
||||||
{`x=''''''`, `{"x": ""}`, ``},
|
{`x=''''''`, `{"x": ""}`, ``},
|
||||||
{"x='''\n'''", `{"x": ""}`, ``},
|
{"x='''\n'''", `{"x": ""}`, ``},
|
||||||
|
@ -84,7 +116,7 @@ func TestMultiLineLiteralString(t *testing.T) {
|
||||||
{"x='''No invalid runes allowed \xcd'''", `{}`, `invalid UTF8 rune at line 1, column 31`},
|
{"x='''No invalid runes allowed \xcd'''", `{}`, `invalid UTF8 rune at line 1, column 31`},
|
||||||
} {
|
} {
|
||||||
p := newParser()
|
p := newParser()
|
||||||
testParseToAST(t, p, p.startKeyValuePair, test)
|
testParse(t, p, p.startKeyValuePair, test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,6 +127,6 @@ func TestBasipStringWithUnescapedControlCharacters(t *testing.T) {
|
||||||
p := newParser()
|
p := newParser()
|
||||||
input := fmt.Sprintf(`x="%c"`, rune(i))
|
input := fmt.Sprintf(`x="%c"`, rune(i))
|
||||||
expected := fmt.Sprintf(`invalid character in string value: %q (must be escaped) at line 1, column 4`, rune(i))
|
expected := fmt.Sprintf(`invalid character in string value: %q (must be escaped) at line 1, column 4`, rune(i))
|
||||||
testParseToAST(t, p, p.startKeyValuePair, parseToASTTest{input, "{}", expected})
|
testParse(t, p, p.startKeyValuePair, parseTest{input, "{}", expected})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,18 @@ package toml
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"git.makaay.nl/mauricem/go-parsekit/parse"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestStartTable(t *testing.T) {
|
||||||
|
parser := newParser()
|
||||||
|
wrapper := func(p *parse.API) { parser.startTable(p) }
|
||||||
|
testParse(t, parser, wrapper, parseTest{"(not a table)", "{}", "unexpected input (expected a table) at start of file"})
|
||||||
|
}
|
||||||
|
|
||||||
func TestTableKey(t *testing.T) {
|
func TestTableKey(t *testing.T) {
|
||||||
for _, test := range []parseToASTTest{
|
for _, test := range []parseTest{
|
||||||
{"[", `{}`, `unexpected end of file (expected a key name) at line 1, column 2`},
|
{"[", `{}`, `unexpected end of file (expected a key name) at line 1, column 2`},
|
||||||
{" \t [", `{}`, `unexpected end of file (expected a key name) at line 1, column 5`},
|
{" \t [", `{}`, `unexpected end of file (expected a key name) at line 1, column 5`},
|
||||||
{" \t [key", `{}`, `unexpected end of file (expected closing ']' for table name) at line 1, column 8`},
|
{" \t [key", `{}`, `unexpected end of file (expected closing ']' for table name) at line 1, column 8`},
|
||||||
|
@ -18,12 +26,12 @@ func TestTableKey(t *testing.T) {
|
||||||
{" \t [key.'sub key' \t] \t # with comment\n", `{"key": {"sub key": {}}}`, ``},
|
{" \t [key.'sub key' \t] \t # with comment\n", `{"key": {"sub key": {}}}`, ``},
|
||||||
} {
|
} {
|
||||||
p := newParser()
|
p := newParser()
|
||||||
testParseToAST(t, p, p.startTable, test)
|
testParse(t, p, p.startTable, test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTable(t *testing.T) {
|
func TestTable(t *testing.T) {
|
||||||
for _, test := range []parseToASTTest{
|
for _, test := range []parseTest{
|
||||||
{"[a]", `{"a": {}}`, ``},
|
{"[a]", `{"a": {}}`, ``},
|
||||||
{"['a key']", `{"a key": {}}`, ``},
|
{"['a key']", `{"a key": {}}`, ``},
|
||||||
{"[\"a key\"]", `{"a key": {}}`, ``},
|
{"[\"a key\"]", `{"a key": {}}`, ``},
|
||||||
|
@ -35,14 +43,15 @@ func TestTable(t *testing.T) {
|
||||||
{"[a]\n[b] #another table \na=1\n", `{"a": {}, "b": {"a": 1}}`, ``},
|
{"[a]\n[b] #another table \na=1\n", `{"a": {}, "b": {"a": 1}}`, ``},
|
||||||
{"[a]\nx=1\ny=2\n[b] #another table \nx=1\ny=2021-01-01", `{"a": {"x": 1, "y": 2}, "b": {"x": 1, "y": 2021-01-01}}`, ``},
|
{"[a]\nx=1\ny=2\n[b] #another table \nx=1\ny=2021-01-01", `{"a": {"x": 1, "y": 2}, "b": {"x": 1, "y": 2021-01-01}}`, ``},
|
||||||
{"[a]\nx=1\ny=2\n[a.b] #subtable \nx=1\ny=2021-01-01", `{"a": {"b": {"x": 1, "y": 2021-01-01}, "x": 1, "y": 2}}`, ``},
|
{"[a]\nx=1\ny=2\n[a.b] #subtable \nx=1\ny=2021-01-01", `{"a": {"b": {"x": 1, "y": 2021-01-01}, "x": 1, "y": 2}}`, ``},
|
||||||
|
{"[a]\n[a]", `{"a": {}}`, `invalid table: table item already exists at key [a] at line 2, column 4`},
|
||||||
} {
|
} {
|
||||||
p := newParser()
|
p := newParser()
|
||||||
testParseToAST(t, p, p.startTable, test)
|
testParse(t, p, p.startTable, test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestArrayOfTableKey(t *testing.T) {
|
func TestArrayOfTableKey(t *testing.T) {
|
||||||
for _, test := range []parseToASTTest{
|
for _, test := range []parseTest{
|
||||||
{"[[", `{}`, `unexpected end of file (expected a key name) at line 1, column 3`},
|
{"[[", `{}`, `unexpected end of file (expected a key name) at line 1, column 3`},
|
||||||
{" \t [[", `{}`, `unexpected end of file (expected a key name) at line 1, column 6`},
|
{" \t [[", `{}`, `unexpected end of file (expected a key name) at line 1, column 6`},
|
||||||
{" \t [[key", `{}`, `unexpected end of file (expected closing ']]' for array of tables name) at line 1, column 9`},
|
{" \t [[key", `{}`, `unexpected end of file (expected closing ']]' for array of tables name) at line 1, column 9`},
|
||||||
|
@ -55,19 +64,20 @@ func TestArrayOfTableKey(t *testing.T) {
|
||||||
{" \t [[key.'sub key' \t]] \t # with comment\n", `{"key": {"sub key": [{}]}}`, ``},
|
{" \t [[key.'sub key' \t]] \t # with comment\n", `{"key": {"sub key": [{}]}}`, ``},
|
||||||
} {
|
} {
|
||||||
p := newParser()
|
p := newParser()
|
||||||
testParseToAST(t, p, p.startTable, test)
|
testParse(t, p, p.startTable, test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestArrayOfTables(t *testing.T) {
|
func TestArrayOfTables(t *testing.T) {
|
||||||
for _, test := range []parseToASTTest{
|
for _, test := range []parseTest{
|
||||||
{"[[a]]", `{"a": [{}]}`, ``},
|
{"[[a]]", `{"a": [{}]}`, ``},
|
||||||
{"[[a]]\n[['a']]\n[[\"a\"]]", `{"a": [{}, {}, {}]}`, ``},
|
{"[[a]]\n[['a']]\n[[\"a\"]]", `{"a": [{}, {}, {}]}`, ``},
|
||||||
{"[[a]]\n[['a']]\n[b]\n[[\"a\"]]", `{"a": [{}, {}, {}], "b": {}}`, ``},
|
{"[[a]]\n[['a']]\n[b]\n[[\"a\"]]", `{"a": [{}, {}, {}], "b": {}}`, ``},
|
||||||
{"[[a]]\nx=1\n[['a']]\nx=2\ny=3\n[[\"a\"]]", `{"a": [{"x": 1}, {"x": 2, "y": 3}, {}]}`, ``},
|
{"[[a]]\nx=1\n[['a']]\nx=2\ny=3\n[[\"a\"]]", `{"a": [{"x": 1}, {"x": 2, "y": 3}, {}]}`, ``},
|
||||||
{"[a]\n[[a.b]]\nx=1\n[[a.b]]\nx=2\n[a.c]\ny=1234", `{"a": {"b": [{"x": 1}, {"x": 2}], "c": {"y": 1234}}}`, ``},
|
{"[a]\n[[a.b]]\nx=1\n[[a.b]]\nx=2\n[a.c]\ny=1234", `{"a": {"b": [{"x": 1}, {"x": 2}], "c": {"y": 1234}}}`, ``},
|
||||||
|
{"[a]\n[[a]]", `{"a": {}}`, `invalid table array: table item already exists at key [a] at line 2, column 6`},
|
||||||
} {
|
} {
|
||||||
p := newParser()
|
p := newParser()
|
||||||
testParseToAST(t, p, p.startTable, test)
|
testParse(t, p, p.startTable, test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue