summaryrefslogtreecommitdiffstats
path: root/parser/lowercase_camel_json_test.go
blob: ffbc8029522e32aca507e48b41331e2542926c37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package parser

import (
	"testing"

	qt "github.com/frankban/quicktest"
)

func TestReplacingJSONMarshaller(t *testing.T) {
	c := qt.New(t)

	m := map[string]any{
		"foo":        "bar",
		"baz":        42,
		"zeroInt1":   0,
		"zeroInt2":   0,
		"zeroFloat":  0.0,
		"zeroString": "",
		"zeroBool":   false,
		"nil":        nil,
	}

	marshaller := ReplacingJSONMarshaller{
		Value:       m,
		KeysToLower: true,
		OmitEmpty:   true,
	}

	b, err := marshaller.MarshalJSON()
	c.Assert(err, qt.IsNil)

	c.Assert(string(b), qt.Equals, `{"baz":42,"foo":"bar"}`)
}