reply_test.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package service
  2. import (
  3. "context"
  4. "testing"
  5. . "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestFilterViolationMsg(t *testing.T) {
  8. Convey("TestFilterViolationMsg", t, func() {
  9. res := filterViolationMsg("123456789评论过虑违规内容评论过虑违规内容")
  10. t.Log(res)
  11. })
  12. }
  13. func TestTopicReg(t *testing.T) {
  14. s := Service{}
  15. c := context.Background()
  16. Convey("TestAtReg", t, func() {
  17. topics := s.regTopic(c, "#你懂 得##222#")
  18. So(len(topics), ShouldEqual, 2)
  19. So(topics[0], ShouldEqual, "你懂 得")
  20. So(topics[1], ShouldEqual, "222")
  21. topics = s.regTopic(c, "#你懂 \n得##22@有人艾特2#")
  22. So(len(topics), ShouldEqual, 0)
  23. topics = s.regTopic(c, "#你懂 \n得#哈哈哈#22@有人艾特2#")
  24. So(len(topics), ShouldEqual, 1)
  25. So(topics[0], ShouldEqual, "哈哈哈")
  26. topics = s.regTopic(c, "# ## ##你懂得")
  27. So(len(topics), ShouldEqual, 0)
  28. topics = s.regTopic(c, "热热# ##!%……&()()*()*()&*……&……%……¥%##同一套##协助特大号哈哈哈嘎嘎协助特大号哈哈哈嘎嘎协助特大号哈哈哈ee120##协助特大号哈哈哈嘎嘎协助特大号哈哈哈嘎嘎协助特大号哈哈哈ee12##@1r##tet##899##5677#")
  29. So(len(topics), ShouldEqual, 5)
  30. topics = s.regTopic(c, "#我是大佬你是谁你是大佬嘛哈哈啊#123#")
  31. So(len(topics), ShouldEqual, 1)
  32. topics = s.regTopic(c, "#2😁3#123#3😁3##2😁3#")
  33. So(len(topics), ShouldEqual, 1)
  34. So(topics[0], ShouldEqual, "123")
  35. topics = s.regTopic(c, " http://t.bilibili.com/av111111#reply#haha #didi")
  36. So(len(topics), ShouldEqual, 0)
  37. topics = s.regTopic(c, " http://t.bilibili.com/av111111#reply#haha #didi# http://t.baidu.com/av111111#reply#haha")
  38. So(len(topics), ShouldEqual, 2)
  39. So(topics[0], ShouldEqual, "didi")
  40. So(topics[1], ShouldEqual, "reply")
  41. topics = s.regTopic(c, "asdasd#av1000#33333#vc11111#44444#cv1111#55555#")
  42. So(len(topics), ShouldEqual, 3)
  43. })
  44. }
  45. func TestAtReg(t *testing.T) {
  46. Convey("TestAtReg", t, func() {
  47. ss := _atReg.FindAllStringSubmatch("@aa:hh@bb,cc", 10)
  48. So(len(ss), ShouldEqual, 2)
  49. So(ss[0][1], ShouldEqual, "aa")
  50. So(ss[1][1], ShouldEqual, "bb")
  51. ss = _atReg.FindAllStringSubmatch("@aa@bb", 10)
  52. So(len(ss), ShouldEqual, 2)
  53. So(ss[0][1], ShouldEqual, "aa")
  54. So(ss[1][1], ShouldEqual, "bb")
  55. ss = _atReg.FindAllStringSubmatch("@aa @bb", 10)
  56. So(len(ss), ShouldEqual, 2)
  57. So(ss[0][1], ShouldEqual, "aa")
  58. So(ss[1][1], ShouldEqual, "bb")
  59. ss = _atReg.FindAllStringSubmatch("@aa bb@cc;@dd:sa", 10)
  60. So(len(ss), ShouldEqual, 3)
  61. So(ss[0][1], ShouldEqual, "aa")
  62. So(ss[1][1], ShouldEqual, "cc;")
  63. So(ss[2][1], ShouldEqual, "dd")
  64. })
  65. }