diff options
author | clsr <clsr@clsr.net> | 2017-08-18 13:45:49 +0200 |
---|---|---|
committer | clsr <clsr@clsr.net> | 2017-08-18 13:45:49 +0200 |
commit | 26248678aafc2f8e277d4bdafc116f2b349b02c5 (patch) | |
tree | 15f82488edb8c05aae756443284731875f36737c /simpletext_test.go | |
download | cnm-go-26248678aafc2f8e277d4bdafc116f2b349b02c5.tar.gz cnm-go-26248678aafc2f8e277d4bdafc116f2b349b02c5.zip |
Initial commitv0.1.0
Diffstat (limited to 'simpletext_test.go')
-rw-r--r-- | simpletext_test.go | 180 |
1 files changed, 180 insertions, 0 deletions
diff --git a/simpletext_test.go b/simpletext_test.go new file mode 100644 index 0000000..8fdf754 --- /dev/null +++ b/simpletext_test.go @@ -0,0 +1,180 @@ +package cnm + +import "testing" + +var simpleEscapes = map[string]string{ + "": ``, + "ContNet": `ContNet`, + "\t": `\t`, + "\n": `\n`, + "\f": `\f`, + "\r": `\r`, + " ": `\ `, + "\\": `\\`, + "\x00": `\x00`, + " ": `\ \ \ \ `, + " ": `\ \ \ \ `, + " ": `\ \ \ `, + " ": `\ \ \ `, + " ": `\ \ `, + " ": `\ \ `, + "\b\v\\\x00\xff\u00ff\\xff": "\b\v\\\\\\x00\xff\u00ff\\\\xff", +} + +func TestEscape(t *testing.T) { + for k, v := range simpleEscapes { + t.Run(k, func(t *testing.T) { + e := Escape(k) + if e != v { + t.Errorf("Escape(%q) -> %q, expected %q", k, e, v) + } + }) + } +} + +var nonspaceEscapes = map[string]string{ + "": ``, + "ContNet": `ContNet`, + "\t": "\t", + "\n": "\n", + "\f": `\f`, + "\r": `\r`, + " ": ` `, + "\\": `\\`, + "\x00": `\x00`, + " ": ` `, + " ": ` `, + " ": ` `, + " ": ` `, + " ": ` `, + " ": ` `, + "\b\v\\\x00\xff\u00ff\\xff": "\b\v\\\\\\x00\xff\u00ff\\\\xff", +} + +func TestEscapeNonspace(t *testing.T) { + for k, v := range nonspaceEscapes { + t.Run(k, func(t *testing.T) { + e := EscapeNonspace(k) + if e != v { + t.Errorf("EscapeNonspace(%q) -> %q, expected %q", k, e, v) + } + }) + } +} + +var spaceEscapes = map[string]string{ + "": ``, + "ContNet": `ContNet`, + "\t": `\t`, + "\n": `\n`, + "\f": "\f", + "\r": "\r", + " ": `\ `, + "\\": `\`, + "\x00": "\x00", + " ": `\ \ \ \ `, + " ": `\ \ \ \ `, + " ": `\ \ \ `, + " ": `\ \ \ `, + " ": `\ \ `, + " ": `\ \ `, + "\b\v\\\x00\xff\u00ff\\xff": "\b\v\\\x00\xff\u00ff\\xff", +} + +func TestEscapeSpace(t *testing.T) { + for k, v := range spaceEscapes { + t.Run(k, func(t *testing.T) { + e := EscapeSpace(k) + if e != v { + t.Errorf("EscapeSpace(%q) -> %q, expected %q", k, e, v) + } + }) + } +} + +var simpleUnescapes = map[string]string{ + ``: "", + `ContNet`: "ContNet", + `\b`: "\b", + `\t`: "\t", + `\n`: "\n", + `\v`: "\v", + `\f`: "\f", + `\r`: "\r", + `\ `: " ", + `\\`: "\\", + `\`: "\\", + `\x00`: "\x00", + `a\nb\ c\rd\be\\f`: "a\nb c\rd\be\\f", + `\n\n\n`: "\n\n\n", + `\x00\xff\n\x123`: "\x00\u00ff\n\x123", + " \b\\b\t\n\v\f\r\\x00\x00\\\\xff": " \b\b\t\n\v\f\r\x00\x00\\xff", + `\xAA\xAa\xaA\xaa`: "\u00aa\u00aa\u00aa\u00aa", + `\x00\xfg`: "\x00\\xfg", + `\\\\\\`: "\\\\\\", + "\b5Ὂg̀9!\\n℃ᾭG": "\b5Ὂg̀9!\n℃ᾭG", + "\xff\\x00\xee\xaa\xee": "\xff\x00\xee\xaa\xee", + "\\x00\x10\\ \x30\x40": "\x00\x10\x20\x30\x40", + "\x10\x50\x90\xe0": "\x10\x50\x90\xe0", + `Hello,\ 世界`: "Hello, 世界", + "\xed\x9f\xbf": "\xed\x9f\xbf", + "\xee\x80\x80": "\xee\x80\x80", + "\xef\xbf\xbd": "\xef\xbf\xbd", + "\x80\x80\x80\x80": "\x80\x80\x80\x80", + `\ \ \ `: " ", + `\uffff\u0000\u0123\ufedc\ufffe`: "\uffff\u0000\u0123\ufedc\ufffe", + `\Uffff0000\U0003fedc\U0010ffff\U00110000`: "\ufffd\U0003fedc\U0010ffff\ufffd", + `\x0x\u012x\U0123456x`: "\\x0x\\u012x\\U0123456x", + `\U0123456`: "\\U0123456", + `\u012`: "\\u012", + `\x0`: "\\x0", + `\x\u\U\a\z\0\-`: "\\x\\u\\U\\a\\z\\0\\-", +} + +func TestUnescape(t *testing.T) { + for k, v := range simpleUnescapes { + t.Run(k, func(t *testing.T) { + u := Unescape(k) + if u != v { + t.Errorf("Unescape(%q) -> %q, expected %q", k, u, v) + } + }) + } +} + +var simpleTexts = map[string]string{ + "foo": "foo", + "\n": "", + "\n\r \t\v\f": "\v", + " ": "", + `\ `: " ", + ` \ `: " ", + `\ `: " ", + `\ \ `: " ", + ` \`: "\\", + `\`: "\\", + ` \ `: " ", + ` `: "", + `\ \ `: " ", + ` \ `: " ", + " qwe asd ": "qwe asd", + "\\ qwe\nasd\n\nzxc\\n123\n": " qwe asd zxc\n123", + `\ \ \ \ \ `: " ", + ` \ \ \ `: " ", + ` \\ `: "\\", + `\ \\ `: " \\", + ` \\\ `: "\\ ", + ` \ \\\ `: " \\ ", + `\ \\ \ `: " \\ ", +} + +func TestParseSimpleText(t *testing.T) { + for k, v := range simpleTexts { + t.Run(k, func(t *testing.T) { + u := ParseSimpleText(k) + if u != v { + t.Errorf("ParseSimpleText(%q) -> %q, expected %q", k, u, v) + } + }) + } +} |