30 lines
907 B
Go
30 lines
907 B
Go
package keys
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestNamesEscapeIntoKeyPartsAndBack(t *testing.T) {
|
|
for _, c := range []struct{ name, esc string }{
|
|
{"fix/1.2", "fix/1=2e2"}, {"a.b", "a=2eb"}, {"a=b", "a=3db"}, {"a+b", "a=2bb"}, {"plain-name_1/x", "plain-name_1/x"},
|
|
{"fix/ü", "fix/=c3=bc"}, {"x y", "x=20y"},
|
|
} {
|
|
esc := EscapeName(c.name)
|
|
if esc != c.esc || strings.ContainsAny(esc, ".+ ") {
|
|
t.Errorf("escape of %q = %q, want %q", c.name, esc, c.esc)
|
|
}
|
|
if back, err := UnescapeName(esc); err != nil || back != c.name {
|
|
t.Errorf("unescape(%q) = %q, %v; want %q", esc, back, err, c.name)
|
|
}
|
|
}
|
|
for _, bad := range []string{"a.b", "a=", "a=2", "a=zz", "a=2E", "a b"} {
|
|
if got, err := UnescapeName(bad); err == nil {
|
|
t.Errorf("unescape(%q) = %q, accepted", bad, got)
|
|
}
|
|
}
|
|
if Version != 1 {
|
|
t.Errorf("Version = %d: a kept value's readers read the one version", Version)
|
|
}
|
|
}
|