mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
Added tests for bool & uint
This commit is contained in:
@@ -42,3 +42,66 @@ func TestSemanticErrorsInt(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSemanticErrorsBool(t *testing.T) {
|
||||
if !*jlexer.UseSemanticErrors {
|
||||
return
|
||||
}
|
||||
for i, test := range []struct {
|
||||
Data []byte
|
||||
ErrorNum int
|
||||
}{
|
||||
{
|
||||
Data: []byte(`[true, false, true, false]`),
|
||||
},
|
||||
{
|
||||
Data: []byte(`["test", "value", "lol", "1"]`),
|
||||
ErrorNum: 4,
|
||||
},
|
||||
{
|
||||
Data: []byte(`[true, 42, {"a":"b", "c":"d"}, false`),
|
||||
ErrorNum: 2,
|
||||
},
|
||||
} {
|
||||
l := jlexer.Lexer{Data: test.Data}
|
||||
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSemanticErrorsUint(t *testing.T) {
|
||||
if !*jlexer.UseSemanticErrors {
|
||||
return
|
||||
}
|
||||
|
||||
for i, test := range []struct {
|
||||
Data []byte
|
||||
ErrorNum int
|
||||
}{
|
||||
{
|
||||
Data: []byte(`[42, 42, 42]`),
|
||||
},
|
||||
{
|
||||
Data: []byte(`[17, "42", 32]`),
|
||||
ErrorNum: 1,
|
||||
},
|
||||
{
|
||||
Data: []byte(`["zz", "zz"]`),
|
||||
ErrorNum: 2,
|
||||
},
|
||||
} {
|
||||
l := jlexer.Lexer{Data: test.Data}
|
||||
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user