Skip to content

Commit

Permalink
Improve syntax and test (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
AurevoirXavier authored Aug 16, 2023
1 parent 88e797b commit a0acb68
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ impl Unescaper {
'n' => '\n',
'r' => '\r',
't' => '\t',
'\'' => '\'',
'\"' => '\"',
'\\' => '\\',
'/' => '/',
// https://github.com/hack-ink/unescaper/pull/10#issuecomment-1676443635
//
// https://www.ecma-international.org/wp-content/uploads/ECMA-404_2nd_edition_december_2017.pdf
// On page 4 it says: "\/ represents the solidus character (U+002F)."
'\'' | '\"' | '\\' | '/' => c,
'u' => self.unescape_unicode_internal().map_err(|e| offset(e, self.chars.len()))?,
'x' => self.unescape_byte_internal().map_err(|e| offset(e, self.chars.len()))?,
_ => self.unescape_octal_internal(c).map_err(|e| offset(e, self.chars.len()))?,
Expand Down
12 changes: 10 additions & 2 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ fn unescape_octal() {
}

#[test]
fn unescape_others() {
unescape_assert_eq!(r"\/", "/");
fn unescape_special_symbols() {
unescape_assert_eq!(r"\b", "\u{0008}");
unescape_assert_eq!(r"\f", "\u{000c}");
unescape_assert_eq!(r"\n", "\n");
unescape_assert_eq!(r"\r", "\r");
unescape_assert_eq!(r"\t", "\t");
unescape_assert_eq!(r"\'", "\'");
unescape_assert_eq!(r#"\""#, "\"");
unescape_assert_eq!(r"\\", "\\");
unescape_assert_eq!(r"//", "//");
}

0 comments on commit a0acb68

Please sign in to comment.