@ -74,10 +74,33 @@ func TestSplitN(t *testing.T) {
}
func TestSprintName ( t * testing . T ) {
got := sprintName ( "abc\\.def\007\"\127@\255\x05\xef\\" )
if want := "abc\\.def\\007\\\"W\\@\\173\\005\\239" ; got != want {
t . Errorf ( "expected %q, got %q" , want , got )
tests := map [ string ] string {
// Non-numeric escaping of special printable characters.
" '@;()\"\\..example" : ` \ \'\@\;\(\)\"\..example ` ,
"\\032\\039\\064\\059\\040\\041\\034\\046\\092.example" : ` \ \'\@\;\(\)\"\.\\.example ` ,
// Numeric escaping of nonprintable characters.
"\x00\x07\x09\x0a\x1f.\x7f\x80\xad\xef\xff" : ` \000\007\009\010\031.\127\128\173\239\255 ` ,
"\\000\\007\\009\\010\\031.\\127\\128\\173\\239\\255" : ` \000\007\009\010\031.\127\128\173\239\255 ` ,
// No escaping of other printable characters, at least after a prior escape.
";[a-zA-Z0-9_]+/*.~" : ` \;[a-zA-Z0-9_]+/*.~ ` ,
";\\091\\097\\045\\122\\065\\045\\090\\048\\045\\057\\095\\093\\043\\047\\042.\\126" : ` \;[a-zA-Z0-9_]+/*.~ ` ,
// "\\091\\097\\045\\122\\065\\045\\090\\048\\045\\057\\095\\093\\043\\047\\042.\\126": `[a-zA-Z0-9_]+/*.~`,
// Incomplete "dangling" escapes are dropped regardless of prior escaping.
"a\\" : ` a ` ,
";\\" : ` \; ` ,
// Escaped dots stay escaped regardless of prior escaping.
"a\\.\\046.\\.\\046" : ` a\.\..\.\. ` ,
"a\\046\\..\\046\\." : ` a\.\..\.\. ` ,
}
for input , want := range tests {
got := sprintName ( input )
if got != want {
t . Errorf ( "input %q: expected %q, got %q" , input , want , got )
}
}
}