package parse

import (
	"testing"

	"git.makaay.nl/mauricem/go-parsekit/parse"
)

func TestStartArray(t *testing.T) {
	parser := newParser()
	wrapper := func(p *parse.API) { parser.parseArray(p) }
	testParse(t, parser, wrapper, parseTest{"INVALID", "{}", "unexpected input (expected an array) at start of file"})
}

func TestArray(t *testing.T) {
	for _, test := range []parseTest{
		// {"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=[]", `{"x": []}`, ``},
		// {"x=[\n]", `{"x": []}`, ``},
		// {"x=[,]", `{"x": []}`, ``},
		// {"x=[ , ]", `{"x": []}`, ``},
		// {"x=[ \n , \r\n ]", `{"x": []}`, ``},
		// {"x=[ \t , \t ]", `{"x": []}`, ``},
		// {"x=[\r\n\r\n   ,   \r\n  \t\n]", `{"x": []}`, ``},
		// {"x=[\n#comment on its own line\n]", `{"x": []}`, ``},
		// {"x=[#comment before close\n]", `{"x": []}`, ``},
		// {"x=[,#comment after separator\n]", `{"x": []}`, ``},
		// {"x=[#comment before separator\n,]", `{"x": []}`, ``},
		// {"x=[#comment before value\n1]", `{"x": [1]}`, ``},
		// {"x=[1#comment after value\n]", `{"x": [1]}`, ``},
		// {"x=[1\n#comment on its own line after value\n]", `{"x": [1]}`, ``},
		// {"x=[1#comment 1\n,\n2]", `{}`, `unexpected input (expected an array separator) at line 1, column 5`},
		// {"#\nx=[ #\n1,#\n2 #\n]#\n#\n", `{"x": [1, 2]}`, ``},
		// Freak case that I ran into during optimization of the code.
		// It failed with 'unexpected input (expected an array separator) at line 4, column 2'.
		{"#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\na=[\n123,\n456]", `{"a": [123, 456]}`, ``},
		// {"x=[1]", `{"x": [1]}`, ``},
		// {"x=[1,0x2, 0b11, 0o4]", `{"x": [1, 2, 3, 4]}`, ``},
		// {"x=[0.1,0.2,3e-1,0.04e+1, nan, inf]", `{"x": [0.1, 0.2, 0.3, 0.4, NaN, +Inf]}`, ``},
		// {"x=[\n\t 'a', \"b\", '''c''', \"\"\"d\ne\"\"\",\n \t]", `{"x": ["a", "b", "c", "d\ne"]}`, ``},
		// {`x=[1, 2, 3, "four"]`, `{}`, `type mismatch in array of integers: found an item of type string at line 1, column 19`},
		// {`x=[[1],['a']]`, `{"x": [[1], ["a"]]}`, ``},
		// {`x=[[[],[]],[]]`, `{"x": [[[], []], []]}`, ``},
		// {"x=[\r\n\r\n \t\n [\r\n\r\n\t  [],[\t]],\t\n[]\t \t \n   ]", `{"x": [[[], []], []]}`, ``},
		// {`x=[[1],'a']`, `{}`, `type mismatch in array of arrays: found an item of type string at line 1, column 11`},
	} {
		p := newParser()
		testParse(t, p, p.startDocument, test)
	}
}
