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.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. tListLong.RegenerateCachedReply()
  27. longReplies := [][]string{
  28. {"1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D"},
  29. {"E", "F"},
  30. }
  31. if !reflect.DeepEqual(tListLong.CachedReply, longReplies) {
  32. t.Errorf("Multiple output replies did not match, got [%v]", longReplies)
  33. }
  34. // create first list
  35. tList1 := NewList()
  36. tList1.Add("SASL", "yes")
  37. tList1.Add("CASEMAPPING", "rfc1459-strict")
  38. tList1.Add("INVEX", "i")
  39. tList1.AddNoValue("EXTBAN")
  40. tList1.Add("RANDKILL", "whenever")
  41. tList1.RegenerateCachedReply()
  42. expected := [][]string{{"CASEMAPPING=rfc1459-strict", "EXTBAN", "INVEX=i", "RANDKILL=whenever", "SASL=yes"}}
  43. if !reflect.DeepEqual(tList1.CachedReply, expected) {
  44. t.Error("tList1's cached reply does not match expected cached reply")
  45. }
  46. // create second list
  47. tList2 := NewList()
  48. tList2.Add("SASL", "yes")
  49. tList2.Add("CASEMAPPING", "ascii")
  50. tList2.AddNoValue("INVEX")
  51. tList2.Add("EXTBAN", "TestBah")
  52. tList2.AddNoValue("STABLEKILL")
  53. tList2.RegenerateCachedReply()
  54. expected = [][]string{{"CASEMAPPING=ascii", "EXTBAN=TestBah", "INVEX", "SASL=yes", "STABLEKILL"}}
  55. if !reflect.DeepEqual(tList2.CachedReply, expected) {
  56. t.Error("tList2's cached reply does not match expected cached reply")
  57. }
  58. // compare lists
  59. actual := tList1.GetDifference(tList2)
  60. expected = [][]string{{"-RANDKILL", "CASEMAPPING=ascii", "EXTBAN=TestBah", "INVEX", "STABLEKILL"}}
  61. if !reflect.DeepEqual(actual, expected) {
  62. t.Error("difference reply does not match expected difference reply")
  63. }
  64. }