-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from slingamn/escapes.2
add support for C hex escapes
- Loading branch information
Showing
3 changed files
with
90 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2023 Shivaram Lingamneni <[email protected]> | ||
// released under the ISC license | ||
|
||
package lib | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
var replacementTestCases = []struct { | ||
input string | ||
output string | ||
}{ | ||
{"", ""}, | ||
{`a`, "a"}, | ||
{`[`, "["}, | ||
{`[[`, "[["}, | ||
{`[[a]]`, "[[a]]"}, | ||
{`a[[CTCP]]b`, "a\x01b"}, | ||
{`[[B]]b[[B]]`, "\x02b\x02"}, | ||
{`a[[\x67]]b`, "a\x67b"}, | ||
{`[[\x67]]`, "\x67"}, | ||
{`www[[\x00]]`, "www\x00"}, | ||
{`www[[\x0D]]`, "www\x0d"}, | ||
{`www[[\xff]]`, "www\xff"}, | ||
{`www[[\xFF]]`, "www\xff"}, | ||
{`[[notanescape]]`, "[[notanescape]]"}, | ||
{`[[[U]]]`, "[\x1f]"}, | ||
} | ||
|
||
func TestReplaceControlCodes(t *testing.T) { | ||
for _, testCase := range replacementTestCases { | ||
actual := ReplaceControlCodes(testCase.input) | ||
if actual != testCase.output { | ||
t.Errorf("expected `%s` -> %#v, got %#v", testCase.input, []byte(testCase.output), []byte(actual)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters