From d67cec2dbff4cf9f6282ea5d5a6bdfde2ea49e60 Mon Sep 17 00:00:00 2001 From: Jevan Chan Date: Mon, 18 Jan 2021 20:56:19 -0800 Subject: [PATCH] Add tests --- boa/src/syntax/lexer/tests.rs | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/boa/src/syntax/lexer/tests.rs b/boa/src/syntax/lexer/tests.rs index 61e8962f190..496ca44174a 100644 --- a/boa/src/syntax/lexer/tests.rs +++ b/boa/src/syntax/lexer/tests.rs @@ -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] @@ -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::*;