string_test.go 1003 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package stringx
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestString_IsEmptyOrSpace(t *testing.T) {
  7. ret := From(" ").IsEmptyOrSpace()
  8. assert.Equal(t, true, ret)
  9. ret2 := From("ll??").IsEmptyOrSpace()
  10. assert.Equal(t, false, ret2)
  11. ret3 := From(`
  12. `).IsEmptyOrSpace()
  13. assert.Equal(t, true, ret3)
  14. }
  15. func TestString_Snake2Camel(t *testing.T) {
  16. ret := From("____this_is_snake").ToCamel()
  17. assert.Equal(t, "ThisIsSnake", ret)
  18. ret2 := From("测试_test_Data").ToCamel()
  19. assert.Equal(t, "测试TestData", ret2)
  20. ret3 := From("___").ToCamel()
  21. assert.Equal(t, "", ret3)
  22. ret4 := From("testData_").ToCamel()
  23. assert.Equal(t, "TestData", ret4)
  24. ret5 := From("testDataTestData").ToCamel()
  25. assert.Equal(t, "TestDataTestData", ret5)
  26. }
  27. func TestString_Camel2Snake(t *testing.T) {
  28. ret := From("ThisIsCCCamel").ToSnake()
  29. assert.Equal(t, "this_is_c_c_camel", ret)
  30. ret2 := From("测试Test_Data_test_data").ToSnake()
  31. assert.Equal(t, "测试_test__data_test_data", ret2)
  32. }