You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

string_test.go 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2022 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package util
  4. import (
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestToSnakeCase(t *testing.T) {
  9. cases := map[string]string{
  10. // all old cases from the legacy package
  11. "HTTPServer": "http_server",
  12. "_camelCase": "_camel_case",
  13. "NoHTTPS": "no_https",
  14. "Wi_thF": "wi_th_f",
  15. "_AnotherTES_TCaseP": "_another_tes_t_case_p",
  16. "ALL": "all",
  17. "_HELLO_WORLD_": "_hello_world_",
  18. "HELLO_WORLD": "hello_world",
  19. "HELLO____WORLD": "hello____world",
  20. "TW": "tw",
  21. "_C": "_c",
  22. " sentence case ": "__sentence_case__",
  23. " Mixed-hyphen case _and SENTENCE_case and UPPER-case": "_mixed_hyphen_case__and_sentence_case_and_upper_case",
  24. // new cases
  25. " ": "_",
  26. "A": "a",
  27. "A0": "a0",
  28. "a0": "a0",
  29. "Aa0": "aa0",
  30. "啊": "啊",
  31. "A啊": "a啊",
  32. "Aa啊b": "aa啊b",
  33. "A啊B": "a啊_b",
  34. "Aa啊B": "aa啊_b",
  35. "TheCase2": "the_case2",
  36. "ObjIDs": "obj_i_ds", // the strange database column name which already exists
  37. }
  38. for input, expected := range cases {
  39. assert.Equal(t, expected, ToSnakeCase(input))
  40. }
  41. }