diff --git a/tests/errors_test.go b/tests/errors_test.go index a434f65..af27396 100644 --- a/tests/errors_test.go +++ b/tests/errors_test.go @@ -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)) + } + } +}