gitea源码

footnote_test.go 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package common
  4. import (
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestCleanValue(t *testing.T) {
  9. tests := []struct {
  10. param string
  11. expect string
  12. }{
  13. // Github behavior test cases
  14. {"", ""},
  15. {"test(0)", "test0"},
  16. {"test!1", "test1"},
  17. {"test:2", "test2"},
  18. {"test*3", "test3"},
  19. {"test!4", "test4"},
  20. {"test:5", "test5"},
  21. {"test*6", "test6"},
  22. {"test:6 a", "test6-a"},
  23. {"test:6 !b", "test6-b"},
  24. {"test:ad # df", "testad--df"},
  25. {"test:ad #23 df 2*/*", "testad-23-df-2"},
  26. {"test:ad 23 df 2*/*", "testad-23-df-2"},
  27. {"test:ad # 23 df 2*/*", "testad--23-df-2"},
  28. {"Anchors in Markdown", "anchors-in-markdown"},
  29. {"a_b_c", "a_b_c"},
  30. {"a-b-c", "a-b-c"},
  31. {"a-b-c----", "a-b-c----"},
  32. {"test:6a", "test6a"},
  33. {"test:a6", "testa6"},
  34. {"tes a a a a", "tes-a-a---a--a"},
  35. {" tes a a a a ", "tes-a-a---a--a"},
  36. {"Header with \"double quotes\"", "header-with-double-quotes"},
  37. {"Placeholder to force scrolling on link's click", "placeholder-to-force-scrolling-on-links-click"},
  38. {"tes()", "tes"},
  39. {"tes(0)", "tes0"},
  40. {"tes{0}", "tes0"},
  41. {"tes[0]", "tes0"},
  42. {"test【0】", "test0"},
  43. {"tes…@a", "tesa"},
  44. {"tes¥& a", "tes-a"},
  45. {"tes= a", "tes-a"},
  46. {"tes|a", "tesa"},
  47. {"tes\\a", "tesa"},
  48. {"tes/a", "tesa"},
  49. {"a啊啊b", "a啊啊b"},
  50. {"c🤔️🤔️d", "cd"},
  51. {"a⚡a", "aa"},
  52. {"e.~f", "ef"},
  53. }
  54. for _, test := range tests {
  55. assert.Equal(t, []byte(test.expect), CleanValue([]byte(test.param)), test.param)
  56. }
  57. }