Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

set_test.go 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (c) 2017 Daniel Oaks <daniel@danieloaks.net>
  2. // released under the MIT license
  3. package caps
  4. import "testing"
  5. import "reflect"
  6. func TestSets(t *testing.T) {
  7. s1 := NewSet()
  8. s1.Enable(AccountTag, EchoMessage, UserhostInNames)
  9. if !s1.Has(AccountTag, EchoMessage, UserhostInNames) {
  10. t.Error("Did not have the tags we expected")
  11. }
  12. if s1.Has(AccountTag, EchoMessage, STS, UserhostInNames) {
  13. t.Error("Has() returned true when we don't have all the given capabilities")
  14. }
  15. s1.Disable(AccountTag)
  16. if s1.Has(AccountTag) {
  17. t.Error("Disable() did not correctly disable the given capability")
  18. }
  19. enabledCaps := make(map[Capability]bool)
  20. for _, capab := range s1.List() {
  21. enabledCaps[capab] = true
  22. }
  23. expectedCaps := map[Capability]bool{
  24. EchoMessage: true,
  25. UserhostInNames: true,
  26. }
  27. if !reflect.DeepEqual(enabledCaps, expectedCaps) {
  28. t.Errorf("Enabled and expected capability lists do not match: %v, %v", enabledCaps, expectedCaps)
  29. }
  30. // make sure re-enabling doesn't add to the count or something weird like that
  31. s1.Enable(EchoMessage)
  32. if s1.Count() != 2 {
  33. t.Error("Count() did not match expected capability count")
  34. }
  35. // make sure add and remove work fine
  36. s1.Add(InviteNotify)
  37. s1.Remove(EchoMessage)
  38. if s1.Count() != 2 {
  39. t.Error("Count() did not match expected capability count")
  40. }
  41. // test String()
  42. values := NewValues()
  43. values.Set(InviteNotify, "invitemepls")
  44. actualCap301ValuesString := s1.String(Cap301, values)
  45. expectedCap301ValuesString := "invite-notify userhost-in-names"
  46. if actualCap301ValuesString != expectedCap301ValuesString {
  47. t.Errorf("Generated Cap301 values string [%s] did not match expected values string [%s]", actualCap301ValuesString, expectedCap301ValuesString)
  48. }
  49. actualCap302ValuesString := s1.String(Cap302, values)
  50. expectedCap302ValuesString := "invite-notify=invitemepls userhost-in-names"
  51. if actualCap302ValuesString != expectedCap302ValuesString {
  52. t.Errorf("Generated Cap302 values string [%s] did not match expected values string [%s]", actualCap302ValuesString, expectedCap302ValuesString)
  53. }
  54. }