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.

list_test.go 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright (c) 2016 Daniel Oaks <daniel@danieloaks.net>
  2. // released under the MIT license
  3. package isupport
  4. import (
  5. "reflect"
  6. "testing"
  7. )
  8. func TestISUPPORT(t *testing.T) {
  9. // test multiple output replies
  10. tListLong := NewList()
  11. tListLong.AddNoValue("1")
  12. tListLong.AddNoValue("2")
  13. tListLong.AddNoValue("3")
  14. tListLong.AddNoValue("4")
  15. tListLong.AddNoValue("5")
  16. tListLong.AddNoValue("6")
  17. tListLong.AddNoValue("7")
  18. tListLong.AddNoValue("8")
  19. tListLong.AddNoValue("9")
  20. tListLong.AddNoValue("A")
  21. tListLong.AddNoValue("B")
  22. tListLong.AddNoValue("C")
  23. tListLong.AddNoValue("D")
  24. tListLong.AddNoValue("E")
  25. tListLong.AddNoValue("F")
  26. err := tListLong.RegenerateCachedReply()
  27. if err != nil {
  28. t.Error(err)
  29. }
  30. longReplies := [][]string{
  31. {"1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D"},
  32. {"E", "F"},
  33. }
  34. if !reflect.DeepEqual(tListLong.CachedReply, longReplies) {
  35. t.Errorf("Multiple output replies did not match, got [%v]", longReplies)
  36. }
  37. // create first list
  38. tList1 := NewList()
  39. tList1.Add("SASL", "yes")
  40. tList1.Add("CASEMAPPING", "rfc1459-strict")
  41. tList1.Add("INVEX", "i")
  42. tList1.AddNoValue("EXTBAN")
  43. tList1.Add("RANDKILL", "whenever")
  44. err = tList1.RegenerateCachedReply()
  45. if err != nil {
  46. t.Error(err)
  47. }
  48. expected := [][]string{{"CASEMAPPING=rfc1459-strict", "EXTBAN", "INVEX=i", "RANDKILL=whenever", "SASL=yes"}}
  49. if !reflect.DeepEqual(tList1.CachedReply, expected) {
  50. t.Error("tList1's cached reply does not match expected cached reply")
  51. }
  52. // create second list
  53. tList2 := NewList()
  54. tList2.Add("SASL", "yes")
  55. tList2.Add("CASEMAPPING", "ascii")
  56. tList2.AddNoValue("INVEX")
  57. tList2.Add("EXTBAN", "TestBah")
  58. tList2.AddNoValue("STABLEKILL")
  59. err = tList2.RegenerateCachedReply()
  60. if err != nil {
  61. t.Error(err)
  62. }
  63. expected = [][]string{{"CASEMAPPING=ascii", "EXTBAN=TestBah", "INVEX", "SASL=yes", "STABLEKILL"}}
  64. if !reflect.DeepEqual(tList2.CachedReply, expected) {
  65. t.Error("tList2's cached reply does not match expected cached reply")
  66. }
  67. // compare lists
  68. actual := tList1.GetDifference(tList2)
  69. expected = [][]string{{"-RANDKILL", "CASEMAPPING=ascii", "EXTBAN=TestBah", "INVEX", "STABLEKILL"}}
  70. if !reflect.DeepEqual(actual, expected) {
  71. t.Error("difference reply does not match expected difference reply")
  72. }
  73. }
  74. func TestBadToken(t *testing.T) {
  75. list := NewList()
  76. list.Add("NETWORK", "Bad Network Name")
  77. list.Add("SASL", "yes")
  78. list.Add("CASEMAPPING", "rfc1459-strict")
  79. list.Add("INVEX", "i")
  80. list.AddNoValue("EXTBAN")
  81. err := list.RegenerateCachedReply()
  82. if err == nil {
  83. t.Error("isupport token generation should fail due to space in network name")
  84. }
  85. // should produce a list containing the other, valid params
  86. numParams := 0
  87. for _, tokenLine := range list.CachedReply {
  88. numParams += len(tokenLine)
  89. }
  90. if numParams != 4 {
  91. t.Errorf("expected the other 4 params to be generated, got %v", list.CachedReply)
  92. }
  93. }