diff --git a/arshal.go b/arshal.go index 897b149..6078daf 100644 --- a/arshal.go +++ b/arshal.go @@ -230,7 +230,7 @@ func MarshalEncode(out *jsontext.Encoder, in any, opts ...Options) (err error) { func marshalEncode(out *jsontext.Encoder, in any, mo *jsonopts.Struct) (err error) { v := reflect.ValueOf(in) if !v.IsValid() || (v.Kind() == reflect.Pointer && v.IsNil()) { - return out.WriteToken(jsontext.Null) + return out.WriteToken(jsontext.Null()) } // Shallow copy non-pointer values to obtain an addressable value. // It is beneficial to performance to always pass pointers to avoid this. diff --git a/arshal_any.go b/arshal_any.go index 5ff4bf9..fe18a14 100644 --- a/arshal_any.go +++ b/arshal_any.go @@ -27,7 +27,7 @@ import ( func marshalValueAny(enc *jsontext.Encoder, val any, mo *jsonopts.Struct) error { switch val := val.(type) { case nil: - return enc.WriteToken(jsontext.Null) + return enc.WriteToken(jsontext.Null()) case bool: return enc.WriteToken(jsontext.Bool(val)) case string: @@ -110,7 +110,7 @@ func marshalObjectAny(enc *jsontext.Encoder, obj map[string]any, mo *jsonopts.St // Handle empty maps. if len(obj) == 0 { if mo.Flags.Get(jsonflags.FormatNilMapAsNull) && obj == nil { - return enc.WriteToken(jsontext.Null) + return enc.WriteToken(jsontext.Null()) } // Optimize for marshaling an empty map without any preceding whitespace. if !mo.Flags.Get(jsonflags.AnyWhitespace) && !xe.Tokens.Last.NeedObjectName() { @@ -123,7 +123,7 @@ func marshalObjectAny(enc *jsontext.Encoder, obj map[string]any, mo *jsonopts.St } } - if err := enc.WriteToken(jsontext.ObjectStart); err != nil { + if err := enc.WriteToken(jsontext.ObjectStart()); err != nil { return err } // A Go map guarantees that each entry has a unique key @@ -158,7 +158,7 @@ func marshalObjectAny(enc *jsontext.Encoder, obj map[string]any, mo *jsonopts.St } putStrings(names) } - if err := enc.WriteToken(jsontext.ObjectEnd); err != nil { + if err := enc.WriteToken(jsontext.ObjectEnd()); err != nil { return err } return nil @@ -226,7 +226,7 @@ func marshalArrayAny(enc *jsontext.Encoder, arr []any, mo *jsonopts.Struct) erro // Handle empty slices. if len(arr) == 0 { if mo.Flags.Get(jsonflags.FormatNilSliceAsNull) && arr == nil { - return enc.WriteToken(jsontext.Null) + return enc.WriteToken(jsontext.Null()) } // Optimize for marshaling an empty slice without any preceding whitespace. if !mo.Flags.Get(jsonflags.AnyWhitespace) && !xe.Tokens.Last.NeedObjectName() { @@ -239,7 +239,7 @@ func marshalArrayAny(enc *jsontext.Encoder, arr []any, mo *jsonopts.Struct) erro } } - if err := enc.WriteToken(jsontext.ArrayStart); err != nil { + if err := enc.WriteToken(jsontext.ArrayStart()); err != nil { return err } for _, val := range arr { @@ -247,7 +247,7 @@ func marshalArrayAny(enc *jsontext.Encoder, arr []any, mo *jsonopts.Struct) erro return err } } - if err := enc.WriteToken(jsontext.ArrayEnd); err != nil { + if err := enc.WriteToken(jsontext.ArrayEnd()); err != nil { return err } return nil diff --git a/arshal_default.go b/arshal_default.go index a6777ff..9b1d068 100644 --- a/arshal_default.go +++ b/arshal_default.go @@ -331,7 +331,7 @@ func makeBytesArshaler(t reflect.Type, fncs *arshaler) *arshaler { } if mo.Flags.Get(jsonflags.FormatNilSliceAsNull) && va.Kind() == reflect.Slice && va.IsNil() { // TODO: Provide a "emitempty" format override? - return enc.WriteToken(jsontext.Null) + return enc.WriteToken(jsontext.Null()) } return xe.AppendRaw('"', true, func(b []byte) ([]byte, error) { return appendEncode(b, va.Bytes()), nil @@ -739,7 +739,7 @@ func makeMapArshaler(t reflect.Type) *arshaler { n := va.Len() if n == 0 { if emitNull && va.IsNil() { - return enc.WriteToken(jsontext.Null) + return enc.WriteToken(jsontext.Null()) } // Optimize for marshaling an empty map without any preceding whitespace. if optimizeCommon && !mo.Flags.Get(jsonflags.AnyWhitespace) && !xe.Tokens.Last.NeedObjectName() { @@ -753,7 +753,7 @@ func makeMapArshaler(t reflect.Type) *arshaler { } once.Do(init) - if err := enc.WriteToken(jsontext.ObjectStart); err != nil { + if err := enc.WriteToken(jsontext.ObjectStart()); err != nil { return err } if n > 0 { @@ -864,7 +864,7 @@ func makeMapArshaler(t reflect.Type) *arshaler { } } } - if err := enc.WriteToken(jsontext.ObjectEnd); err != nil { + if err := enc.WriteToken(jsontext.ObjectEnd()); err != nil { return err } return nil @@ -1037,7 +1037,7 @@ func makeStructArshaler(t reflect.Type) *arshaler { if errInit != nil && !mo.Flags.Get(jsonflags.ReportErrorsWithLegacySemantics) { return newMarshalErrorBefore(enc, errInit.GoType, errInit.Err) } - if err := enc.WriteToken(jsontext.ObjectStart); err != nil { + if err := enc.WriteToken(jsontext.ObjectStart()); err != nil { return err } var seenIdxs uintSet @@ -1185,7 +1185,7 @@ func makeStructArshaler(t reflect.Type) *arshaler { return err } } - if err := enc.WriteToken(jsontext.ObjectEnd); err != nil { + if err := enc.WriteToken(jsontext.ObjectEnd()); err != nil { return err } return nil @@ -1416,7 +1416,7 @@ func makeSliceArshaler(t reflect.Type) *arshaler { n := va.Len() if n == 0 { if emitNull && va.IsNil() { - return enc.WriteToken(jsontext.Null) + return enc.WriteToken(jsontext.Null()) } // Optimize for marshaling an empty slice without any preceding whitespace. if optimizeCommon && !mo.Flags.Get(jsonflags.AnyWhitespace) && !xe.Tokens.Last.NeedObjectName() { @@ -1430,7 +1430,7 @@ func makeSliceArshaler(t reflect.Type) *arshaler { } once.Do(init) - if err := enc.WriteToken(jsontext.ArrayStart); err != nil { + if err := enc.WriteToken(jsontext.ArrayStart()); err != nil { return err } marshal := valFncs.marshal @@ -1443,7 +1443,7 @@ func makeSliceArshaler(t reflect.Type) *arshaler { return err } } - if err := enc.WriteToken(jsontext.ArrayEnd); err != nil { + if err := enc.WriteToken(jsontext.ArrayEnd()); err != nil { return err } return nil @@ -1536,7 +1536,7 @@ func makeArrayArshaler(t reflect.Type) *arshaler { return newInvalidFormatError(enc, t, mo) } once.Do(init) - if err := enc.WriteToken(jsontext.ArrayStart); err != nil { + if err := enc.WriteToken(jsontext.ArrayStart()); err != nil { return err } marshal := valFncs.marshal @@ -1549,7 +1549,7 @@ func makeArrayArshaler(t reflect.Type) *arshaler { return err } } - if err := enc.WriteToken(jsontext.ArrayEnd); err != nil { + if err := enc.WriteToken(jsontext.ArrayEnd()); err != nil { return err } return nil @@ -1636,7 +1636,7 @@ func makePointerArshaler(t reflect.Type) *arshaler { // NOTE: Struct.Format is forwarded to underlying marshal. if va.IsNil() { - return enc.WriteToken(jsontext.Null) + return enc.WriteToken(jsontext.Null()) } once.Do(init) marshal := valFncs.marshal @@ -1705,7 +1705,7 @@ func makeInterfaceArshaler(t reflect.Type) *arshaler { return newInvalidFormatError(enc, t, mo) } if va.IsNil() { - return enc.WriteToken(jsontext.Null) + return enc.WriteToken(jsontext.Null()) } else if mo.Flags.Get(jsonflags.CallMethodsWithLegacySemantics) && whichMarshaler != nil { // The marshaler for a pointer never calls the method on a nil receiver. // Wrap the nil pointer within a struct type so that marshal diff --git a/arshal_test.go b/arshal_test.go index 8379e22..8c28e90 100644 --- a/arshal_test.go +++ b/arshal_test.go @@ -3411,8 +3411,8 @@ func TestMarshal(t *testing.T) { }, { name: jsontest.Name("Methods/Invalid/JSONv2/TooMany"), in: marshalJSONv2Func(func(enc *jsontext.Encoder, opts Options) error { - enc.WriteToken(jsontext.Null) - enc.WriteToken(jsontext.Null) + enc.WriteToken(jsontext.Null()) + enc.WriteToken(jsontext.Null()) return nil }), want: `nullnull`, @@ -3491,7 +3491,7 @@ func TestMarshal(t *testing.T) { name: jsontest.Name("Methods/Invalid/MapKey/JSONv2/Syntax"), in: map[any]string{ addr(marshalJSONv2Func(func(enc *jsontext.Encoder, opts Options) error { - return enc.WriteToken(jsontext.Null) + return enc.WriteToken(jsontext.Null()) })): "invalid", }, want: `{`, @@ -3777,7 +3777,7 @@ func TestMarshal(t *testing.T) { name: jsontest.Name("Functions/Map/Key/NoCaseString/V2/InvalidToken"), opts: []Options{ WithMarshalers(MarshalToFunc(func(enc *jsontext.Encoder, v nocaseString, opts Options) error { - return enc.WriteToken(jsontext.Null) + return enc.WriteToken(jsontext.Null()) })), }, in: map[nocaseString]string{"hello": "world"}, @@ -9100,7 +9100,7 @@ func TestMarshalInvalidNamespace(t *testing.T) { t.Fatalf("%s: MarshalEncode error is nil, want non-nil", tt.name.Where) } for _, tok := range []jsontext.Token{ - jsontext.Null, jsontext.String(""), jsontext.Int(0), jsontext.ObjectStart, jsontext.ObjectEnd, jsontext.ArrayStart, jsontext.ArrayEnd, + jsontext.Null(), jsontext.String(""), jsontext.Int(0), jsontext.ObjectStart(), jsontext.ObjectEnd(), jsontext.ArrayStart(), jsontext.ArrayEnd(), } { if err := enc.WriteToken(tok); err == nil { t.Fatalf("%s: WriteToken error is nil, want non-nil", tt.name.Where) diff --git a/example_orderedobject_test.go b/example_orderedobject_test.go index 38812c0..7d164de 100644 --- a/example_orderedobject_test.go +++ b/example_orderedobject_test.go @@ -30,7 +30,7 @@ type ObjectMember[V any] struct { // MarshalJSONTo encodes obj as a JSON object into enc. func (obj *OrderedObject[V]) MarshalJSONTo(enc *jsontext.Encoder, opts json.Options) error { - if err := enc.WriteToken(jsontext.ObjectStart); err != nil { + if err := enc.WriteToken(jsontext.ObjectStart()); err != nil { return err } for i := range *obj { @@ -42,7 +42,7 @@ func (obj *OrderedObject[V]) MarshalJSONTo(enc *jsontext.Encoder, opts json.Opti return err } } - if err := enc.WriteToken(jsontext.ObjectEnd); err != nil { + if err := enc.WriteToken(jsontext.ObjectEnd()); err != nil { return err } return nil diff --git a/jsontext/coder_test.go b/jsontext/coder_test.go index 8c34721..74ad9f8 100644 --- a/jsontext/coder_test.go +++ b/jsontext/coder_test.go @@ -64,18 +64,18 @@ var coderTestdata = []coderTestdataEntry{{ name: jsontest.Name("Null"), in: ` null `, outCompacted: `null`, - tokens: []Token{Null}, + tokens: []Token{Null()}, pointers: []Pointer{""}, }, { name: jsontest.Name("False"), in: ` false `, outCompacted: `false`, - tokens: []Token{False}, + tokens: []Token{Bool(false)}, }, { name: jsontest.Name("True"), in: ` true `, outCompacted: `true`, - tokens: []Token{True}, + tokens: []Token{Bool(true)}, }, { name: jsontest.Name("EmptyString"), in: ` "" `, @@ -169,12 +169,12 @@ var coderTestdata = []coderTestdataEntry{{ ]`, outCanonicalized: `[0,0,0,0,1,1.7976931348623157e+308,-5e-324,1e+100,1.7976931348623157e+308,9007199254740990,9007199254740991,9007199254740992,9007199254740992,9007199254740994,-9223372036854776000,9223372036854776000,0,18446744073709552000]`, tokens: []Token{ - ArrayStart, + ArrayStart(), Float(0), Float(math.Copysign(0, -1)), rawToken(`0.0`), rawToken(`-0.0`), rawToken(`1.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001`), rawToken(`1e1000`), Float(-5e-324), Float(1e100), Float(1.7976931348623157e+308), Float(9007199254740990), Float(9007199254740991), Float(9007199254740992), rawToken(`9007199254740993`), rawToken(`9007199254740994`), Int(minInt64), Int(maxInt64), Uint(minUint64), Uint(maxUint64), - ArrayEnd, + ArrayEnd(), }, pointers: []Pointer{ "", "/0", "/1", "/2", "/3", "/4", "/5", "/6", "/7", "/8", "/9", "/10", "/11", "/12", "/13", "/14", "/15", "/16", "/17", "", @@ -183,7 +183,7 @@ var coderTestdata = []coderTestdataEntry{{ name: jsontest.Name("ObjectN0"), in: ` { } `, outCompacted: `{}`, - tokens: []Token{ObjectStart, ObjectEnd}, + tokens: []Token{ObjectStart(), ObjectEnd()}, pointers: []Pointer{"", ""}, }, { name: jsontest.Name("ObjectN1"), @@ -193,7 +193,7 @@ var coderTestdata = []coderTestdataEntry{{ outIndented: `{ "0": 0 }`, - tokens: []Token{ObjectStart, String("0"), Uint(0), ObjectEnd}, + tokens: []Token{ObjectStart(), String("0"), Uint(0), ObjectEnd()}, pointers: []Pointer{"", "/0", "/0", ""}, }, { name: jsontest.Name("ObjectN2"), @@ -204,7 +204,7 @@ var coderTestdata = []coderTestdataEntry{{ "0": 0, "1": 1 }`, - tokens: []Token{ObjectStart, String("0"), Uint(0), String("1"), Uint(1), ObjectEnd}, + tokens: []Token{ObjectStart(), String("0"), Uint(0), String("1"), Uint(1), ObjectEnd()}, pointers: []Pointer{"", "/0", "/0", "/1", "/1", ""}, }, { name: jsontest.Name("ObjectNested"), @@ -222,7 +222,7 @@ var coderTestdata = []coderTestdataEntry{{ } } }`, - tokens: []Token{ObjectStart, String("0"), ObjectStart, String("1"), ObjectStart, String("2"), ObjectStart, String("3"), ObjectStart, String("4"), ObjectStart, ObjectEnd, ObjectEnd, ObjectEnd, ObjectEnd, ObjectEnd, ObjectEnd}, + tokens: []Token{ObjectStart(), String("0"), ObjectStart(), String("1"), ObjectStart(), String("2"), ObjectStart(), String("3"), ObjectStart(), String("4"), ObjectStart(), ObjectEnd(), ObjectEnd(), ObjectEnd(), ObjectEnd(), ObjectEnd(), ObjectEnd()}, pointers: []Pointer{ "", "/0", "/0", @@ -269,23 +269,23 @@ var coderTestdata = []coderTestdataEntry{{ }`, outCanonicalized: `{"":{"0":{"11":"","222":"aaaaa","3333":"bbb"},"44444":{"555555":"aaaa","6666666":"ccccccc","77777777":"bb"}}}`, tokens: []Token{ - ObjectStart, + ObjectStart(), String(""), - ObjectStart, + ObjectStart(), String("44444"), - ObjectStart, + ObjectStart(), String("6666666"), String("ccccccc"), String("77777777"), String("bb"), String("555555"), String("aaaa"), - ObjectEnd, + ObjectEnd(), String("0"), - ObjectStart, + ObjectStart(), String("3333"), String("bbb"), String("11"), String(""), String("222"), String("aaaaa"), - ObjectEnd, - ObjectEnd, - ObjectEnd, + ObjectEnd(), + ObjectEnd(), + ObjectEnd(), }, pointers: []Pointer{ "", @@ -307,7 +307,7 @@ var coderTestdata = []coderTestdataEntry{{ name: jsontest.Name("ArrayN0"), in: ` [ ] `, outCompacted: `[]`, - tokens: []Token{ArrayStart, ArrayEnd}, + tokens: []Token{ArrayStart(), ArrayEnd()}, pointers: []Pointer{"", ""}, }, { name: jsontest.Name("ArrayN1"), @@ -316,7 +316,7 @@ var coderTestdata = []coderTestdataEntry{{ outIndented: `[ 0 ]`, - tokens: []Token{ArrayStart, Uint(0), ArrayEnd}, + tokens: []Token{ArrayStart(), Uint(0), ArrayEnd()}, pointers: []Pointer{"", "/0", ""}, }, { name: jsontest.Name("ArrayN2"), @@ -326,7 +326,7 @@ var coderTestdata = []coderTestdataEntry{{ 0, 1 ]`, - tokens: []Token{ArrayStart, Uint(0), Uint(1), ArrayEnd}, + tokens: []Token{ArrayStart(), Uint(0), Uint(1), ArrayEnd()}, }, { name: jsontest.Name("ArrayNested"), in: ` [ [ [ [ [ ] ] ] ] ] `, @@ -340,7 +340,7 @@ var coderTestdata = []coderTestdataEntry{{ ] ] ]`, - tokens: []Token{ArrayStart, ArrayStart, ArrayStart, ArrayStart, ArrayStart, ArrayEnd, ArrayEnd, ArrayEnd, ArrayEnd, ArrayEnd}, + tokens: []Token{ArrayStart(), ArrayStart(), ArrayStart(), ArrayStart(), ArrayStart(), ArrayEnd(), ArrayEnd(), ArrayEnd(), ArrayEnd(), ArrayEnd()}, pointers: []Pointer{ "", "/0", @@ -395,17 +395,17 @@ var coderTestdata = []coderTestdataEntry{{ }`, outCanonicalized: `{"arrayN0":[],"arrayN1":[0],"arrayN2":[0,1],"literals":[null,false,true],"number":3.14159,"objectN0":{},"objectN1":{"0":0},"objectN2":{"0":0,"1":1},"string":"Hello, 世界"}`, tokens: []Token{ - ObjectStart, - String("literals"), ArrayStart, Null, False, True, ArrayEnd, + ObjectStart(), + String("literals"), ArrayStart(), Null(), Bool(false), Bool(true), ArrayEnd(), String("string"), String("Hello, 世界"), String("number"), Float(3.14159), - String("arrayN0"), ArrayStart, ArrayEnd, - String("arrayN1"), ArrayStart, Uint(0), ArrayEnd, - String("arrayN2"), ArrayStart, Uint(0), Uint(1), ArrayEnd, - String("objectN0"), ObjectStart, ObjectEnd, - String("objectN1"), ObjectStart, String("0"), Uint(0), ObjectEnd, - String("objectN2"), ObjectStart, String("0"), Uint(0), String("1"), Uint(1), ObjectEnd, - ObjectEnd, + String("arrayN0"), ArrayStart(), ArrayEnd(), + String("arrayN1"), ArrayStart(), Uint(0), ArrayEnd(), + String("arrayN2"), ArrayStart(), Uint(0), Uint(1), ArrayEnd(), + String("objectN0"), ObjectStart(), ObjectEnd(), + String("objectN1"), ObjectStart(), String("0"), Uint(0), ObjectEnd(), + String("objectN2"), ObjectStart(), String("0"), Uint(0), String("1"), Uint(1), ObjectEnd(), + ObjectEnd(), }, pointers: []Pointer{ "", @@ -515,54 +515,54 @@ func TestCoderStackPointer(t *testing.T) { token Token want Pointer }{ - {Null, ""}, + {Null(), ""}, - {ArrayStart, ""}, - {ArrayEnd, ""}, + {ArrayStart(), ""}, + {ArrayEnd(), ""}, - {ArrayStart, ""}, + {ArrayStart(), ""}, {Bool(true), "/0"}, - {ArrayEnd, ""}, + {ArrayEnd(), ""}, - {ArrayStart, ""}, + {ArrayStart(), ""}, {String("hello"), "/0"}, {String("goodbye"), "/1"}, - {ArrayEnd, ""}, + {ArrayEnd(), ""}, - {ObjectStart, ""}, - {ObjectEnd, ""}, + {ObjectStart(), ""}, + {ObjectEnd(), ""}, - {ObjectStart, ""}, + {ObjectStart(), ""}, {String("hello"), "/hello"}, {String("goodbye"), "/hello"}, - {ObjectEnd, ""}, + {ObjectEnd(), ""}, - {ObjectStart, ""}, + {ObjectStart(), ""}, {String(""), "/"}, - {Null, "/"}, + {Null(), "/"}, {String("0"), "/0"}, - {Null, "/0"}, + {Null(), "/0"}, {String("~"), "/~0"}, - {Null, "/~0"}, + {Null(), "/~0"}, {String("/"), "/~1"}, - {Null, "/~1"}, + {Null(), "/~1"}, {String("a//b~/c/~d~~e"), "/a~1~1b~0~1c~1~0d~0~0e"}, - {Null, "/a~1~1b~0~1c~1~0d~0~0e"}, + {Null(), "/a~1~1b~0~1c~1~0d~0~0e"}, {String(" \r\n\t"), "/ \r\n\t"}, - {Null, "/ \r\n\t"}, - {ObjectEnd, ""}, + {Null(), "/ \r\n\t"}, + {ObjectEnd(), ""}, - {ArrayStart, ""}, - {ObjectStart, "/0"}, + {ArrayStart(), ""}, + {ObjectStart(), "/0"}, {String(""), "/0/"}, - {ArrayStart, "/0/"}, - {ObjectStart, "/0//0"}, + {ArrayStart(), "/0/"}, + {ObjectStart(), "/0//0"}, {String("#"), "/0//0/#"}, - {Null, "/0//0/#"}, - {ObjectEnd, "/0//0"}, - {ArrayEnd, "/0/"}, - {ObjectEnd, "/0"}, - {ArrayEnd, ""}, + {Null(), "/0//0/#"}, + {ObjectEnd(), "/0//0"}, + {ArrayEnd(), "/0/"}, + {ObjectEnd(), "/0"}, + {ArrayEnd(), ""}, } for _, allowDupes := range []bool{false, true} { @@ -738,19 +738,19 @@ func TestCoderMaxDepth(t *testing.T) { }) t.Run("Arrays/TokenThenValue", func(t *testing.T) { enc.s.reset(enc.s.Buf[:0], nil) - checkWriteToken(t, ArrayStart, nil) + checkWriteToken(t, ArrayStart(), nil) checkWriteValue(t, trimArray(maxArrays), wantErr) checkWriteValue(t, trimArray(trimArray(maxArrays)), nil) - checkWriteToken(t, ArrayEnd, nil) + checkWriteToken(t, ArrayEnd(), nil) }) t.Run("Arrays/AllTokens", func(t *testing.T) { enc.s.reset(enc.s.Buf[:0], nil) for range maxNestingDepth { - checkWriteToken(t, ArrayStart, nil) + checkWriteToken(t, ArrayStart(), nil) } - checkWriteToken(t, ArrayStart, wantErr) + checkWriteToken(t, ArrayStart(), wantErr) for range maxNestingDepth { - checkWriteToken(t, ArrayEnd, nil) + checkWriteToken(t, ArrayEnd(), nil) } }) @@ -766,24 +766,24 @@ func TestCoderMaxDepth(t *testing.T) { }) t.Run("Objects/TokenThenValue", func(t *testing.T) { enc.s.reset(enc.s.Buf[:0], nil) - checkWriteToken(t, ObjectStart, nil) + checkWriteToken(t, ObjectStart(), nil) checkWriteToken(t, String(""), nil) checkWriteValue(t, trimObject(maxObjects), wantErr) checkWriteValue(t, trimObject(trimObject(maxObjects)), nil) - checkWriteToken(t, ObjectEnd, nil) + checkWriteToken(t, ObjectEnd(), nil) }) t.Run("Objects/AllTokens", func(t *testing.T) { enc.s.reset(enc.s.Buf[:0], nil) for range maxNestingDepth - 1 { - checkWriteToken(t, ObjectStart, nil) + checkWriteToken(t, ObjectStart(), nil) checkWriteToken(t, String(""), nil) } - checkWriteToken(t, ObjectStart, nil) + checkWriteToken(t, ObjectStart(), nil) checkWriteToken(t, String(""), nil) - checkWriteToken(t, ObjectStart, wantErr) + checkWriteToken(t, ObjectStart(), wantErr) checkWriteToken(t, String(""), nil) for range maxNestingDepth { - checkWriteToken(t, ObjectEnd, nil) + checkWriteToken(t, ObjectEnd(), nil) } }) }) diff --git a/jsontext/decode.go b/jsontext/decode.go index 6f14095..fa3da83 100644 --- a/jsontext/decode.go +++ b/jsontext/decode.go @@ -507,7 +507,7 @@ func (d *decoderState) ReadToken() (Token, error) { return Token{}, wrapSyntacticError(d, err, pos-len("null"), +1) // report position at start of literal } d.prevStart, d.prevEnd = pos, pos - return Null, nil + return Null(), nil case 'f': if jsonwire.ConsumeFalse(d.buf[pos:]) == 0 { @@ -522,7 +522,7 @@ func (d *decoderState) ReadToken() (Token, error) { return Token{}, wrapSyntacticError(d, err, pos-len("false"), +1) // report position at start of literal } d.prevStart, d.prevEnd = pos, pos - return False, nil + return Bool(false), nil case 't': if jsonwire.ConsumeTrue(d.buf[pos:]) == 0 { @@ -537,7 +537,7 @@ func (d *decoderState) ReadToken() (Token, error) { return Token{}, wrapSyntacticError(d, err, pos-len("true"), +1) // report position at start of literal } d.prevStart, d.prevEnd = pos, pos - return True, nil + return Bool(true), nil case '"': var flags jsonwire.ValueFlags // TODO: Preserve this in Token? @@ -600,7 +600,7 @@ func (d *decoderState) ReadToken() (Token, error) { } pos += 1 d.prevStart, d.prevEnd = pos, pos - return ObjectStart, nil + return ObjectStart(), nil case '}': if err = d.Tokens.popObject(); err != nil { @@ -612,7 +612,7 @@ func (d *decoderState) ReadToken() (Token, error) { } pos += 1 d.prevStart, d.prevEnd = pos, pos - return ObjectEnd, nil + return ObjectEnd(), nil case '[': if err = d.Tokens.pushArray(); err != nil { @@ -620,7 +620,7 @@ func (d *decoderState) ReadToken() (Token, error) { } pos += 1 d.prevStart, d.prevEnd = pos, pos - return ArrayStart, nil + return ArrayStart(), nil case ']': if err = d.Tokens.popArray(); err != nil { @@ -628,7 +628,7 @@ func (d *decoderState) ReadToken() (Token, error) { } pos += 1 d.prevStart, d.prevEnd = pos, pos - return ArrayEnd, nil + return ArrayEnd(), nil default: err = jsonwire.NewInvalidCharacterError(d.buf[pos:], "at start of value") diff --git a/jsontext/decode_test.go b/jsontext/decode_test.go index 80f235d..6882d65 100644 --- a/jsontext/decode_test.go +++ b/jsontext/decode_test.go @@ -205,7 +205,7 @@ var decoderErrorTestdata = []struct { name: jsontest.Name("StreamN1"), in: ` null `, calls: []decoderMethodCall{ - {'n', Null, nil, ""}, + {'n', Null(), nil, ""}, {0, zeroToken, io.EOF, ""}, {0, zeroValue, io.EOF, ""}, }, @@ -214,8 +214,8 @@ var decoderErrorTestdata = []struct { name: jsontest.Name("StreamN2"), in: ` nullnull `, calls: []decoderMethodCall{ - {'n', Null, nil, ""}, - {'n', Null, nil, ""}, + {'n', Null(), nil, ""}, + {'n', Null(), nil, ""}, {0, zeroToken, io.EOF, ""}, {0, zeroValue, io.EOF, ""}, }, @@ -224,7 +224,7 @@ var decoderErrorTestdata = []struct { name: jsontest.Name("StreamN2/ExtraComma"), // stream is whitespace delimited, not comma delimited in: ` null , null `, calls: []decoderMethodCall{ - {'n', Null, nil, ""}, + {'n', Null(), nil, ""}, {0, zeroToken, newInvalidCharacterError(",", `at start of value`).withPos(` null `, ""), ""}, {0, zeroValue, newInvalidCharacterError(",", `at start of value`).withPos(` null `, ""), ""}, }, @@ -328,7 +328,7 @@ var decoderErrorTestdata = []struct { in: `{`, calls: []decoderMethodCall{ {'{', zeroValue, E(io.ErrUnexpectedEOF).withPos("{", ""), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {0, zeroToken, E(io.ErrUnexpectedEOF).withPos("{", ""), ""}, {0, zeroValue, E(io.ErrUnexpectedEOF).withPos("{", ""), ""}, }, @@ -338,7 +338,7 @@ var decoderErrorTestdata = []struct { in: `{"0"`, calls: []decoderMethodCall{ {'{', zeroValue, E(io.ErrUnexpectedEOF).withPos(`{"0"`, "/0"), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("0"), nil, ""}, {0, zeroToken, E(io.ErrUnexpectedEOF).withPos(`{"0"`, "/0"), ""}, {0, zeroValue, E(io.ErrUnexpectedEOF).withPos(`{"0"`, "/0"), ""}, @@ -349,7 +349,7 @@ var decoderErrorTestdata = []struct { in: `{"0":`, calls: []decoderMethodCall{ {'{', zeroValue, E(io.ErrUnexpectedEOF).withPos(`{"0":`, "/0"), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("0"), nil, ""}, {0, zeroToken, E(io.ErrUnexpectedEOF).withPos(`{"0":`, "/0"), ""}, {0, zeroValue, E(io.ErrUnexpectedEOF).withPos(`{"0":`, "/0"), ""}, @@ -360,7 +360,7 @@ var decoderErrorTestdata = []struct { in: `{"0":0`, calls: []decoderMethodCall{ {'{', zeroValue, E(io.ErrUnexpectedEOF).withPos(`{"0":0`, ""), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("0"), nil, ""}, {'0', Uint(0), nil, ""}, {0, zeroToken, E(io.ErrUnexpectedEOF).withPos(`{"0":0`, ""), ""}, @@ -372,7 +372,7 @@ var decoderErrorTestdata = []struct { in: `{"0":0,`, calls: []decoderMethodCall{ {'{', zeroValue, E(io.ErrUnexpectedEOF).withPos(`{"0":0,`, ""), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("0"), nil, ""}, {'0', Uint(0), nil, ""}, {0, zeroToken, E(io.ErrUnexpectedEOF).withPos(`{"0":0,`, ""), ""}, @@ -384,7 +384,7 @@ var decoderErrorTestdata = []struct { in: ` { "fizz" "buzz" } `, calls: []decoderMethodCall{ {'{', zeroValue, newInvalidCharacterError("\"", "after object name (expecting ':')").withPos(` { "fizz" `, "/fizz"), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("fizz"), nil, ""}, {0, zeroToken, newInvalidCharacterError("\"", "after object name (expecting ':')").withPos(` { "fizz" `, "/fizz"), ""}, {0, zeroValue, newInvalidCharacterError("\"", "after object name (expecting ':')").withPos(` { "fizz" `, "/fizz"), ""}, @@ -395,7 +395,7 @@ var decoderErrorTestdata = []struct { in: ` { "fizz" , "buzz" } `, calls: []decoderMethodCall{ {'{', zeroValue, newInvalidCharacterError(",", "after object name (expecting ':')").withPos(` { "fizz" `, "/fizz"), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("fizz"), nil, ""}, {0, zeroToken, newInvalidCharacterError(",", "after object name (expecting ':')").withPos(` { "fizz" `, "/fizz"), ""}, {0, zeroValue, newInvalidCharacterError(",", "after object name (expecting ':')").withPos(` { "fizz" `, "/fizz"), ""}, @@ -406,7 +406,7 @@ var decoderErrorTestdata = []struct { in: ` { "fizz" # "buzz" } `, calls: []decoderMethodCall{ {'{', zeroValue, newInvalidCharacterError("#", "after object name (expecting ':')").withPos(` { "fizz" `, "/fizz"), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("fizz"), nil, ""}, {0, zeroToken, newInvalidCharacterError("#", "after object name (expecting ':')").withPos(` { "fizz" `, "/fizz"), ""}, {0, zeroValue, newInvalidCharacterError("#", "after object name (expecting ':')").withPos(` { "fizz" `, "/fizz"), ""}, @@ -417,7 +417,7 @@ var decoderErrorTestdata = []struct { in: ` { "fizz" : "buzz" "gazz" } `, calls: []decoderMethodCall{ {'{', zeroValue, newInvalidCharacterError("\"", "after object value (expecting ',' or '}')").withPos(` { "fizz" : "buzz" `, ""), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("fizz"), nil, ""}, {'"', String("buzz"), nil, ""}, {0, zeroToken, newInvalidCharacterError("\"", "after object value (expecting ',' or '}')").withPos(` { "fizz" : "buzz" `, ""), ""}, @@ -429,7 +429,7 @@ var decoderErrorTestdata = []struct { in: ` { "fizz" : "buzz" : "gazz" } `, calls: []decoderMethodCall{ {'{', zeroValue, newInvalidCharacterError(":", "after object value (expecting ',' or '}')").withPos(` { "fizz" : "buzz" `, ""), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("fizz"), nil, ""}, {'"', String("buzz"), nil, ""}, {0, zeroToken, newInvalidCharacterError(":", "after object value (expecting ',' or '}')").withPos(` { "fizz" : "buzz" `, ""), ""}, @@ -441,7 +441,7 @@ var decoderErrorTestdata = []struct { in: ` { "fizz" : "buzz" # "gazz" } `, calls: []decoderMethodCall{ {'{', zeroValue, newInvalidCharacterError("#", "after object value (expecting ',' or '}')").withPos(` { "fizz" : "buzz" `, ""), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("fizz"), nil, ""}, {'"', String("buzz"), nil, ""}, {0, zeroToken, newInvalidCharacterError("#", "after object value (expecting ',' or '}')").withPos(` { "fizz" : "buzz" `, ""), ""}, @@ -453,7 +453,7 @@ var decoderErrorTestdata = []struct { in: ` { , } `, calls: []decoderMethodCall{ {'{', zeroValue, newInvalidCharacterError(",", `at start of string (expecting '"')`).withPos(` { `, ""), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {0, zeroToken, newInvalidCharacterError(",", `at start of value`).withPos(` { `, ""), ""}, {0, zeroValue, newInvalidCharacterError(",", `at start of value`).withPos(` { `, ""), ""}, }, @@ -463,7 +463,7 @@ var decoderErrorTestdata = []struct { in: ` { "fizz" : "buzz" , } `, calls: []decoderMethodCall{ {'{', zeroValue, newInvalidCharacterError("}", `at start of string (expecting '"')`).withPos(` { "fizz" : "buzz" , `, ""), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("fizz"), nil, ""}, {'"', String("buzz"), nil, ""}, {0, zeroToken, newInvalidCharacterError(",", `at start of value`).withPos(` { "fizz" : "buzz" `, ""), ""}, @@ -475,7 +475,7 @@ var decoderErrorTestdata = []struct { in: ` { null : null } `, calls: []decoderMethodCall{ {'{', zeroValue, newInvalidCharacterError("n", "at start of string (expecting '\"')").withPos(` { `, ""), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'n', zeroToken, E(ErrNonStringName).withPos(` { `, ""), ""}, {'n', zeroValue, E(ErrNonStringName).withPos(` { `, ""), ""}, }, @@ -485,7 +485,7 @@ var decoderErrorTestdata = []struct { in: ` { false : false } `, calls: []decoderMethodCall{ {'{', zeroValue, newInvalidCharacterError("f", "at start of string (expecting '\"')").withPos(` { `, ""), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'f', zeroToken, E(ErrNonStringName).withPos(` { `, ""), ""}, {'f', zeroValue, E(ErrNonStringName).withPos(` { `, ""), ""}, }, @@ -495,7 +495,7 @@ var decoderErrorTestdata = []struct { in: ` { true : true } `, calls: []decoderMethodCall{ {'{', zeroValue, newInvalidCharacterError("t", "at start of string (expecting '\"')").withPos(` { `, ""), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'t', zeroToken, E(ErrNonStringName).withPos(` { `, ""), ""}, {'t', zeroValue, E(ErrNonStringName).withPos(` { `, ""), ""}, }, @@ -505,7 +505,7 @@ var decoderErrorTestdata = []struct { in: ` { 0 : 0 } `, calls: []decoderMethodCall{ {'{', zeroValue, newInvalidCharacterError("0", "at start of string (expecting '\"')").withPos(` { `, ""), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'0', zeroToken, E(ErrNonStringName).withPos(` { `, ""), ""}, {'0', zeroValue, E(ErrNonStringName).withPos(` { `, ""), ""}, }, @@ -515,7 +515,7 @@ var decoderErrorTestdata = []struct { in: ` { {} : {} } `, calls: []decoderMethodCall{ {'{', zeroValue, newInvalidCharacterError("{", "at start of string (expecting '\"')").withPos(` { `, ""), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'{', zeroToken, E(ErrNonStringName).withPos(` { `, ""), ""}, {'{', zeroValue, E(ErrNonStringName).withPos(` { `, ""), ""}, }, @@ -525,7 +525,7 @@ var decoderErrorTestdata = []struct { in: ` { [] : [] } `, calls: []decoderMethodCall{ {'{', zeroValue, newInvalidCharacterError("[", "at start of string (expecting '\"')").withPos(` { `, ""), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'[', zeroToken, E(ErrNonStringName).withPos(` { `, ""), ""}, {'[', zeroValue, E(ErrNonStringName).withPos(` { `, ""), ""}, }, @@ -535,7 +535,7 @@ var decoderErrorTestdata = []struct { in: ` { ] `, calls: []decoderMethodCall{ {'{', zeroValue, newInvalidCharacterError("]", "at start of string (expecting '\"')").withPos(` { `, ""), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {']', zeroToken, newInvalidCharacterError("]", "at start of value").withPos(` { `, ""), ""}, {']', zeroValue, newInvalidCharacterError("]", "at start of value").withPos(` { `, ""), ""}, }, @@ -544,7 +544,7 @@ var decoderErrorTestdata = []struct { name: jsontest.Name("ValidObject/InvalidValue"), in: ` { } `, calls: []decoderMethodCall{ - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'}', zeroValue, newInvalidCharacterError("}", "at start of value").withPos(" { ", ""), ""}, }, wantOffset: len(` {`), @@ -552,12 +552,12 @@ var decoderErrorTestdata = []struct { name: jsontest.Name("ValidObject/UniqueNames"), in: `{"0":0,"1":1} `, calls: []decoderMethodCall{ - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("0"), nil, ""}, {'0', Uint(0), nil, ""}, {'"', String("1"), nil, ""}, {'0', Uint(1), nil, ""}, - {'}', ObjectEnd, nil, ""}, + {'}', ObjectEnd(), nil, ""}, }, wantOffset: len(`{"0":0,"1":1}`), }, { @@ -565,12 +565,12 @@ var decoderErrorTestdata = []struct { opts: []Options{AllowDuplicateNames(true)}, in: `{"0":0,"0":0} `, calls: []decoderMethodCall{ - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("0"), nil, ""}, {'0', Uint(0), nil, ""}, {'"', String("0"), nil, ""}, {'0', Uint(0), nil, ""}, - {'}', ObjectEnd, nil, ""}, + {'}', ObjectEnd(), nil, ""}, }, wantOffset: len(`{"0":0,"0":0}`), }, { @@ -578,13 +578,13 @@ var decoderErrorTestdata = []struct { in: `{"X":{},"Y":{},"X":{}} `, calls: []decoderMethodCall{ {'{', zeroValue, E(ErrDuplicateName).withPos(`{"X":{},"Y":{},`, "/X"), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("X"), nil, ""}, - {'{', ObjectStart, nil, ""}, - {'}', ObjectEnd, nil, ""}, + {'{', ObjectStart(), nil, ""}, + {'}', ObjectEnd(), nil, ""}, {'"', String("Y"), nil, ""}, - {'{', ObjectStart, nil, ""}, - {'}', ObjectEnd, nil, ""}, + {'{', ObjectStart(), nil, ""}, + {'}', ObjectEnd(), nil, ""}, {'"', zeroToken, E(ErrDuplicateName).withPos(`{"X":{},"Y":{},`, "/X"), "/Y"}, {'"', zeroValue, E(ErrDuplicateName).withPos(`{"0":{},"Y":{},`, "/X"), "/Y"}, }, @@ -594,7 +594,7 @@ var decoderErrorTestdata = []struct { in: `[`, calls: []decoderMethodCall{ {'[', zeroValue, E(io.ErrUnexpectedEOF).withPos("[", ""), ""}, - {'[', ArrayStart, nil, ""}, + {'[', ArrayStart(), nil, ""}, {0, zeroToken, E(io.ErrUnexpectedEOF).withPos("[", ""), ""}, {0, zeroValue, E(io.ErrUnexpectedEOF).withPos("[", ""), ""}, }, @@ -604,7 +604,7 @@ var decoderErrorTestdata = []struct { in: `[0`, calls: []decoderMethodCall{ {'[', zeroValue, E(io.ErrUnexpectedEOF).withPos("[0", ""), ""}, - {'[', ArrayStart, nil, ""}, + {'[', ArrayStart(), nil, ""}, {'0', Uint(0), nil, ""}, {0, zeroToken, E(io.ErrUnexpectedEOF).withPos("[0", ""), ""}, {0, zeroValue, E(io.ErrUnexpectedEOF).withPos("[0", ""), ""}, @@ -615,7 +615,7 @@ var decoderErrorTestdata = []struct { in: `[0,`, calls: []decoderMethodCall{ {'[', zeroValue, E(io.ErrUnexpectedEOF).withPos("[0,", ""), ""}, - {'[', ArrayStart, nil, ""}, + {'[', ArrayStart(), nil, ""}, {'0', Uint(0), nil, ""}, {0, zeroToken, E(io.ErrUnexpectedEOF).withPos("[0,", ""), ""}, {0, zeroValue, E(io.ErrUnexpectedEOF).withPos("[0,", ""), ""}, @@ -626,7 +626,7 @@ var decoderErrorTestdata = []struct { in: ` [ "fizz" "buzz" ] `, calls: []decoderMethodCall{ {'[', zeroValue, newInvalidCharacterError("\"", "after array element (expecting ',' or ']')").withPos(` [ "fizz" `, ""), ""}, - {'[', ArrayStart, nil, ""}, + {'[', ArrayStart(), nil, ""}, {'"', String("fizz"), nil, ""}, {0, zeroToken, newInvalidCharacterError("\"", "after array element (expecting ',' or ']')").withPos(` [ "fizz" `, ""), ""}, {0, zeroValue, newInvalidCharacterError("\"", "after array element (expecting ',' or ']')").withPos(` [ "fizz" `, ""), ""}, @@ -637,7 +637,7 @@ var decoderErrorTestdata = []struct { in: ` [ } `, calls: []decoderMethodCall{ {'[', zeroValue, newInvalidCharacterError("}", "at start of value").withPos(` [ `, "/0"), ""}, - {'[', ArrayStart, nil, ""}, + {'[', ArrayStart(), nil, ""}, {'}', zeroToken, newInvalidCharacterError("}", "at start of value").withPos(` [ `, "/0"), ""}, {'}', zeroValue, newInvalidCharacterError("}", "at start of value").withPos(` [ `, "/0"), ""}, }, @@ -646,7 +646,7 @@ var decoderErrorTestdata = []struct { name: jsontest.Name("ValidArray/InvalidValue"), in: ` [ ] `, calls: []decoderMethodCall{ - {'[', ArrayStart, nil, ""}, + {'[', ArrayStart(), nil, ""}, {']', zeroValue, newInvalidCharacterError("]", "at start of value").withPos(" [ ", "/0"), ""}, }, wantOffset: len(` [`), @@ -664,7 +664,7 @@ var decoderErrorTestdata = []struct { in: `{:`, calls: []decoderMethodCall{ {'{', zeroValue, newInvalidCharacterError(":", `at start of string (expecting '"')`).withPos(`{`, ""), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {0, zeroToken, newInvalidCharacterError(":", "at start of value").withPos(`{`, ""), ""}, {0, zeroValue, newInvalidCharacterError(":", "at start of value").withPos(`{`, ""), ""}, }, @@ -674,7 +674,7 @@ var decoderErrorTestdata = []struct { in: `{"",`, calls: []decoderMethodCall{ {'{', zeroValue, newInvalidCharacterError(",", "after object name (expecting ':')").withPos(`{""`, "/"), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String(""), nil, ""}, {0, zeroToken, newInvalidCharacterError(",", "after object name (expecting ':')").withPos(`{""`, "/"), ""}, {0, zeroValue, newInvalidCharacterError(",", "after object name (expecting ':')").withPos(`{""`, "/"), ""}, @@ -685,7 +685,7 @@ var decoderErrorTestdata = []struct { in: `{"":`, calls: []decoderMethodCall{ {'{', zeroValue, E(io.ErrUnexpectedEOF).withPos(`{"":`, "/"), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String(""), nil, ""}, {0, zeroToken, E(io.ErrUnexpectedEOF).withPos(`{"":`, "/"), ""}, {0, zeroValue, E(io.ErrUnexpectedEOF).withPos(`{"":`, "/"), ""}, @@ -696,7 +696,7 @@ var decoderErrorTestdata = []struct { in: `{"":"":`, calls: []decoderMethodCall{ {'{', zeroValue, newInvalidCharacterError(":", "after object value (expecting ',' or '}')").withPos(`{"":""`, ""), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String(""), nil, ""}, {'"', String(""), nil, ""}, {0, zeroToken, newInvalidCharacterError(":", "after object value (expecting ',' or '}')").withPos(`{"":""`, ""), ""}, @@ -708,7 +708,7 @@ var decoderErrorTestdata = []struct { in: `{"":"",`, calls: []decoderMethodCall{ {'{', zeroValue, E(io.ErrUnexpectedEOF).withPos(`{"":"",`, ""), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String(""), nil, ""}, {'"', String(""), nil, ""}, {0, zeroToken, E(io.ErrUnexpectedEOF).withPos(`{"":"",`, ""), ""}, @@ -720,7 +720,7 @@ var decoderErrorTestdata = []struct { in: `[,`, calls: []decoderMethodCall{ {'[', zeroValue, newInvalidCharacterError(",", "at start of value").withPos(`[`, "/0"), ""}, - {'[', ArrayStart, nil, ""}, + {'[', ArrayStart(), nil, ""}, {0, zeroToken, newInvalidCharacterError(",", "at start of value").withPos(`[`, ""), ""}, {0, zeroValue, newInvalidCharacterError(",", "at start of value").withPos(`[`, ""), ""}, }, @@ -730,7 +730,7 @@ var decoderErrorTestdata = []struct { in: `["":`, calls: []decoderMethodCall{ {'[', zeroValue, newInvalidCharacterError(":", "after array element (expecting ',' or ']')").withPos(`[""`, ""), ""}, - {'[', ArrayStart, nil, ""}, + {'[', ArrayStart(), nil, ""}, {'"', String(""), nil, ""}, {0, zeroToken, newInvalidCharacterError(":", "after array element (expecting ',' or ']')").withPos(`[""`, ""), ""}, {0, zeroValue, newInvalidCharacterError(":", "after array element (expecting ',' or ']')").withPos(`[""`, ""), ""}, @@ -741,7 +741,7 @@ var decoderErrorTestdata = []struct { in: `["",`, calls: []decoderMethodCall{ {'[', zeroValue, E(io.ErrUnexpectedEOF).withPos(`["",`, ""), ""}, - {'[', ArrayStart, nil, ""}, + {'[', ArrayStart(), nil, ""}, {'"', String(""), nil, ""}, {0, zeroToken, E(io.ErrUnexpectedEOF).withPos(`["",`, ""), ""}, {0, zeroValue, E(io.ErrUnexpectedEOF).withPos(`["",`, ""), ""}, @@ -759,7 +759,7 @@ var decoderErrorTestdata = []struct { in: ` [ "a` + "\xff" + `1" ] `, calls: []decoderMethodCall{ {'[', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ "a`, "/0"), ""}, - {'[', ArrayStart, nil, ""}, + {'[', ArrayStart(), nil, ""}, {'"', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ "a`, "/0"), ""}, {'"', zeroToken, E(jsonwire.ErrInvalidUTF8).withPos(` [ "a`, "/0"), ""}, }, @@ -769,7 +769,7 @@ var decoderErrorTestdata = []struct { in: ` [ "a1" , "b` + "\xff" + `1" ] `, calls: []decoderMethodCall{ {'[', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ "a1" , "b`, "/1"), ""}, - {'[', ArrayStart, nil, ""}, + {'[', ArrayStart(), nil, ""}, {'"', String("a1"), nil, ""}, {'"', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ "a1" , "b`, "/1"), ""}, {'"', zeroToken, E(jsonwire.ErrInvalidUTF8).withPos(` [ "a1" , "b`, "/1"), ""}, @@ -780,9 +780,9 @@ var decoderErrorTestdata = []struct { in: ` [ [ "a` + "\xff" + `2" ] ] `, calls: []decoderMethodCall{ {'[', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ [ "a`, "/0/0"), ""}, - {'[', ArrayStart, nil, ""}, + {'[', ArrayStart(), nil, ""}, {'[', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ [ "a`, "/0/0"), ""}, - {'[', ArrayStart, nil, "/0"}, + {'[', ArrayStart(), nil, "/0"}, {'"', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ [ "a`, "/0/0"), ""}, {'"', zeroToken, E(jsonwire.ErrInvalidUTF8).withPos(` [ [ "a`, "/0/0"), ""}, }, @@ -792,10 +792,10 @@ var decoderErrorTestdata = []struct { in: ` [ "a1" , [ "a` + "\xff" + `2" ] ] `, calls: []decoderMethodCall{ {'[', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ "a1" , [ "a`, "/1/0"), ""}, - {'[', ArrayStart, nil, ""}, + {'[', ArrayStart(), nil, ""}, {'"', String("a1"), nil, "/0"}, {'[', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ "a1" , [ "a`, "/1/0"), "/0"}, - {'[', ArrayStart, nil, "/1"}, + {'[', ArrayStart(), nil, "/1"}, {'"', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ "a1" , [ "a`, "/1/0"), "/1"}, {'"', zeroToken, E(jsonwire.ErrInvalidUTF8).withPos(` [ "a1" , [ "a`, "/1/0"), "/1"}, }, @@ -805,9 +805,9 @@ var decoderErrorTestdata = []struct { in: ` [ [ "a2" , "b` + "\xff" + `2" ] ] `, calls: []decoderMethodCall{ {'[', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ [ "a2" , "b`, "/0/1"), ""}, - {'[', ArrayStart, nil, ""}, + {'[', ArrayStart(), nil, ""}, {'[', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ [ "a2" , "b`, "/0/1"), ""}, - {'[', ArrayStart, nil, "/0"}, + {'[', ArrayStart(), nil, "/0"}, {'"', String("a2"), nil, "/0/0"}, {'"', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ [ "a2" , "b`, "/0/1"), "/0/0"}, {'"', zeroToken, E(jsonwire.ErrInvalidUTF8).withPos(` [ [ "a2" , "b`, "/0/1"), "/0/0"}, @@ -818,10 +818,10 @@ var decoderErrorTestdata = []struct { in: ` [ "a1" , [ "a2" , "b` + "\xff" + `2" ] ] `, calls: []decoderMethodCall{ {'[', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ "a1" , [ "a2" , "b`, "/1/1"), ""}, - {'[', ArrayStart, nil, ""}, + {'[', ArrayStart(), nil, ""}, {'"', String("a1"), nil, "/0"}, {'[', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ "a1" , [ "a2" , "b`, "/1/1"), ""}, - {'[', ArrayStart, nil, "/1"}, + {'[', ArrayStart(), nil, "/1"}, {'"', String("a2"), nil, "/1/0"}, {'"', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ "a1" , [ "a2" , "b`, "/1/1"), "/1/0"}, {'"', zeroToken, E(jsonwire.ErrInvalidUTF8).withPos(` [ "a1" , [ "a2" , "b`, "/1/1"), "/1/0"}, @@ -832,7 +832,7 @@ var decoderErrorTestdata = []struct { in: ` { "a` + "\xff" + `1" : "b1" } `, calls: []decoderMethodCall{ {'{', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` { "a`, ""), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` { "a`, ""), ""}, {'"', zeroToken, E(jsonwire.ErrInvalidUTF8).withPos(` { "a`, ""), ""}, }, @@ -842,7 +842,7 @@ var decoderErrorTestdata = []struct { in: ` { "a1" : "b` + "\xff" + `1" } `, calls: []decoderMethodCall{ {'{', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : "b`, "/a1"), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("a1"), nil, "/a1"}, {'"', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : "b`, "/a1"), ""}, {'"', zeroToken, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : "b`, "/a1"), ""}, @@ -853,7 +853,7 @@ var decoderErrorTestdata = []struct { in: ` { "a1" : "b1" , "c` + "\xff" + `1" : "d1" } `, calls: []decoderMethodCall{ {'{', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : "b1" , "c`, ""), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("a1"), nil, "/a1"}, {'"', String("b1"), nil, "/a1"}, {'"', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : "b1" : "c`, ""), "/a1"}, @@ -865,7 +865,7 @@ var decoderErrorTestdata = []struct { in: ` { "a1" : "b1" , "c1" : "d` + "\xff" + `1" } `, calls: []decoderMethodCall{ {'{', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : "b1" , "c1" : "d`, "/c1"), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("a1"), nil, "/a1"}, {'"', String("b1"), nil, "/a1"}, {'"', String("c1"), nil, "/c1"}, @@ -878,10 +878,10 @@ var decoderErrorTestdata = []struct { in: ` { "a1" : { "a` + "\xff" + `2" : "b2" } } `, calls: []decoderMethodCall{ {'{', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : { "a`, "/a1"), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("a1"), nil, "/a1"}, {'{', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : { "a`, "/a1"), ""}, - {'{', ObjectStart, nil, "/a1"}, + {'{', ObjectStart(), nil, "/a1"}, {'"', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : { "a`, "/a1"), "/a1"}, {'"', zeroToken, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : { "a`, "/a1"), "/a1"}, }, @@ -891,10 +891,10 @@ var decoderErrorTestdata = []struct { in: ` { "a1" : { "a2" : "b` + "\xff" + `2" } } `, calls: []decoderMethodCall{ {'{', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : { "a2" : "b`, "/a1/a2"), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("a1"), nil, "/a1"}, {'{', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : { "a2" : "b`, "/a1/a2"), ""}, - {'{', ObjectStart, nil, "/a1"}, + {'{', ObjectStart(), nil, "/a1"}, {'"', String("a2"), nil, "/a1/a2"}, {'"', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : { "a2" : "b`, "/a1/a2"), "/a1/a2"}, {'"', zeroToken, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : { "a2" : "b`, "/a1/a2"), "/a1/a2"}, @@ -905,9 +905,9 @@ var decoderErrorTestdata = []struct { in: ` { "a1" : { "a2" : "b2" , "c` + "\xff" + `2" : "d2" } } `, calls: []decoderMethodCall{ {'{', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : { "a2" : "b2" , "c`, "/a1"), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("a1"), nil, "/a1"}, - {'{', ObjectStart, nil, "/a1"}, + {'{', ObjectStart(), nil, "/a1"}, {'"', String("a2"), nil, "/a1/a2"}, {'"', String("b2"), nil, "/a1/a2"}, {'"', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : { "a2" : "b2" , "c`, "/a1"), "/a1/a2"}, @@ -919,10 +919,10 @@ var decoderErrorTestdata = []struct { in: ` { "a1" : { "a2" : "b2" , "c2" : "d` + "\xff" + `2" } } `, calls: []decoderMethodCall{ {'{', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : { "a2" : "b2" , "c2" : "d`, "/a1/c2"), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("a1"), nil, "/a1"}, {'{', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : { "a2" : "b2" , "c2" : "d`, "/a1/c2"), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("a2"), nil, "/a1/a2"}, {'"', String("b2"), nil, "/a1/a2"}, {'"', String("c2"), nil, "/a1/c2"}, @@ -935,10 +935,10 @@ var decoderErrorTestdata = []struct { in: ` [ "a1" , { "a2" : "b` + "\xff" + `2" } ] `, calls: []decoderMethodCall{ {'[', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ "a1" , { "a2" : "b`, "/1/a2"), ""}, - {'[', ArrayStart, nil, ""}, + {'[', ArrayStart(), nil, ""}, {'"', String("a1"), nil, "/0"}, {'{', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ "a1" , { "a2" : "b`, "/1/a2"), ""}, - {'{', ObjectStart, nil, "/1"}, + {'{', ObjectStart(), nil, "/1"}, {'"', String("a2"), nil, "/1/a2"}, {'"', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ "a1" , { "a2" : "b`, "/1/a2"), "/1/a2"}, {'"', zeroToken, E(jsonwire.ErrInvalidUTF8).withPos(` [ "a1" , { "a2" : "b`, "/1/a2"), "/1/a2"}, @@ -949,12 +949,12 @@ var decoderErrorTestdata = []struct { in: ` { "a1" : "b1" , "c1" : [ "a2" , "b` + "\xff" + `2" ] } `, calls: []decoderMethodCall{ {'{', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : "b1" , "c1" : [ "a2" , "b`, "/c1/1"), ""}, - {'{', ObjectStart, nil, ""}, + {'{', ObjectStart(), nil, ""}, {'"', String("a1"), nil, "/a1"}, {'"', String("b1"), nil, "/a1"}, {'"', String("c1"), nil, "/c1"}, {'[', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : "b1" , "c1" : [ "a2" , "b`, "/c1/1"), ""}, - {'[', ArrayStart, nil, "/c1"}, + {'[', ArrayStart(), nil, "/c1"}, {'"', String("a2"), nil, "/c1/0"}, {'"', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : "b1" , "c1" : [ "a2" , "b`, "/c1/1"), "/c1/0"}, {'"', zeroToken, E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : "b1" , "c1" : [ "a2" , "b`, "/c1/1"), "/c1/0"}, @@ -965,20 +965,20 @@ var decoderErrorTestdata = []struct { in: ` [ { "a1" : [ "a2" , { "a3" : "b3" , "c3" : [ "a4" , "b` + "\xff" + `4" ] } ] } ] `, calls: []decoderMethodCall{ {'[', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ { "a1" : [ "a2" , { "a3" : "b3" , "c3" : [ "a4" , "b`, "/0/a1/1/c3/1"), ""}, - {'[', ArrayStart, nil, ""}, + {'[', ArrayStart(), nil, ""}, {'{', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ { "a1" : [ "a2" , { "a3" : "b3" , "c3" : [ "a4" , "b`, "/0/a1/1/c3/1"), ""}, - {'{', ObjectStart, nil, "/0"}, + {'{', ObjectStart(), nil, "/0"}, {'"', String("a1"), nil, "/0/a1"}, {'[', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ { "a1" : [ "a2" , { "a3" : "b3" , "c3" : [ "a4" , "b`, "/0/a1/1/c3/1"), ""}, - {'[', ArrayStart, nil, ""}, + {'[', ArrayStart(), nil, ""}, {'"', String("a2"), nil, "/0/a1/0"}, {'{', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ { "a1" : [ "a2" , { "a3" : "b3" , "c3" : [ "a4" , "b`, "/0/a1/1/c3/1"), ""}, - {'{', ObjectStart, nil, "/0/a1/1"}, + {'{', ObjectStart(), nil, "/0/a1/1"}, {'"', String("a3"), nil, "/0/a1/1/a3"}, {'"', String("b3"), nil, "/0/a1/1/a3"}, {'"', String("c3"), nil, "/0/a1/1/c3"}, {'[', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ { "a1" : [ "a2" , { "a3" : "b3" , "c3" : [ "a4" , "b`, "/0/a1/1/c3/1"), ""}, - {'[', ArrayStart, nil, "/0/a1/1/c3"}, + {'[', ArrayStart(), nil, "/0/a1/1/c3"}, {'"', String("a4"), nil, "/0/a1/1/c3/0"}, {'"', zeroValue, E(jsonwire.ErrInvalidUTF8).withPos(` [ { "a1" : [ "a2" , { "a3" : "b3" , "c3" : [ "a4" , "b`, "/0/a1/1/c3/1"), "/0/a1/1/c3/0"}, {'"', zeroToken, E(jsonwire.ErrInvalidUTF8).withPos(` [ { "a1" : [ "a2" , { "a3" : "b3" , "c3" : [ "a4" , "b`, "/0/a1/1/c3/1"), "/0/a1/1/c3/0"}, diff --git a/jsontext/encode_test.go b/jsontext/encode_test.go index fe8af3e..15b1c55 100644 --- a/jsontext/encode_test.go +++ b/jsontext/encode_test.go @@ -224,9 +224,9 @@ var encoderErrorTestdata = []struct { calls: []encoderMethodCall{ {String("living\xde\xad\xbe\xef"), E(jsonwire.ErrInvalidUTF8), ""}, {Value("\"living\xde\xad\xbe\xef\""), E(jsonwire.ErrInvalidUTF8).withPos("\"living\xde\xad", ""), ""}, - {ObjectStart, nil, ""}, + {ObjectStart(), nil, ""}, {String("name"), nil, ""}, - {ArrayStart, nil, ""}, + {ArrayStart(), nil, ""}, {String("living\xde\xad\xbe\xef"), E(jsonwire.ErrInvalidUTF8).withPos(`{"name":[`, "/name/0"), ""}, {Value("\"living\xde\xad\xbe\xef\""), E(jsonwire.ErrInvalidUTF8).withPos("{\"name\":[\"living\xde\xad", "/name/0"), ""}, }, @@ -293,20 +293,20 @@ var encoderErrorTestdata = []struct { {Value(`{ 0 }`), newInvalidCharacterError("0", `at start of string (expecting '"')`).withPos(`{ `, ""), ""}, {Value(`{ {} }`), newInvalidCharacterError("{", `at start of string (expecting '"')`).withPos(`{ `, ""), ""}, {Value(`{ [] }`), newInvalidCharacterError("[", `at start of string (expecting '"')`).withPos(`{ `, ""), ""}, - {ObjectStart, nil, ""}, - {Null, E(ErrNonStringName).withPos(`{`, ""), ""}, + {ObjectStart(), nil, ""}, + {Null(), E(ErrNonStringName).withPos(`{`, ""), ""}, {Value(`null`), E(ErrNonStringName).withPos(`{`, ""), ""}, - {False, E(ErrNonStringName).withPos(`{`, ""), ""}, + {Bool(false), E(ErrNonStringName).withPos(`{`, ""), ""}, {Value(`false`), E(ErrNonStringName).withPos(`{`, ""), ""}, - {True, E(ErrNonStringName).withPos(`{`, ""), ""}, + {Bool(true), E(ErrNonStringName).withPos(`{`, ""), ""}, {Value(`true`), E(ErrNonStringName).withPos(`{`, ""), ""}, {Uint(0), E(ErrNonStringName).withPos(`{`, ""), ""}, {Value(`0`), E(ErrNonStringName).withPos(`{`, ""), ""}, - {ObjectStart, E(ErrNonStringName).withPos(`{`, ""), ""}, + {ObjectStart(), E(ErrNonStringName).withPos(`{`, ""), ""}, {Value(`{}`), E(ErrNonStringName).withPos(`{`, ""), ""}, - {ArrayStart, E(ErrNonStringName).withPos(`{`, ""), ""}, + {ArrayStart(), E(ErrNonStringName).withPos(`{`, ""), ""}, {Value(`[]`), E(ErrNonStringName).withPos(`{`, ""), ""}, - {ObjectEnd, nil, ""}, + {ObjectEnd(), nil, ""}, }, wantOut: "{}\n", }, { @@ -319,21 +319,21 @@ var encoderErrorTestdata = []struct { calls: []encoderMethodCall{ {Value(` { ] `), newInvalidCharacterError("]", `at start of string (expecting '"')`).withPos(` { `, ""), ""}, {Value(` { "0":0 ] `), newInvalidCharacterError("]", `after object value (expecting ',' or '}')`).withPos(` { "0":0 `, ""), ""}, - {ObjectStart, nil, ""}, - {ArrayEnd, E(errMismatchDelim).withPos(`{`, ""), ""}, + {ObjectStart(), nil, ""}, + {ArrayEnd(), E(errMismatchDelim).withPos(`{`, ""), ""}, {Value(`]`), newInvalidCharacterError("]", "at start of value").withPos(`{`, ""), ""}, - {ObjectEnd, nil, ""}, + {ObjectEnd(), nil, ""}, }, wantOut: "{}\n", }, { name: jsontest.Name("ValidObject/UniqueNames"), calls: []encoderMethodCall{ - {ObjectStart, nil, ""}, + {ObjectStart(), nil, ""}, {String("0"), nil, ""}, {Uint(0), nil, ""}, {String("1"), nil, ""}, {Uint(1), nil, ""}, - {ObjectEnd, nil, ""}, + {ObjectEnd(), nil, ""}, {Value(` { "0" : 0 , "1" : 1 } `), nil, ""}, }, wantOut: `{"0":0,"1":1}` + "\n" + `{"0":0,"1":1}` + "\n", @@ -341,32 +341,32 @@ var encoderErrorTestdata = []struct { name: jsontest.Name("ValidObject/DuplicateNames"), opts: []Options{AllowDuplicateNames(true)}, calls: []encoderMethodCall{ - {ObjectStart, nil, ""}, + {ObjectStart(), nil, ""}, {String("0"), nil, ""}, {Uint(0), nil, ""}, {String("0"), nil, ""}, {Uint(0), nil, ""}, - {ObjectEnd, nil, ""}, + {ObjectEnd(), nil, ""}, {Value(` { "0" : 0 , "0" : 0 } `), nil, ""}, }, wantOut: `{"0":0,"0":0}` + "\n" + `{"0":0,"0":0}` + "\n", }, { name: jsontest.Name("InvalidObject/DuplicateNames"), calls: []encoderMethodCall{ - {ObjectStart, nil, ""}, + {ObjectStart(), nil, ""}, {String("X"), nil, ""}, - {ObjectStart, nil, ""}, - {ObjectEnd, nil, ""}, + {ObjectStart(), nil, ""}, + {ObjectEnd(), nil, ""}, {String("X"), E(ErrDuplicateName).withPos(`{"X":{},`, "/X"), "/X"}, {Value(`"X"`), E(ErrDuplicateName).withPos(`{"X":{},`, "/X"), "/X"}, {String("Y"), nil, ""}, - {ObjectStart, nil, ""}, - {ObjectEnd, nil, ""}, + {ObjectStart(), nil, ""}, + {ObjectEnd(), nil, ""}, {String("X"), E(ErrDuplicateName).withPos(`{"X":{},"Y":{},`, "/X"), "/Y"}, {Value(`"X"`), E(ErrDuplicateName).withPos(`{"X":{},"Y":{},`, "/X"), "/Y"}, {String("Y"), E(ErrDuplicateName).withPos(`{"X":{},"Y":{},`, "/Y"), "/Y"}, {Value(`"Y"`), E(ErrDuplicateName).withPos(`{"X":{},"Y":{},`, "/Y"), "/Y"}, - {ObjectEnd, nil, ""}, + {ObjectEnd(), nil, ""}, {Value(` { "X" : 0 , "Y" : 1 , "X" : 0 } `), E(ErrDuplicateName).withPos(`{"X":{},"Y":{}}`+"\n"+` { "X" : 0 , "Y" : 1 , `, "/X"), ""}, }, wantOut: `{"X":{},"Y":{}}` + "\n", @@ -394,10 +394,10 @@ var encoderErrorTestdata = []struct { name: jsontest.Name("InvalidArray/MismatchingDelim"), calls: []encoderMethodCall{ {Value(` [ } `), newInvalidCharacterError("}", `at start of value`).withPos(` [ `, "/0"), ""}, - {ArrayStart, nil, ""}, - {ObjectEnd, E(errMismatchDelim).withPos(`[`, "/0"), ""}, + {ArrayStart(), nil, ""}, + {ObjectEnd(), E(errMismatchDelim).withPos(`[`, "/0"), ""}, {Value(`}`), newInvalidCharacterError("}", "at start of value").withPos(`[`, "/0"), ""}, - {ArrayEnd, nil, ""}, + {ArrayEnd(), nil, ""}, }, wantOut: "[]\n", }, { @@ -444,8 +444,8 @@ var encoderErrorTestdata = []struct { PreserveRawStrings(true), }, calls: []encoderMethodCall{ - {ArrayStart, nil, ""}, - {ArrayStart, nil, ""}, + {ArrayStart(), nil, ""}, + {ArrayStart(), nil, ""}, {Value(` { "fizz" : "buzz" , "zip" : { "x` + "\xfd" + `x" : 123 , "x` + "\xff" + `x" : 123, "x` + "\xfe" + `x" : 123 @@ -454,8 +454,8 @@ var encoderErrorTestdata = []struct { "xxx" : 333, "xxx": 1, "xxx": 22 }, "alpha" : "bravo" } `), nil, ""}, - {ArrayEnd, nil, ""}, - {ArrayEnd, nil, ""}, + {ArrayEnd(), nil, ""}, + {ArrayEnd(), nil, ""}, }, wantOut: "[\n \t[\n \t\t{\n \t\t\t\"alpha\":\"bravo\", \n \t\t\t\"fizz\":\"buzz\", \n \t\t\t\"zap\":{\n \t\t\t\t\"xxx\":1, \n \t\t\t\t\"xxx\":22, \n \t\t\t\t\"xxx\":333\n \t\t\t}, \n \t\t\t\"zip\":{\n \t\t\t\t\"x\xfdx\":123, \n \t\t\t\t\"x\xfex\":123, \n \t\t\t\t\"x\xffx\":123\n \t\t\t}\n \t\t}\n \t]\n ]\n", }, { @@ -482,7 +482,7 @@ var encoderErrorTestdata = []struct { name: jsontest.Name("ErrorPosition/0"), calls: []encoderMethodCall{ {Value(` [ "a` + "\xff" + `1" ] `), E(jsonwire.ErrInvalidUTF8).withPos(` [ "a`, "/0"), ""}, - {ArrayStart, nil, ""}, + {ArrayStart(), nil, ""}, {Value(` "a` + "\xff" + `1" `), E(jsonwire.ErrInvalidUTF8).withPos(`[ "a`, "/0"), ""}, {String(`a` + "\xff" + `1`), E(jsonwire.ErrInvalidUTF8).withPos(`[`, "/0"), ""}, }, @@ -491,7 +491,7 @@ var encoderErrorTestdata = []struct { name: jsontest.Name("ErrorPosition/1"), calls: []encoderMethodCall{ {Value(` [ "a1" , "b` + "\xff" + `1" ] `), E(jsonwire.ErrInvalidUTF8).withPos(` [ "a1" , "b`, "/1"), ""}, - {ArrayStart, nil, ""}, + {ArrayStart(), nil, ""}, {String("a1"), nil, ""}, {Value(` "b` + "\xff" + `1" `), E(jsonwire.ErrInvalidUTF8).withPos(`["a1", "b`, "/1"), ""}, {String(`b` + "\xff" + `1`), E(jsonwire.ErrInvalidUTF8).withPos(`["a1",`, "/1"), ""}, @@ -501,9 +501,9 @@ var encoderErrorTestdata = []struct { name: jsontest.Name("ErrorPosition/0/0"), calls: []encoderMethodCall{ {Value(` [ [ "a` + "\xff" + `2" ] ] `), E(jsonwire.ErrInvalidUTF8).withPos(` [ [ "a`, "/0/0"), ""}, - {ArrayStart, nil, ""}, + {ArrayStart(), nil, ""}, {Value(` [ "a` + "\xff" + `2" ] `), E(jsonwire.ErrInvalidUTF8).withPos(`[ [ "a`, "/0/0"), ""}, - {ArrayStart, nil, "/0"}, + {ArrayStart(), nil, "/0"}, {Value(` "a` + "\xff" + `2" `), E(jsonwire.ErrInvalidUTF8).withPos(`[[ "a`, "/0/0"), "/0"}, {String(`a` + "\xff" + `2`), E(jsonwire.ErrInvalidUTF8).withPos(`[[`, "/0/0"), "/0"}, }, @@ -512,10 +512,10 @@ var encoderErrorTestdata = []struct { name: jsontest.Name("ErrorPosition/1/0"), calls: []encoderMethodCall{ {Value(` [ "a1" , [ "a` + "\xff" + `2" ] ] `), E(jsonwire.ErrInvalidUTF8).withPos(` [ "a1" , [ "a`, "/1/0"), ""}, - {ArrayStart, nil, ""}, + {ArrayStart(), nil, ""}, {String("a1"), nil, "/0"}, {Value(` [ "a` + "\xff" + `2" ] `), E(jsonwire.ErrInvalidUTF8).withPos(`["a1", [ "a`, "/1/0"), ""}, - {ArrayStart, nil, "/1"}, + {ArrayStart(), nil, "/1"}, {Value(` "a` + "\xff" + `2" `), E(jsonwire.ErrInvalidUTF8).withPos(`["a1",[ "a`, "/1/0"), "/1"}, {String(`a` + "\xff" + `2`), E(jsonwire.ErrInvalidUTF8).withPos(`["a1",[`, "/1/0"), "/1"}, }, @@ -524,9 +524,9 @@ var encoderErrorTestdata = []struct { name: jsontest.Name("ErrorPosition/0/1"), calls: []encoderMethodCall{ {Value(` [ [ "a2" , "b` + "\xff" + `2" ] ] `), E(jsonwire.ErrInvalidUTF8).withPos(` [ [ "a2" , "b`, "/0/1"), ""}, - {ArrayStart, nil, ""}, + {ArrayStart(), nil, ""}, {Value(` [ "a2" , "b` + "\xff" + `2" ] `), E(jsonwire.ErrInvalidUTF8).withPos(`[ [ "a2" , "b`, "/0/1"), ""}, - {ArrayStart, nil, "/0"}, + {ArrayStart(), nil, "/0"}, {String("a2"), nil, "/0/0"}, {Value(` "b` + "\xff" + `2" `), E(jsonwire.ErrInvalidUTF8).withPos(`[["a2", "b`, "/0/1"), "/0/0"}, {String(`b` + "\xff" + `2`), E(jsonwire.ErrInvalidUTF8).withPos(`[["a2",`, "/0/1"), "/0/0"}, @@ -536,10 +536,10 @@ var encoderErrorTestdata = []struct { name: jsontest.Name("ErrorPosition/1/1"), calls: []encoderMethodCall{ {Value(` [ "a1" , [ "a2" , "b` + "\xff" + `2" ] ] `), E(jsonwire.ErrInvalidUTF8).withPos(` [ "a1" , [ "a2" , "b`, "/1/1"), ""}, - {ArrayStart, nil, ""}, + {ArrayStart(), nil, ""}, {String("a1"), nil, "/0"}, {Value(` [ "a2" , "b` + "\xff" + `2" ] `), E(jsonwire.ErrInvalidUTF8).withPos(`["a1", [ "a2" , "b`, "/1/1"), ""}, - {ArrayStart, nil, "/1"}, + {ArrayStart(), nil, "/1"}, {String("a2"), nil, "/1/0"}, {Value(` "b` + "\xff" + `2" `), E(jsonwire.ErrInvalidUTF8).withPos(`["a1",["a2", "b`, "/1/1"), "/1/0"}, {String(`b` + "\xff" + `2`), E(jsonwire.ErrInvalidUTF8).withPos(`["a1",["a2",`, "/1/1"), "/1/0"}, @@ -549,7 +549,7 @@ var encoderErrorTestdata = []struct { name: jsontest.Name("ErrorPosition/a1-"), calls: []encoderMethodCall{ {Value(` { "a` + "\xff" + `1" : "b1" } `), E(jsonwire.ErrInvalidUTF8).withPos(` { "a`, ""), ""}, - {ObjectStart, nil, ""}, + {ObjectStart(), nil, ""}, {Value(` "a` + "\xff" + `1" `), E(jsonwire.ErrInvalidUTF8).withPos(`{ "a`, ""), ""}, {String(`a` + "\xff" + `1`), E(jsonwire.ErrInvalidUTF8).withPos(`{`, ""), ""}, }, @@ -558,7 +558,7 @@ var encoderErrorTestdata = []struct { name: jsontest.Name("ErrorPosition/a1"), calls: []encoderMethodCall{ {Value(` { "a1" : "b` + "\xff" + `1" } `), E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : "b`, "/a1"), ""}, - {ObjectStart, nil, ""}, + {ObjectStart(), nil, ""}, {String("a1"), nil, "/a1"}, {Value(` "b` + "\xff" + `1" `), E(jsonwire.ErrInvalidUTF8).withPos(`{"a1": "b`, "/a1"), ""}, {String(`b` + "\xff" + `1`), E(jsonwire.ErrInvalidUTF8).withPos(`{"a1":`, "/a1"), ""}, @@ -568,7 +568,7 @@ var encoderErrorTestdata = []struct { name: jsontest.Name("ErrorPosition/c1-"), calls: []encoderMethodCall{ {Value(` { "a1" : "b1" , "c` + "\xff" + `1" : "d1" } `), E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : "b1" , "c`, ""), ""}, - {ObjectStart, nil, ""}, + {ObjectStart(), nil, ""}, {String("a1"), nil, "/a1"}, {String("b1"), nil, "/a1"}, {Value(` "c` + "\xff" + `1" `), E(jsonwire.ErrInvalidUTF8).withPos(`{"a1":"b1": "c`, ""), "/a1"}, @@ -579,7 +579,7 @@ var encoderErrorTestdata = []struct { name: jsontest.Name("ErrorPosition/c1"), calls: []encoderMethodCall{ {Value(` { "a1" : "b1" , "c1" : "d` + "\xff" + `1" } `), E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : "b1" , "c1" : "d`, "/c1"), ""}, - {ObjectStart, nil, ""}, + {ObjectStart(), nil, ""}, {String("a1"), nil, "/a1"}, {String("b1"), nil, "/a1"}, {String("c1"), nil, "/c1"}, @@ -591,10 +591,10 @@ var encoderErrorTestdata = []struct { name: jsontest.Name("ErrorPosition/a1/a2-"), calls: []encoderMethodCall{ {Value(` { "a1" : { "a` + "\xff" + `2" : "b2" } } `), E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : { "a`, "/a1"), ""}, - {ObjectStart, nil, ""}, + {ObjectStart(), nil, ""}, {String("a1"), nil, "/a1"}, {Value(` { "a` + "\xff" + `2" : "b2" } `), E(jsonwire.ErrInvalidUTF8).withPos(`{"a1": { "a`, "/a1"), ""}, - {ObjectStart, nil, "/a1"}, + {ObjectStart(), nil, "/a1"}, {Value(` "a` + "\xff" + `2" `), E(jsonwire.ErrInvalidUTF8).withPos(`{"a1":{ "a`, "/a1"), "/a1"}, {String(`a` + "\xff" + `2`), E(jsonwire.ErrInvalidUTF8).withPos(`{"a1":{`, "/a1"), "/a1"}, }, @@ -603,10 +603,10 @@ var encoderErrorTestdata = []struct { name: jsontest.Name("ErrorPosition/a1/a2"), calls: []encoderMethodCall{ {Value(` { "a1" : { "a2" : "b` + "\xff" + `2" } } `), E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : { "a2" : "b`, "/a1/a2"), ""}, - {ObjectStart, nil, ""}, + {ObjectStart(), nil, ""}, {String("a1"), nil, "/a1"}, {Value(` { "a2" : "b` + "\xff" + `2" } `), E(jsonwire.ErrInvalidUTF8).withPos(`{"a1": { "a2" : "b`, "/a1/a2"), ""}, - {ObjectStart, nil, "/a1"}, + {ObjectStart(), nil, "/a1"}, {String("a2"), nil, "/a1/a2"}, {Value(` "b` + "\xff" + `2" `), E(jsonwire.ErrInvalidUTF8).withPos(`{"a1":{"a2": "b`, "/a1/a2"), "/a1/a2"}, {String(`b` + "\xff" + `2`), E(jsonwire.ErrInvalidUTF8).withPos(`{"a1":{"a2":`, "/a1/a2"), "/a1/a2"}, @@ -616,9 +616,9 @@ var encoderErrorTestdata = []struct { name: jsontest.Name("ErrorPosition/a1/c2-"), calls: []encoderMethodCall{ {Value(` { "a1" : { "a2" : "b2" , "c` + "\xff" + `2" : "d2" } } `), E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : { "a2" : "b2" , "c`, "/a1"), ""}, - {ObjectStart, nil, ""}, + {ObjectStart(), nil, ""}, {String("a1"), nil, "/a1"}, - {ObjectStart, nil, "/a1"}, + {ObjectStart(), nil, "/a1"}, {String("a2"), nil, "/a1/a2"}, {String("b2"), nil, "/a1/a2"}, {Value(` "c` + "\xff" + `2" `), E(jsonwire.ErrInvalidUTF8).withPos(`{"a1":{"a2":"b2", "c`, "/a1"), "/a1/a2"}, @@ -629,10 +629,10 @@ var encoderErrorTestdata = []struct { name: jsontest.Name("ErrorPosition/a1/c2"), calls: []encoderMethodCall{ {Value(` { "a1" : { "a2" : "b2" , "c2" : "d` + "\xff" + `2" } } `), E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : { "a2" : "b2" , "c2" : "d`, "/a1/c2"), ""}, - {ObjectStart, nil, ""}, + {ObjectStart(), nil, ""}, {String("a1"), nil, "/a1"}, {Value(` { "a2" : "b2" , "c2" : "d` + "\xff" + `2" } `), E(jsonwire.ErrInvalidUTF8).withPos(`{"a1": { "a2" : "b2" , "c2" : "d`, "/a1/c2"), ""}, - {ObjectStart, nil, ""}, + {ObjectStart(), nil, ""}, {String("a2"), nil, "/a1/a2"}, {String("b2"), nil, "/a1/a2"}, {String("c2"), nil, "/a1/c2"}, @@ -644,10 +644,10 @@ var encoderErrorTestdata = []struct { name: jsontest.Name("ErrorPosition/1/a2"), calls: []encoderMethodCall{ {Value(` [ "a1" , { "a2" : "b` + "\xff" + `2" } ] `), E(jsonwire.ErrInvalidUTF8).withPos(` [ "a1" , { "a2" : "b`, "/1/a2"), ""}, - {ArrayStart, nil, ""}, + {ArrayStart(), nil, ""}, {String("a1"), nil, "/0"}, {Value(` { "a2" : "b` + "\xff" + `2" } `), E(jsonwire.ErrInvalidUTF8).withPos(`["a1", { "a2" : "b`, "/1/a2"), ""}, - {ObjectStart, nil, "/1"}, + {ObjectStart(), nil, "/1"}, {String("a2"), nil, "/1/a2"}, {Value(` "b` + "\xff" + `2" `), E(jsonwire.ErrInvalidUTF8).withPos(`["a1",{"a2": "b`, "/1/a2"), "/1/a2"}, {String(`b` + "\xff" + `2`), E(jsonwire.ErrInvalidUTF8).withPos(`["a1",{"a2":`, "/1/a2"), "/1/a2"}, @@ -657,12 +657,12 @@ var encoderErrorTestdata = []struct { name: jsontest.Name("ErrorPosition/c1/1"), calls: []encoderMethodCall{ {Value(` { "a1" : "b1" , "c1" : [ "a2" , "b` + "\xff" + `2" ] } `), E(jsonwire.ErrInvalidUTF8).withPos(` { "a1" : "b1" , "c1" : [ "a2" , "b`, "/c1/1"), ""}, - {ObjectStart, nil, ""}, + {ObjectStart(), nil, ""}, {String("a1"), nil, "/a1"}, {String("b1"), nil, "/a1"}, {String("c1"), nil, "/c1"}, {Value(` [ "a2" , "b` + "\xff" + `2" ] `), E(jsonwire.ErrInvalidUTF8).withPos(`{"a1":"b1","c1": [ "a2" , "b`, "/c1/1"), ""}, - {ArrayStart, nil, "/c1"}, + {ArrayStart(), nil, "/c1"}, {String("a2"), nil, "/c1/0"}, {Value(` "b` + "\xff" + `2" `), E(jsonwire.ErrInvalidUTF8).withPos(`{"a1":"b1","c1":["a2", "b`, "/c1/1"), "/c1/0"}, {String(`b` + "\xff" + `2`), E(jsonwire.ErrInvalidUTF8).withPos(`{"a1":"b1","c1":["a2",`, "/c1/1"), "/c1/0"}, @@ -672,20 +672,20 @@ var encoderErrorTestdata = []struct { name: jsontest.Name("ErrorPosition/0/a1/1/c3/1"), calls: []encoderMethodCall{ {Value(` [ { "a1" : [ "a2" , { "a3" : "b3" , "c3" : [ "a4" , "b` + "\xff" + `4" ] } ] } ] `), E(jsonwire.ErrInvalidUTF8).withPos(` [ { "a1" : [ "a2" , { "a3" : "b3" , "c3" : [ "a4" , "b`, "/0/a1/1/c3/1"), ""}, - {ArrayStart, nil, ""}, + {ArrayStart(), nil, ""}, {Value(` { "a1" : [ "a2" , { "a3" : "b3" , "c3" : [ "a4" , "b` + "\xff" + `4" ] } ] } `), E(jsonwire.ErrInvalidUTF8).withPos(`[ { "a1" : [ "a2" , { "a3" : "b3" , "c3" : [ "a4" , "b`, "/0/a1/1/c3/1"), ""}, - {ObjectStart, nil, "/0"}, + {ObjectStart(), nil, "/0"}, {String("a1"), nil, "/0/a1"}, {Value(` [ "a2" , { "a3" : "b3" , "c3" : [ "a4" , "b` + "\xff" + `4" ] } ] `), E(jsonwire.ErrInvalidUTF8).withPos(`[{"a1": [ "a2" , { "a3" : "b3" , "c3" : [ "a4" , "b`, "/0/a1/1/c3/1"), ""}, - {ArrayStart, nil, ""}, + {ArrayStart(), nil, ""}, {String("a2"), nil, "/0/a1/0"}, {Value(` { "a3" : "b3" , "c3" : [ "a4" , "b` + "\xff" + `4" ] } `), E(jsonwire.ErrInvalidUTF8).withPos(`[{"a1":["a2", { "a3" : "b3" , "c3" : [ "a4" , "b`, "/0/a1/1/c3/1"), ""}, - {ObjectStart, nil, "/0/a1/1"}, + {ObjectStart(), nil, "/0/a1/1"}, {String("a3"), nil, "/0/a1/1/a3"}, {String("b3"), nil, "/0/a1/1/a3"}, {String("c3"), nil, "/0/a1/1/c3"}, {Value(` [ "a4" , "b` + "\xff" + `4" ] `), E(jsonwire.ErrInvalidUTF8).withPos(`[{"a1":["a2",{"a3":"b3","c3": [ "a4" , "b`, "/0/a1/1/c3/1"), ""}, - {ArrayStart, nil, "/0/a1/1/c3"}, + {ArrayStart(), nil, "/0/a1/1/c3"}, {String("a4"), nil, "/0/a1/1/c3/0"}, {Value(` "b` + "\xff" + `4" `), E(jsonwire.ErrInvalidUTF8).withPos(`[{"a1":["a2",{"a3":"b3","c3":["a4", "b`, "/0/a1/1/c3/1"), "/0/a1/1/c3/0"}, {String(`b` + "\xff" + `4`), E(jsonwire.ErrInvalidUTF8).withPos(`[{"a1":["a2",{"a3":"b3","c3":["a4",`, "/0/a1/1/c3/1"), "/0/a1/1/c3/0"}, diff --git a/jsontext/token.go b/jsontext/token.go index b389fc0..35868fc 100644 --- a/jsontext/token.go +++ b/jsontext/token.go @@ -90,14 +90,14 @@ type Token struct { // TODO: Does representing 1-byte delimiters as *decodeBuffer cause performance issues? var ( - Null Token = rawToken("null") - False Token = rawToken("false") - True Token = rawToken("true") + nullToken Token = rawToken("null") + falseToken Token = rawToken("false") + trueToken Token = rawToken("true") - ObjectStart Token = rawToken("{") - ObjectEnd Token = rawToken("}") - ArrayStart Token = rawToken("[") - ArrayEnd Token = rawToken("]") + objectStartToken Token = rawToken("{") + objectEndToken Token = rawToken("}") + arrayStartToken Token = rawToken("[") + arrayEndToken Token = rawToken("]") zeroString Token = rawToken(`""`) zeroNumber Token = rawToken(`0`) @@ -111,12 +111,15 @@ func rawToken(s string) Token { return Token{raw: &decodeBuffer{buf: []byte(s), prevStart: 0, prevEnd: len(s)}} } +// Null returns a Token representing a JSON null. +func Null() Token { return nullToken } + // Bool constructs a Token representing a JSON boolean. func Bool(b bool) Token { if b { - return True + return trueToken } - return False + return falseToken } // String constructs a Token representing a JSON string. @@ -162,6 +165,18 @@ func Uint(n uint64) Token { return Token{str: "u", num: uint64(n)} } +// ObjectStart returns a Token representing the start of a JSON object. +func ObjectStart() Token { return objectStartToken } + +// ObjectEnd returns a Token representing the end of a JSON object. +func ObjectEnd() Token { return objectEndToken } + +// ArrayStart returns a Token representing the start of a JSON array. +func ArrayStart() Token { return arrayStartToken } + +// ArrayEnd returns a Token representing the end of a JSON array. +func ArrayEnd() Token { return arrayEndToken } + // Clone makes a copy of the Token such that its value remains valid // even after a subsequent [Decoder.Read] call. func (t Token) Clone() Token { @@ -170,20 +185,20 @@ func (t Token) Clone() Token { // Avoid copying globals. if t.raw.prevStart == 0 { switch t.raw { - case Null.raw: - return Null - case False.raw: - return False - case True.raw: - return True - case ObjectStart.raw: - return ObjectStart - case ObjectEnd.raw: - return ObjectEnd - case ArrayStart.raw: - return ArrayStart - case ArrayEnd.raw: - return ArrayEnd + case nullToken.raw: + return nullToken + case falseToken.raw: + return falseToken + case trueToken.raw: + return trueToken + case objectStartToken.raw: + return objectStartToken + case objectEndToken.raw: + return objectEndToken + case arrayStartToken.raw: + return arrayStartToken + case arrayEndToken.raw: + return arrayEndToken } } @@ -200,9 +215,9 @@ func (t Token) Clone() Token { // It panics if the token kind is not a JSON boolean. func (t Token) Bool() bool { switch t.raw { - case True.raw: + case trueToken.raw: return true - case False.raw: + case falseToken.raw: return false default: panic("invalid JSON token kind: " + t.Kind().String()) diff --git a/jsontext/token_test.go b/jsontext/token_test.go index 2180b6a..e1f5aee 100644 --- a/jsontext/token_test.go +++ b/jsontext/token_test.go @@ -44,15 +44,15 @@ func TestTokenAccessors(t *testing.T) { want token }{ {Token{}, token{String: ""}}, - {Null, token{String: "null", Kind: 'n'}}, - {False, token{Bool: false, String: "false", Kind: 'f'}}, - {True, token{Bool: true, String: "true", Kind: 't'}}, + {Null(), token{String: "null", Kind: 'n'}}, {Bool(false), token{Bool: false, String: "false", Kind: 'f'}}, {Bool(true), token{Bool: true, String: "true", Kind: 't'}}, - {ObjectStart, token{String: "{", Kind: '{'}}, - {ObjectEnd, token{String: "}", Kind: '}'}}, - {ArrayStart, token{String: "[", Kind: '['}}, - {ArrayEnd, token{String: "]", Kind: ']'}}, + {Bool(false), token{Bool: false, String: "false", Kind: 'f'}}, + {Bool(true), token{Bool: true, String: "true", Kind: 't'}}, + {ObjectStart(), token{String: "{", Kind: '{'}}, + {ObjectEnd(), token{String: "}", Kind: '}'}}, + {ArrayStart(), token{String: "[", Kind: '['}}, + {ArrayEnd(), token{String: "]", Kind: ']'}}, {String(""), token{String: "", Kind: '"'}}, {String("hello, world!"), token{String: "hello, world!", Kind: '"'}}, {rawToken(`"hello, world!"`), token{String: "hello, world!", Kind: '"'}}, @@ -138,13 +138,13 @@ func TestTokenClone(t *testing.T) { wantExactRaw bool }{ {Token{}, true}, - {Null, true}, - {False, true}, - {True, true}, - {ObjectStart, true}, - {ObjectEnd, true}, - {ArrayStart, true}, - {ArrayEnd, true}, + {Null(), true}, + {Bool(false), true}, + {Bool(true), true}, + {ObjectStart(), true}, + {ObjectEnd(), true}, + {ArrayStart(), true}, + {ArrayEnd(), true}, {String("hello, world!"), true}, {rawToken(`"hello, world!"`), false}, {Float(3.14159), true},