[Tests] add tests for disallow_unknown_fields

This commit is contained in:
Aleksandr Petrukhin
2018-05-29 16:32:28 +00:00
parent c63cf99c78
commit 31e0226908
5 changed files with 20 additions and 0 deletions
+1
View File
@@ -2,3 +2,4 @@
*_easyjson.go
*.iml
.idea
*.swp
+1
View File
@@ -37,6 +37,7 @@ generate: root build
.root/bin/easyjson .root/src/$(PKG)/tests/named_type.go
.root/bin/easyjson .root/src/$(PKG)/tests/custom_map_key_type.go
.root/bin/easyjson .root/src/$(PKG)/tests/embedded_type.go
.root/bin/easyjson -disallow_unknown_fields .root/src/$(PKG)/tests/disallow_unknown.go
test: generate root
go test \
+2
View File
@@ -53,6 +53,8 @@ Usage of easyjson:
use lowerCamelCase instead of CamelCase by default
-stubs
only generate stubs for marshaler/unmarshaler funcs
-disallow_unknown_fields
return error if some unknown field in json occured
```
Using `-all` will generate marshalers/unmarshalers for all Go structs in the
+8
View File
@@ -232,3 +232,11 @@ func TestUnmarshalStructWithEmbeddedPtrStruct(t *testing.T) {
t.Errorf("easyjson.Unmarshal() = %#v; want %#v", s, structWithInterfaceValueFilled)
}
}
func TestDisallowUnknown(t *testing.T) {
var d DisallowUnknown
err := easyjson.Unmarshal([]byte(disallowUnknownString), &d)
if err == nil {
t.Error("want error, got nil")
}
}
+8
View File
@@ -0,0 +1,8 @@
package tests
//easyjson:json
type DisallowUnknown struct {
FieldOne string `json:"field_one"`
}
var disallowUnknownString = `{"field_one": "one", "field_two": "two"}`