1
0
mirror of https://github.com/json-iterator/go.git synced 2025-02-07 19:30:06 +02:00
json-iterator/extra/naming_strategy_test.go

24 lines
536 B
Go
Raw Normal View History

2017-06-20 23:09:53 +08:00
package extra
import (
"testing"
"github.com/json-iterator/go"
"github.com/json-iterator/go/require"
)
func Test_lower_case_with_underscores(t *testing.T) {
should := require.New(t)
should.Equal("hello_world", LowerCaseWithUnderscores("helloWorld"))
should.Equal("hello_world", LowerCaseWithUnderscores("HelloWorld"))
SetNamingStrategy(LowerCaseWithUnderscores)
output, err := jsoniter.MarshalToString(struct {
HelloWorld string
}{
HelloWorld: "hi",
})
should.Nil(err)
should.Equal(`{"hello_world":"hi"}`, output)
}