6
0

code_style_test.go 659 B

1234567891011121314151617181920212223242526272829303132
  1. package common
  2. import "testing"
  3. func TestSnake2Orm(t *testing.T) {
  4. type A struct {
  5. Id int `json:"id" orm:"EntityId"`
  6. Name string `json:"name" orm:"Name"`
  7. Age int
  8. }
  9. type args struct {
  10. entity interface{}
  11. field string
  12. }
  13. tests := []struct {
  14. name string
  15. args args
  16. want string
  17. }{
  18. {"struct 类型测试", args{entity: A{}, field: "id"}, "EntityId"},
  19. {"ptr 类型测试", args{entity: &A{}, field: "id"}, "EntityId"},
  20. }
  21. for _, tt := range tests {
  22. t.Run(tt.name, func(t *testing.T) {
  23. if got := Snake2Orm(tt.args.entity, tt.args.field); got != tt.want {
  24. t.Errorf("Snake2Orm() = %v, want %v", got, tt.want)
  25. }
  26. })
  27. }
  28. }