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.

client_test.go 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright (c) 2019 Shivaram Lingamneni
  2. // released under the MIT license
  3. package irc
  4. import (
  5. "testing"
  6. "github.com/ergochat/ergo/irc/utils"
  7. )
  8. func TestGenerateBatchID(t *testing.T) {
  9. var session Session
  10. s := make(utils.StringSet)
  11. count := 100000
  12. for i := 0; i < count; i++ {
  13. s.Add(session.generateBatchID())
  14. }
  15. if len(s) != count {
  16. t.Error("duplicate batch ID detected")
  17. }
  18. }
  19. func BenchmarkGenerateBatchID(b *testing.B) {
  20. var session Session
  21. for i := 0; i < b.N; i++ {
  22. session.generateBatchID()
  23. }
  24. }
  25. func TestUserMasks(t *testing.T) {
  26. var um UserMaskSet
  27. if um.Match("horse_!user@tor-network.onion") {
  28. t.Error("bad match")
  29. }
  30. um.Add("_!*@*", "x", "x")
  31. if !um.Match("_!user@tor-network.onion") {
  32. t.Error("failure to match")
  33. }
  34. if um.Match("horse_!user@tor-network.onion") {
  35. t.Error("bad match")
  36. }
  37. um.Add("beer*!*@*", "x", "x")
  38. if !um.Match("beergarden!user@tor-network.onion") {
  39. t.Error("failure to match")
  40. }
  41. if um.Match("horse_!user@tor-network.onion") {
  42. t.Error("bad match")
  43. }
  44. um.Add("horse*!user@*", "x", "x")
  45. if !um.Match("horse_!user@tor-network.onion") {
  46. t.Error("failure to match")
  47. }
  48. }
  49. func TestWhoFields(t *testing.T) {
  50. var w whoxFields
  51. if w.Has('a') {
  52. t.Error("zero value of whoxFields must be empty")
  53. }
  54. w = w.Add('a')
  55. if !w.Has('a') {
  56. t.Error("failed to set and get")
  57. }
  58. if w.Has('A') {
  59. t.Error("false positive")
  60. }
  61. if w.Has('o') {
  62. t.Error("false positive")
  63. }
  64. w = w.Add('🐬')
  65. if w.Has('🐬') {
  66. t.Error("should not be able to set invalid who field")
  67. }
  68. w = w.Add('o')
  69. if !w.Has('o') {
  70. t.Error("failed to set and get")
  71. }
  72. w = w.Add('z')
  73. if !w.Has('z') {
  74. t.Error("failed to set and get")
  75. }
  76. }