summaryrefslogtreecommitdiff
path: root/mask_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'mask_test.go')
-rw-r--r--mask_test.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/mask_test.go b/mask_test.go
new file mode 100644
index 0000000..87ba406
--- /dev/null
+++ b/mask_test.go
@@ -0,0 +1,45 @@
+package main
+
+import (
+ "testing"
+)
+
+func TestDomainMask(t *testing.T) {
+ testCases := []struct {
+ in, out string
+ }{
+ {"192.0.2.1", "192.0.2.*"},
+ {"gateway/ip.192.0.2.1", "*.192.0.2.1"},
+ {"example.com", "example.com"},
+ {"www.example.com", "*.example.com"},
+ {"2001:db8::1", "2001:db8::*"},
+ {"cloaked/user", "cloaked/user"},
+ }
+ for _, tc := range testCases {
+ t.Run(tc.in, func(t *testing.T) {
+ out := domainMask(tc.in)
+ if out != tc.out {
+ t.Errorf("got %v; want %v", out, tc.out)
+ }
+ })
+ }
+}
+
+func TestMask(t *testing.T) {
+ testCases := []struct {
+ in, out string
+ }{
+ {"~test@gateway/web/freenode/ip.192.0.2.1", "*!*test@*.192.0.2.1"},
+ {"~test@192.0.2.1", "*!*test@192.0.2.*"},
+ {"test@192.0.2.1", "*!*test@192.0.2.*"},
+ {"bogus", "*!*bogus"},
+ }
+ for _, tc := range testCases {
+ t.Run(tc.in, func(t *testing.T) {
+ out := mask(tc.in)
+ if out != tc.out {
+ t.Errorf("got %v; want %v", out, tc.out)
+ }
+ })
+ }
+}