1
0
mirror of https://github.com/json-iterator/go.git synced 2025-02-01 19:14:29 +02:00
json-iterator/extra/naming_strategy_test.go

24 lines
624 B
Go
Raw Normal View History

2017-06-20 23:09:53 +08:00
package extra
import (
"github.com/json-iterator/go"
"github.com/stretchr/testify/require"
2017-06-21 00:26:18 +08:00
"testing"
2017-06-20 23:09:53 +08:00
)
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)
2017-06-20 23:48:41 +08:00
output, err := jsoniter.Marshal(struct {
UserName string
FirstLanguage string
2017-06-20 23:09:53 +08:00
}{
2017-06-20 23:48:41 +08:00
UserName: "taowen",
FirstLanguage: "Chinese",
2017-06-20 23:09:53 +08:00
})
should.Nil(err)
2017-06-20 23:48:41 +08:00
should.Equal(`{"user_name":"taowen","first_language":"Chinese"}`, string(output))
2017-06-20 23:09:53 +08:00
}