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.

69 lines
1.3 KiB
Go

5 years ago
package blammo
import (
"testing"
)
func TestPath(t *testing.T) {
p := NewPath("alice")
if p.String() != "alice" {
t.Error("bad root path generation")
}
p = p.Child("bob")
if p.String() != "alice/bob" {
t.Error("bad child path generation")
}
p = p.Child("carol")
if p.String() != "alice/bob/carol" {
t.Error("bad grandchild generation")
}
p = p.Child(" dave ")
if p.String() != "alice/bob/carol/dave" {
t.Error("bad sanitation transformation")
}
5 years ago
}
func TestSafeNames(t *testing.T) {
safeNames := []string{
"one",
"1",
"1one",
"niño",
"garçon",
"alice-bob",
"alice_bob",
"alice:bob",
5 years ago
"你好",
// this string contains a unicode zero-width non-joiner character. Not
// sure how I feel about this being considered safe. On the one hand
// it's necessary for some languages, on the other hand it has the
// propensity to create confusing homoglyph situations.
string([]rune{'o', 0x8204, 'n', 'e'}),
5 years ago
"",
}
for _, n := range safeNames {
if !IsSafeName(n) {
t.Errorf("expected safe name is considered unsafe: %s", n)
}
}
unsafeNames := []string{
" one",
"one ",
"alice/bob",
"alice bob",
5 years ago
"alice[bob]",
"alice{bob}",
"alice=bob",
}
for _, n := range unsafeNames {
if IsSafeName(n) {
t.Errorf("expected unsafe name is considered safe: %s", n)
}
}
5 years ago
}