// The main testing is via conformance checking in this file. Here
// we'll only add a few basic tests and more tests for specific
// regressions as they are encountered.
The main testing is via conformance checking in this file. Here
we'll only add a few basic tests and more tests for specific
regressions as they are encountered.
// The main testing is via conformance checking in this file . Here // we ' ll only add a few basic tests and more tests for specific // regressions as they are encountered .
func TestFlattenerRegressions(t *testing.T) {
	t.Run("single value", func(t *testing.T) {
		tests := []flattenerTest{
			{
				input: "{}",
				output: []pair{
					{path: ".", value: "{}"},
				},
			},
			{
				input: "[]",
				output: []pair{
					{path: ".", value: "[]"},
				},
			},
			{
				input: "unquoted",
				output: []pair{
					{path: ".", value: "unquoted"},
				},
			},
			{
				input: `"quoted"`,
				output: []pair{
					{path: ".", value: `"quoted"`},
				},
			},
			{
				input: `{ "user": "bob", "friends": [ "alice" ] }`,
				output: []pair{
					{path: ".", value: "{}"},
					{path: `."user"`, value: `"bob"`},
					{path: `."friends"`, value: "[]"},
					{path: `."friends"[0]`, value: `"alice"`},
				},
			},
			{
				input: `1 2`,
				output: []pair{
					{path: ".", value: "1"},
					{err: errors.New("expected to flatten one value and get EOF, got: 2")},
				},
			},
		}
		for _, tt := range tests {
			t.Run("", func(t *testing.T) {
				f := newFlattener(strings.NewReader(tt.input))
				tt.run(t, f)
			})
		}
	})
	t.Run("many values", func(t *testing.T) {
		tests := []flattenerTest{
			{
				input: `1 [ 2 ]`,
				output: []pair{
					{path: ".", value: "1"},
					{path: ".", value: "[]"},
					{path: ".[0]", value: "2"},
				},
			},
			{
				input: `"string" 42 true`,
				output: []pair{
					{path: ".", value: `"string"`},
					{path: ".", value: "42"},
					{path: ".", value: "true"},
				},
			},
			{
				input: `{ "name": "richard", "age": 58 } { "name": "carl", "age": 45 }`,
				output: []pair{
					{path: ".", value: "{}"},
					{path: `."name"`, value: `"richard"`},
					{path: `."age"`, value: "58"},
					{path: ".", value: "{}"},
					{path: `."name"`, value: `"carl"`},
					{path: `."age"`, value: "45"},
				},
			},
		}
		for _, tt := range tests {
			t.Run("", func(t *testing.T) {
				tt.run(t, newFlattener(strings.NewReader(tt.input), acceptMany))
			})
		}
	})
}
func TestFlattenerRegressions ( t * testing . T ) { t . Run ( " " , func ( t * testing . T ) { tests := [ ] flattenerTest { { input : " " , output : [ ] pair { { path : " " , value : " " } , } , } , { input : " " , output : [ ] pair { { path : " " , value : " " } , } , } , { input : " " , output : [ ] pair { { path : " " , value : " " } , } , } , { input : `"quoted"` , output : [ ] pair { { path : " " , value : `"quoted"` } , } , } , { input : `{ "user": "bob", "friends": [ "alice" ] }` , output : [ ] pair { { path : " " , value : " " } , { path : `."user"` , value : `"bob"` } , { path : `."friends"` , value : " " } , { path : `."friends"[0]` , value : `"alice"` } , } , } , { input : `1 2` , output : [ ] pair { { path : " " , value : " " } , { err : errors . New ( " " ) } , } , } , } for _ , tt := range tests { t . Run ( " " , func ( t * testing . T ) { f := newFlattener ( strings . NewReader ( tt . input ) ) tt . run ( t , f ) } ) } } ) t . Run ( " " , func ( t * testing . T ) { tests := [ ] flattenerTest { { input : `1 [ 2 ]` , output : [ ] pair { { path : " " , value : " " } , { path : " " , value : " " } , { path : " " , value : " " } , } , } , { input : `"string" 42 true` , output : [ ] pair { { path : " " , value : `"string"` } , { path : " " , value : " " } , { path : " " , value : " " } , } , } , { input : `{ "name": "richard", "age": 58 } { "name": "carl", "age": 45 }` , output : [ ] pair { { path : " " , value : " " } , { path : `."name"` , value : `"richard"` } , { path : `."age"` , value : " " } , { path : " " , value : " " } , { path : `."name"` , value : `"carl"` } , { path : `."age"` , value : " " } , } , } , } for _ , tt := range tests { t . Run ( " " , func ( t * testing . T ) { tt . run ( t , newFlattener ( strings . NewReader ( tt . input ) , acceptMany ) ) } ) } } ) }
The main testing is via conformance checking in this file.
The main testing is via conformance checking in this file .