diff --git a/optional_marshaljson_bool_test.go b/optional_marshaljson_bool_test.go index 18a88dd..dfaa32e 100644 --- a/optional_marshaljson_bool_test.go +++ b/optional_marshaljson_bool_test.go @@ -44,3 +44,22 @@ func TestOptional_MarshalJSON_bool(t *testing.T) { } } } + +func TestOptional_MarshalJSON_bool_fail(t *testing.T) { + + var nothing opt.Optional[bool] + + actualBytes, err := nothing.MarshalJSON() + if nil == err { + t.Error("Expected an error but did not actually get one.") + t.Logf("ACTUAL: %q", actualBytes) + t.Logf("ERROR: (%T) %s", err, err) + return + } + if nil != actualBytes { + t.Error("Expected not bytes but actually get some.") + t.Logf("ACTUAL: %q", actualBytes) + t.Logf("ERROR: (%T) %s", err, err) + return + } +} diff --git a/optional_marshaljson_string_test.go b/optional_marshaljson_string_test.go index b33a837..eff2ec8 100644 --- a/optional_marshaljson_string_test.go +++ b/optional_marshaljson_string_test.go @@ -103,3 +103,22 @@ func TestOptional_MarshalJSON_string(t *testing.T) { } } } + +func TestOptional_MarshalJSON_string_fail(t *testing.T) { + + var nothing opt.Optional[string] + + actualBytes, err := nothing.MarshalJSON() + if nil == err { + t.Error("Expected an error but did not actually get one.") + t.Logf("ACTUAL: %q", actualBytes) + t.Logf("ERROR: (%T) %s", err, err) + return + } + if nil != actualBytes { + t.Error("Expected not bytes but actually get some.") + t.Logf("ACTUAL: %q", actualBytes) + t.Logf("ERROR: (%T) %s", err, err) + return + } +}