1package search
2
3import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7)
8
9func TestNormalizeLossyURL(t *testing.T) {
10 assert := assert.New(t)
11
12 fixtures := []struct {
13 orig string
14 clean string
15 }{
16 {orig: "", clean: ""},
17 {orig: "asdf", clean: "asdf"},
18 {orig: "HTTP://bSky.app:80/index.html", clean: "http://bsky.app"},
19 {orig: "https://example.com/thing?c=123&utm_campaign=blah&a=first", clean: "https://example.com/thing?a=first&c=123"},
20 {orig: "https://example.com/thing?c=123&utm_campaign=blah&a=first", clean: "https://example.com/thing?a=first&c=123"},
21 {orig: "http://example.com/foo//bar.html", clean: "http://example.com/foo/bar.html"},
22 {orig: "http://example.com/bar.html#section1", clean: "http://example.com/bar.html"},
23 {orig: "http://example.com/foo/", clean: "http://example.com/foo"},
24 {orig: "http://example.com/", clean: "http://example.com"},
25 {orig: "http://example.com/%7Efoo", clean: "http://example.com/~foo"},
26 {orig: "http://example.com/foo/./bar/baz/../qux", clean: "http://example.com/foo/bar/qux"},
27 {orig: "http://www.example.com/", clean: "http://example.com"},
28 }
29
30 for _, fix := range fixtures {
31 assert.Equal(fix.clean, NormalizeLossyURL(fix.orig))
32 }
33}