2016-01-17 02:10:51 +00:00
|
|
|
package ircmsg
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
type testcase struct {
|
|
|
|
escaped string
|
|
|
|
unescaped string
|
|
|
|
}
|
|
|
|
|
|
|
|
var tests = []testcase{
|
2016-01-17 08:27:12 +00:00
|
|
|
{"te\\nst", "te\nst"},
|
2016-01-17 14:01:57 +00:00
|
|
|
{"tes\\\\st", "tes\\st"},
|
|
|
|
}
|
|
|
|
|
|
|
|
var unescapeTests = []testcase{
|
|
|
|
{"te\\n\\kst", "te\nkst"},
|
2016-01-17 14:21:38 +00:00
|
|
|
{"te\\\\nst", "te\\nst"},
|
2016-01-17 02:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEscape(t *testing.T) {
|
|
|
|
for _, pair := range tests {
|
|
|
|
val := EscapeTagValue(pair.unescaped)
|
|
|
|
|
|
|
|
if val != pair.escaped {
|
|
|
|
t.Error(
|
|
|
|
"For", pair.unescaped,
|
|
|
|
"expected", pair.escaped,
|
|
|
|
"got", val,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnescape(t *testing.T) {
|
|
|
|
for _, pair := range tests {
|
|
|
|
val := UnescapeTagValue(pair.escaped)
|
|
|
|
|
2016-01-17 14:01:57 +00:00
|
|
|
if val != pair.unescaped {
|
|
|
|
t.Error(
|
|
|
|
"For", pair.escaped,
|
|
|
|
"expected", pair.unescaped,
|
|
|
|
"got", val,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, pair := range unescapeTests {
|
|
|
|
val := UnescapeTagValue(pair.escaped)
|
|
|
|
|
2016-01-17 02:10:51 +00:00
|
|
|
if val != pair.unescaped {
|
|
|
|
t.Error(
|
|
|
|
"For", pair.escaped,
|
|
|
|
"expected", pair.unescaped,
|
|
|
|
"got", val,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|