Skip to content

Commit

Permalink
Test Bool#MarshalJSON()
Browse files Browse the repository at this point in the history
  • Loading branch information
Al2Klimov committed Jul 7, 2023
1 parent 0745ba7 commit 7568c47
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pkg/types/bool_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package types

import (
"fmt"
"github.com/stretchr/testify/require"
"testing"
"unicode/utf8"
)

func TestBool_MarshalJSON(t *testing.T) {
subtests := []struct {
input Bool
output string
}{
{Bool{Bool: false, Valid: false}, `null`},
{Bool{Bool: false, Valid: true}, `false`},
{Bool{Bool: true, Valid: false}, `null`},
{Bool{Bool: true, Valid: true}, `true`},
}

for _, st := range subtests {
t.Run(fmt.Sprintf("Bool-%#v_Valid-%#v", st.input.Bool, st.input.Valid), func(t *testing.T) {
actual, err := st.input.MarshalJSON()

require.NoError(t, err)
require.True(t, utf8.Valid(actual))
require.Equal(t, st.output, string(actual))
})
}
}

0 comments on commit 7568c47

Please sign in to comment.