You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gophi/core/url_test.go

68 lines
1.3 KiB
Go

package core_test
import (
"fmt"
"gophi/core"
"io/ioutil"
"net/url"
"testing"
)
var toEscape = []string{
"",
"abc",
"abc+def",
"a?b",
"one two",
"10%",
" ?&=#+%!<>#\"{}|\\^[]`☺\t:@$'()*,;",
}
var escaped = []string{
"",
"abc",
"abc+def",
"a%3Fb",
"one%20two",
"10%25",
"%20%3F&=%23+%25%21%3C%3E%23%22%7B%7D%7C%5C%5E%5B%5D%60%E2%98%BA%09:@$%27%28%29%2A%2C%3B",
}
func TestPathEscape(t *testing.T) {
for i, path := range toEscape {
if escapedPath := core.EscapePath(path); escapedPath != escaped[i] {
t.Fatalf("Failed escaping path!\nGot: %s\nExpected: %s\n", escapedPath, escaped[i])
}
}
}
func TestParseEncodedHost(t *testing.T) {
}
func TestParseEncodedURI(t *testing.T) {
}
func BenchmarkCorePathEscape(b *testing.B) {
var s string
for i := 0; i < b.N; i++ {
for _, path := range toEscape {
s = core.EscapePath(path)
}
}
fmt.Fprint(ioutil.Discard, s)
}
func BenchmarkURLPathEscape(b *testing.B) {
var s string
for i := 0; i < b.N; i++ {
for _, path := range toEscape {
// This isn't *exactly* a fair comparison to core.EscapePath,
// since url.PathEscape() escapes a path _segment_ as opposed
// to any entire path, whereas core.EscapePath() escapes an entire
// filesystem path.
s = url.PathEscape(path)
}
}
fmt.Fprint(ioutil.Discard, s)
}