naming_strategy_test.go 536 B

1234567891011121314151617181920212223
  1. package extra
  2. import (
  3. "testing"
  4. "github.com/json-iterator/go"
  5. "github.com/json-iterator/go/require"
  6. )
  7. func Test_lower_case_with_underscores(t *testing.T) {
  8. should := require.New(t)
  9. should.Equal("hello_world", LowerCaseWithUnderscores("helloWorld"))
  10. should.Equal("hello_world", LowerCaseWithUnderscores("HelloWorld"))
  11. SetNamingStrategy(LowerCaseWithUnderscores)
  12. output, err := jsoniter.MarshalToString(struct {
  13. HelloWorld string
  14. }{
  15. HelloWorld: "hi",
  16. })
  17. should.Nil(err)
  18. should.Equal(`{"hello_world":"hi"}`, output)
  19. }