naming_strategy_test.go 624 B

1234567891011121314151617181920212223
  1. package extra
  2. import (
  3. "github.com/json-iterator/go"
  4. "github.com/json-iterator/go/require"
  5. "testing"
  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.Marshal(struct {
  13. UserName string
  14. FirstLanguage string
  15. }{
  16. UserName: "taowen",
  17. FirstLanguage: "Chinese",
  18. })
  19. should.Nil(err)
  20. should.Equal(`{"user_name":"taowen","first_language":"Chinese"}`, string(output))
  21. }