mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
fixed tests for semantic errors
This commit is contained in:
@@ -98,9 +98,9 @@ func TestNumber(t *testing.T) {
|
||||
if err == nil && len(l.SemanticErrors) != 0 {
|
||||
err = l.SemanticErrors[0]
|
||||
}
|
||||
if err != nil && !test.wantError {
|
||||
if (err != nil || (len(l.SemanticErrors) != 0 && *UseSemanticErrors)) && !test.wantError {
|
||||
t.Errorf("[%d, %q] number() error: %v", i, test.toParse, err)
|
||||
} else if err == nil && test.wantError {
|
||||
} else if (err == nil || (len(l.SemanticErrors) == 0 && *UseSemanticErrors)) && test.wantError {
|
||||
t.Errorf("[%d, %q] number() ok; want error", i, test.toParse)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/mailru/easyjson"
|
||||
"github.com/mailru/easyjson/jlexer"
|
||||
"github.com/mailru/easyjson/jwriter"
|
||||
)
|
||||
|
||||
@@ -207,40 +206,3 @@ func TestNestedEasyJsonMarshal(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSemanticErrors(t *testing.T) {
|
||||
if !*jlexer.UseSemanticErrors {
|
||||
return
|
||||
}
|
||||
for i, test := range []struct {
|
||||
Data []byte
|
||||
ErrorNum int
|
||||
}{
|
||||
{
|
||||
Data: []byte(`[1, 2, 3, "4", "5"]`),
|
||||
ErrorNum: 2,
|
||||
},
|
||||
{
|
||||
Data: []byte(`[1, {"2" : "3"}, 3, "4"`),
|
||||
ErrorNum: 2,
|
||||
},
|
||||
{
|
||||
Data: []byte(`[1, "2", "3", "4", "5", "6"]`),
|
||||
ErrorNum: 5,
|
||||
},
|
||||
{
|
||||
Data: []byte(`[1, 2, 3, 4, "5"]`),
|
||||
ErrorNum: 1,
|
||||
},
|
||||
} {
|
||||
l := jlexer.Lexer{Data: test.Data}
|
||||
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,3 +2,9 @@ package tests
|
||||
|
||||
//easyjson:json
|
||||
type ErrorIntSlice []int
|
||||
|
||||
//easyjson:json
|
||||
type ErrorBoolSlice []bool
|
||||
|
||||
//easyjson:json
|
||||
type ErrorUintSlice []uint
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mailru/easyjson/jlexer"
|
||||
)
|
||||
|
||||
func TestSemanticErrorsInt(t *testing.T) {
|
||||
if !*jlexer.UseSemanticErrors {
|
||||
return
|
||||
}
|
||||
for i, test := range []struct {
|
||||
Data []byte
|
||||
ErrorNum int
|
||||
}{
|
||||
{
|
||||
Data: []byte(`[1, 2, 3, "4", "5"]`),
|
||||
ErrorNum: 2,
|
||||
},
|
||||
{
|
||||
Data: []byte(`[1, {"2" : "3"}, 3, "4"`),
|
||||
ErrorNum: 2,
|
||||
},
|
||||
{
|
||||
Data: []byte(`[1, "2", "3", "4", "5", "6"]`),
|
||||
ErrorNum: 5,
|
||||
},
|
||||
{
|
||||
Data: []byte(`[1, 2, 3, 4, "5"]`),
|
||||
ErrorNum: 1,
|
||||
},
|
||||
} {
|
||||
l := jlexer.Lexer{Data: test.Data}
|
||||
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user