tag_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package server
  2. import (
  3. "testing"
  4. )
  5. func TestFindTagListFromMemoContent(t *testing.T) {
  6. tests := []struct {
  7. memoContent string
  8. want []string
  9. }{
  10. {
  11. memoContent: "#tag1 ",
  12. want: []string{"tag1"},
  13. },
  14. {
  15. memoContent: "#tag1 #tag2 ",
  16. want: []string{"tag1", "tag2"},
  17. },
  18. {
  19. memoContent: "#tag1 #tag2 \n#tag3 ",
  20. want: []string{"tag1", "tag2", "tag3"},
  21. },
  22. {
  23. memoContent: "#tag1 #tag2 \n#tag3 #tag4 ",
  24. want: []string{"tag1", "tag2", "tag3", "tag4"},
  25. },
  26. {
  27. memoContent: "#tag1 #tag2 \n#tag3 #tag4 ",
  28. want: []string{"tag1", "tag2", "tag3", "tag4"},
  29. },
  30. {
  31. memoContent: "#tag1 123123#tag2 \n#tag3 #tag4 ",
  32. want: []string{"tag1", "tag2", "tag3", "tag4"},
  33. },
  34. {
  35. memoContent: "#tag1 http://123123.com?123123#tag2 \n#tag3 #tag4 http://123123.com?123123#tag2) ",
  36. want: []string{"tag1", "tag2", "tag2)", "tag3", "tag4"},
  37. },
  38. }
  39. for _, test := range tests {
  40. result := findTagListFromMemoContent(test.memoContent)
  41. if len(result) != len(test.want) {
  42. t.Errorf("Find tag list %s: got result %v, want %v.", test.memoContent, result, test.want)
  43. }
  44. }
  45. }