Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jevancc committed Jan 19, 2021
1 parent 835a5bb commit d67cec2
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions boa/src/syntax/lexer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,17 @@ fn legacy_octal_escape() {

assert_eq!(s, *expected);
}

for (s, _) in test_cases.iter() {
let mut cursor = Cursor::new(s.as_bytes());
StringLiteral::take_string_characters(
&mut cursor,
Position::new(1, 1),
StringTerminator::End,
true,
)
.expect_err("Octal-escape in strict mode not rejected as expected");
}
}

#[test]
Expand All @@ -934,6 +945,50 @@ fn zero_escape() {
}
}

#[test]
fn non_octal_decimal_escape() {
let test_cases = [(r#"\8"#, "8"), (r#"\9"#, "9")];

for (s, expected) in test_cases.iter() {
let mut cursor = Cursor::new(s.as_bytes());
let (s, _) = StringLiteral::take_string_characters(
&mut cursor,
Position::new(1, 1),
StringTerminator::End,
false,
)
.unwrap();

assert_eq!(s, *expected);
}

for (s, _) in test_cases.iter() {
let mut cursor = Cursor::new(s.as_bytes());
StringLiteral::take_string_characters(
&mut cursor,
Position::new(1, 1),
StringTerminator::End,
true,
)
.expect_err("Non-octal-decimal-escape in strict mode not rejected as expected");
}
}

#[test]
fn line_continuation() {
let s = "hello \\\nworld";
let mut cursor = Cursor::new(s.as_bytes());
let (s, _) = StringLiteral::take_string_characters(
&mut cursor,
Position::new(1, 1),
StringTerminator::End,
false,
)
.unwrap();

assert_eq!(s, "hello world");
}

mod carriage_return {
use super::*;

Expand Down

0 comments on commit d67cec2

Please sign in to comment.