Skip to content

Commit

Permalink
Add tests for escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
lynzrand authored and bobzhang committed Mar 22, 2024
1 parent c737fd2 commit 5b1130d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion string/moon.pkg.json
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{}
{
"import": [
{
"path": "moonbitlang/core/assertion",
"alias": "assertion"
}
]
}
12 changes: 12 additions & 0 deletions string/string.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,15 @@ pub fn escape(self : String) -> String {
self.escape_to(buf)
buf.to_string()
}

test "backslash escape" {
let s = "\n\r\t\b\"\'\\"
let expected = "\\n\\r\\t\\b\\\"\\\'\\\\"
@assertion.assert_eq(s.escape(), expected)?
}

test "hex escape"{
let s = "\x11\x12\x01\x02"
let expected = "\\x11\\x12\\x01\\x02"
@assertion.assert_eq(s.escape(), expected)?
}

0 comments on commit 5b1130d

Please sign in to comment.