From a39e266ddeb9d11b9f23f50a0124c56e3414563c Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Sat, 19 Jun 2021 23:44:34 +0200 Subject: url: add test --- skate/url_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/skate/url_test.go b/skate/url_test.go index 8103246..caf05a4 100644 --- a/skate/url_test.go +++ b/skate/url_test.go @@ -148,6 +148,27 @@ func TestSanitizeURL(t *testing.T) { } } +func TestHasAnyPrefix(t *testing.T) { + var cases = []struct { + s string + prefix []string + result bool + }{ + {s: "", prefix: nil, result: false}, + {s: "", prefix: []string{}, result: false}, + {s: "a", prefix: []string{}, result: false}, + {s: "a", prefix: []string{"a"}, result: true}, + {s: "a", prefix: []string{"aa"}, result: false}, + {s: "aa", prefix: []string{"a"}, result: true}, + } + for _, c := range cases { + result := HasAnyPrefix(c.s, c.prefix) + if result != c.result { + t.Fatalf("got %v, want %v", result, c.result) + } + } +} + func BenchmarkSanitizeURL(b *testing.B) { var bms = []struct { name string -- cgit v1.2.3