mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
Fixed copypaste and comments from github
This commit is contained in:
@@ -118,6 +118,7 @@ func (g *Generator) genTypeDecoderNoCheck(t reflect.Type, out string, tags field
|
||||
|
||||
fmt.Fprintln(g.out, ws+" "+out+" = append("+out+", "+tmpVar+")")
|
||||
fmt.Fprintln(g.out, ws+" in.WantComma()")
|
||||
fmt.Fprintln(g.out, ws+" in.ConsumeSemantic()")
|
||||
fmt.Fprintln(g.out, ws+" }")
|
||||
fmt.Fprintln(g.out, ws+" in.Delim(']')")
|
||||
fmt.Fprintln(g.out, ws+"}")
|
||||
@@ -409,6 +410,7 @@ func (g *Generator) genStructDecoder(t reflect.Type) error {
|
||||
fmt.Fprintln(g.out, " default:")
|
||||
fmt.Fprintln(g.out, " in.SkipRecursive()")
|
||||
fmt.Fprintln(g.out, " }")
|
||||
fmt.Fprintln(g.out, " in.ConsumeSemantic()")
|
||||
fmt.Fprintln(g.out, " in.WantComma()")
|
||||
fmt.Fprintln(g.out, " }")
|
||||
fmt.Fprintln(g.out, " in.Delim('}')")
|
||||
|
||||
+100
-164
File diff suppressed because it is too large
Load Diff
@@ -82,7 +82,7 @@ func TestNumber(t *testing.T) {
|
||||
{toParse: "12.35E-15", want: "12.35E-15"},
|
||||
{toParse: "12.35E15", want: "12.35E15"},
|
||||
|
||||
// {toParse: `"a"`, wantError: true}, // FIXME(shmel1k): disable UseSemanticErrors for tests.
|
||||
{toParse: `"a"`, wantError: true},
|
||||
{toParse: "123junk", wantError: true},
|
||||
{toParse: "1.2.3", wantError: true},
|
||||
{toParse: "1e2e3", wantError: true},
|
||||
@@ -95,9 +95,6 @@ func TestNumber(t *testing.T) {
|
||||
t.Errorf("[%d, %q] number() = %v; want %v", i, test.toParse, got, test.want)
|
||||
}
|
||||
err := l.Error()
|
||||
if err == nil && len(l.SemanticErrors) != 0 {
|
||||
err = l.SemanticErrors[0]
|
||||
}
|
||||
if err != nil && !test.wantError {
|
||||
t.Errorf("[%d, %q] number() error: %v", i, test.toParse, err)
|
||||
} else if err == nil && test.wantError {
|
||||
@@ -128,9 +125,6 @@ func TestBool(t *testing.T) {
|
||||
t.Errorf("[%d, %q] Bool() = %v; want %v", i, test.toParse, got, test.want)
|
||||
}
|
||||
err := l.Error()
|
||||
if err == nil && len(l.SemanticErrors) != 0 {
|
||||
err = l.SemanticErrors[0]
|
||||
}
|
||||
if err != nil && !test.wantError {
|
||||
t.Errorf("[%d, %q] Bool() error: %v", i, test.toParse, err)
|
||||
} else if err == nil && test.wantError {
|
||||
|
||||
@@ -8,3 +8,16 @@ type ErrorBoolSlice []bool
|
||||
|
||||
//easyjson:json
|
||||
type ErrorUintSlice []uint
|
||||
|
||||
//easyjson:json
|
||||
type ErrorStruct struct {
|
||||
Int int `json:"int"`
|
||||
String string `json:"string"`
|
||||
Slice []int `json:"slice"`
|
||||
IntSlice []int `json:"int_slice"`
|
||||
}
|
||||
|
||||
type ErrorNestedStruct struct {
|
||||
ErrorStruct ErrorStruct `json:"error_struct"`
|
||||
Int int `json:"int"`
|
||||
}
|
||||
|
||||
+119
-21
@@ -7,9 +7,6 @@ import (
|
||||
)
|
||||
|
||||
func TestSemanticErrorsInt(t *testing.T) {
|
||||
if !*jlexer.UseSemanticErrors {
|
||||
return
|
||||
}
|
||||
for i, test := range []struct {
|
||||
Data []byte
|
||||
ErrorNum int
|
||||
@@ -19,7 +16,7 @@ func TestSemanticErrorsInt(t *testing.T) {
|
||||
ErrorNum: 2,
|
||||
},
|
||||
{
|
||||
Data: []byte(`[1, {"2" : "3"}, 3, "4"`),
|
||||
Data: []byte(`[1, {"2":"3"}, 3, "4"]`),
|
||||
ErrorNum: 2,
|
||||
},
|
||||
{
|
||||
@@ -30,23 +27,29 @@ func TestSemanticErrorsInt(t *testing.T) {
|
||||
Data: []byte(`[1, 2, 3, 4, "5"]`),
|
||||
ErrorNum: 1,
|
||||
},
|
||||
{
|
||||
Data: []byte(`[{"1": "2"}]`),
|
||||
ErrorNum: 1,
|
||||
},
|
||||
} {
|
||||
l := jlexer.Lexer{Data: test.Data}
|
||||
l := jlexer.Lexer{
|
||||
Data: test.Data,
|
||||
UseMultipleErrors: true,
|
||||
}
|
||||
|
||||
var v ErrorIntSlice
|
||||
|
||||
v.UnmarshalEasyJSON(&l)
|
||||
|
||||
if len(l.SemanticErrors) != test.ErrorNum {
|
||||
t.Errorf("[%d] TestSemanticErrors(): errornum: want: %d, got %d", i, test.ErrorNum, len(l.SemanticErrors))
|
||||
if len(l.GetSemanticErrors()) != test.ErrorNum {
|
||||
t.Errorf("[%d] TestSemanticErrorsInt(): errornum: want: %d, got %d", i, test.ErrorNum, len(l.GetSemanticErrors()))
|
||||
t.Errorf("%v", l.GetSemanticErrors())
|
||||
t.Errorf("%v", l.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSemanticErrorsBool(t *testing.T) {
|
||||
if !*jlexer.UseSemanticErrors {
|
||||
return
|
||||
}
|
||||
for i, test := range []struct {
|
||||
Data []byte
|
||||
ErrorNum int
|
||||
@@ -59,26 +62,26 @@ func TestSemanticErrorsBool(t *testing.T) {
|
||||
ErrorNum: 4,
|
||||
},
|
||||
{
|
||||
Data: []byte(`[true, 42, {"a":"b", "c":"d"}, false`),
|
||||
Data: []byte(`[true, 42, {"a":"b", "c":"d"}, false]`),
|
||||
ErrorNum: 2,
|
||||
},
|
||||
} {
|
||||
l := jlexer.Lexer{Data: test.Data}
|
||||
l := jlexer.Lexer{
|
||||
Data: test.Data,
|
||||
UseMultipleErrors: true,
|
||||
}
|
||||
|
||||
var v ErrorBoolSlice
|
||||
v.UnmarshalEasyJSON(&l)
|
||||
|
||||
if len(l.SemanticErrors) != test.ErrorNum {
|
||||
t.Errorf("[%d] TestSemanticErrors(): errornum: want: %d, got %d", i, test.ErrorNum, len(l.SemanticErrors))
|
||||
if len(l.GetSemanticErrors()) != test.ErrorNum {
|
||||
t.Errorf("[%d] TestSemanticErrorsBool(): errornum: want: %d, got %d", i, test.ErrorNum, len(l.GetSemanticErrors()))
|
||||
t.Errorf("%v", l.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSemanticErrorsUint(t *testing.T) {
|
||||
if !*jlexer.UseSemanticErrors {
|
||||
return
|
||||
}
|
||||
|
||||
for i, test := range []struct {
|
||||
Data []byte
|
||||
ErrorNum int
|
||||
@@ -94,14 +97,109 @@ func TestSemanticErrorsUint(t *testing.T) {
|
||||
Data: []byte(`["zz", "zz"]`),
|
||||
ErrorNum: 2,
|
||||
},
|
||||
{
|
||||
Data: []byte(`[{}, 42]`),
|
||||
ErrorNum: 1,
|
||||
},
|
||||
} {
|
||||
l := jlexer.Lexer{Data: test.Data}
|
||||
l := jlexer.Lexer{
|
||||
Data: test.Data,
|
||||
UseMultipleErrors: true,
|
||||
}
|
||||
|
||||
var v ErrorUintSlice
|
||||
v.UnmarshalEasyJSON(&l)
|
||||
|
||||
if len(l.SemanticErrors) != test.ErrorNum {
|
||||
t.Errorf("[%d] TestSemanticErrors(): errornum: want: %d, got %d", i, test.ErrorNum, len(l.SemanticErrors))
|
||||
if len(l.GetSemanticErrors()) != test.ErrorNum {
|
||||
t.Errorf("[%d] TestSemanticErrorsUint(): errornum: want: %d, got %d", i, test.ErrorNum, len(l.GetSemanticErrors()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSemanticErrorsStruct(t *testing.T) {
|
||||
for i, test := range []struct {
|
||||
Data []byte
|
||||
ErrorNum int
|
||||
}{
|
||||
{
|
||||
Data: []byte(`{"string": "test", "slice":[42, 42, 42], "int_slice":[1, 2, 3]}`),
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"string": {"test": "test"}, "slice":[42, 42, 42], "int_slice":["1", 2, 3]}`),
|
||||
ErrorNum: 2,
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"slice": [42, 42], "string": {"test": "test"}, "int_slice":["1", "2", 3]}`),
|
||||
ErrorNum: 3,
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"string": "test", "slice": {}}`),
|
||||
ErrorNum: 1,
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"slice":5, "string" : "test"}`),
|
||||
ErrorNum: 1,
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"slice" : "test", "string" : "test"}`),
|
||||
ErrorNum: 1,
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"slice": "", "string" : {}, "int":{}}`),
|
||||
ErrorNum: 3,
|
||||
},
|
||||
} {
|
||||
l := jlexer.Lexer{
|
||||
Data: test.Data,
|
||||
UseMultipleErrors: true,
|
||||
}
|
||||
var v ErrorStruct
|
||||
v.UnmarshalEasyJSON(&l)
|
||||
|
||||
if len(l.GetSemanticErrors()) != test.ErrorNum {
|
||||
t.Errorf("[%d] TestSemanticErrorsStruct(): errornum: want: %d, got %d", i, test.ErrorNum, len(l.GetSemanticErrors()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSemanticErrorsNestedStruct(t *testing.T) {
|
||||
for i, test := range []struct {
|
||||
Data []byte
|
||||
ErrorNum int
|
||||
}{
|
||||
{
|
||||
Data: []byte(`{"error_struct":{}}`),
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"error_struct":5}`),
|
||||
ErrorNum: 1,
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"error_struct":[]}`),
|
||||
ErrorNum: 1,
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"error_struct":{"int":{}}}`),
|
||||
ErrorNum: 1,
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"error_struct":{"int_slice":{}}, "int":4}`),
|
||||
ErrorNum: 1,
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"error_struct":{"int_slice":["1", 2, "3"]}, "int":[]}`),
|
||||
ErrorNum: 3,
|
||||
},
|
||||
} {
|
||||
l := jlexer.Lexer{
|
||||
Data: test.Data,
|
||||
UseMultipleErrors: true,
|
||||
}
|
||||
var v ErrorNestedStruct
|
||||
v.UnmarshalEasyJSON(&l)
|
||||
|
||||
if len(l.GetSemanticErrors()) != test.ErrorNum {
|
||||
t.Errorf("[%d] TestSemanticErrorsNestedStruct(): errornum: want: %d, got %d", i, test.ErrorNum, len(l.GetSemanticErrors()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user