mirror of
https://github.com/wneessen/niljson.git
synced 2024-11-23 06:00:49 +01:00
Add test for omitted field
Introduce a new test, `TestVariable_Omitted`, to verify the behavior of the `NilBoolean` type fields, ensuring the correct handling of omitted and non-omitted fields during JSON unmarshalling.
This commit is contained in:
parent
7f2cf28053
commit
754b2b90aa
1 changed files with 22 additions and 0 deletions
|
@ -602,6 +602,28 @@ func TestVariable_MarshalJSON_UInt64(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestVariable_Omitted(t *testing.T) {
|
||||||
|
type JSONType struct {
|
||||||
|
NilValue NilBoolean `json:"nilvalue"`
|
||||||
|
Omitted NilBoolean `json:"omitted,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var jt JSONType
|
||||||
|
if err := json.Unmarshal(jsonBytes, &jt); err != nil {
|
||||||
|
t.Errorf(ErrUnmarshalFailed, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if jt.NilValue.NotNil() {
|
||||||
|
t.Error(ErrExpectedNil)
|
||||||
|
}
|
||||||
|
if jt.NilValue.Omitted() {
|
||||||
|
t.Error("expected nil value to be not omitted")
|
||||||
|
}
|
||||||
|
if !jt.Omitted.Omitted() {
|
||||||
|
t.Error("expected omitted value to be omitted")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ExampleVariable_UnmarshalJSON() {
|
func ExampleVariable_UnmarshalJSON() {
|
||||||
type JSONType struct {
|
type JSONType struct {
|
||||||
Bool NilBoolean `json:"bool"`
|
Bool NilBoolean `json:"bool"`
|
||||||
|
|
Loading…
Reference in a new issue