Skip to content

Commit 42956fa

Browse files
committed
Add tests for escaping functions
1 parent 058ce87 commit 42956fa

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

utils_test.go

+39
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,42 @@ func TestFormatBinaryDateTime(t *testing.T) {
252252
expect("1978-12-30 15:46:23", 7, 19)
253253
expect("1978-12-30 15:46:23.987654", 11, 26)
254254
}
255+
256+
func TestEscapeString(t *testing.T) {
257+
expect := func(expected, value string) {
258+
actual := string(EscapeString([]byte(value)))
259+
if actual != expected {
260+
t.Errorf(
261+
"expected %s, got %s",
262+
expected, actual,
263+
)
264+
}
265+
}
266+
267+
expect("foo\\0bar", "foo\x00bar")
268+
expect("foo\\nbar", "foo\nbar")
269+
expect("foo\\rbar", "foo\rbar")
270+
expect("foo\\Zbar", "foo\x1abar")
271+
expect("foo\\\"bar", "foo\"bar")
272+
expect("foo\\\\bar", "foo\\bar")
273+
expect("foo\\'bar", "foo'bar")
274+
}
275+
276+
func TestEscapeQuotes(t *testing.T) {
277+
expect := func(expected, value string) {
278+
actual := string(EscapeQuotes([]byte(value)))
279+
if actual != expected {
280+
t.Errorf(
281+
"expected %s, got %s",
282+
expected, actual,
283+
)
284+
}
285+
}
286+
287+
expect("foo\x00bar", "foo\x00bar") // not affected
288+
expect("foo\nbar", "foo\nbar") // not affected
289+
expect("foo\rbar", "foo\rbar") // not affected
290+
expect("foo\x1abar", "foo\x1abar") // not affected
291+
expect("foo''bar", "foo'bar") // affected
292+
expect("foo\"bar", "foo\"bar") // not affected
293+
}

0 commit comments

Comments
 (0)