From d038cd44f89591a028c54319107cb7934a34f4a8 Mon Sep 17 00:00:00 2001 From: Dustin Sallings Date: Sun, 9 Nov 2014 14:28:58 -0800 Subject: [PATCH] Path matching tests --- servmux_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/servmux_test.go b/servmux_test.go index 8a0b601..b9ddc41 100644 --- a/servmux_test.go +++ b/servmux_test.go @@ -39,3 +39,24 @@ func TestPathMatching(t *testing.T) { t.Errorf("Expected 1 message for /b, got %v", msgs["b"]) } } + +func TestPathMatch(t *testing.T) { + tests := []struct { + pattern, path string + exp bool + }{ + {"", "", false}, + {"/a/b/c", "/a/b/c", true}, + {"/a/b/c", "/a/b/c/d", false}, + {"/a/b/c/", "/a/b/c/d", true}, + {"/a/b/c", "/", false}, + {"/a/", "/", false}, + } + + for _, test := range tests { + if pathMatch(test.pattern, test.path) != test.exp { + t.Errorf("Failed on pathMatch(%q, %q), wanted %v", + test.pattern, test.path, test.exp) + } + } +}