Skip to content

Commit

Permalink
Refactor StringLiteral
Browse files Browse the repository at this point in the history
Fix octal escape in string literal


Add tests


Fix zero escape


Fix zero escape lookahead


Rename variables


Rename helper functions


Refactor match arms


Fix escape line terminator sequence


Fix single character escape


Fix line terminator and escape followed by unicode char


Fix broken tests


Add NonOctalDecimalEscapeSequence


Fix comment


Refactor


Modify error message


Add tests


Rename tests


Add test for error


Add comments for unsafe bytes to str


Update boa/src/syntax/lexer/string.rs

Co-authored-by: tofpie <75836434+tofpie@users.noreply.github.com>
Minor refactor


Remove unsafe bytes to str


Fix panic when reading invalid utf-8 chars


Refactor string literal


Support invalid utf-8 chars in string literal input


Add cook function for template literal


Fix line continuation bug


Add methods for utf16 buffer trait


Add trait comments


Add error message for template literal


Add and fix comments


Hide unused exported function and modify tests


Fix bug


Fix merge bug
  • Loading branch information
jevancc committed Jan 27, 2021
1 parent 2f3b926 commit 8937bb2
Show file tree
Hide file tree
Showing 5 changed files with 304 additions and 299 deletions.
53 changes: 25 additions & 28 deletions boa/src/builtins/json/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ fn json_stringify_pretty_print() {
);
let expected = forward(
&mut context,
r#"'{
"a": "b",
"b": "c"
}'"#,
r#"'{\n'
+' "a": "b",\n'
+' "b": "c"\n'
+'}'"#,
);
assert_eq!(actual, expected);
}
Expand All @@ -235,10 +235,10 @@ fn json_stringify_pretty_print_four_spaces() {
);
let expected = forward(
&mut context,
r#"'{
"a": "b",
"b": "c"
}'"#,
r#"'{\n'
+' "a": "b",\n'
+' "b": "c"\n'
+'}'"#,
);
assert_eq!(actual, expected);
}
Expand All @@ -253,10 +253,10 @@ fn json_stringify_pretty_print_twenty_spaces() {
);
let expected = forward(
&mut context,
r#"'{
"a": "b",
"b": "c"
}'"#,
r#"'{\n'
+' "a": "b",\n'
+' "b": "c"\n'
+'}'"#,
);
assert_eq!(actual, expected);
}
Expand All @@ -271,10 +271,10 @@ fn json_stringify_pretty_print_with_number_object() {
);
let expected = forward(
&mut context,
r#"'{
"a": "b",
"b": "c"
}'"#,
r#"'{\n'
+' "a": "b",\n'
+' "b": "c"\n'
+'}'"#,
);
assert_eq!(actual, expected);
}
Expand All @@ -301,10 +301,10 @@ fn json_stringify_pretty_print_with_too_long_string() {
);
let expected = forward(
&mut context,
r#"'{
abcdefghij"a": "b",
abcdefghij"b": "c"
}'"#,
r#"'{\n'
+'abcdefghij"a": "b",\n'
+'abcdefghij"b": "c"\n'
+'}'"#,
);
assert_eq!(actual, expected);
}
Expand All @@ -319,10 +319,10 @@ fn json_stringify_pretty_print_with_string_object() {
);
let expected = forward(
&mut context,
r#"'{
abcd"a": "b",
abcd"b": "c"
}'"#,
r#"'{\n'
+'abcd"a": "b",\n'
+'abcd"b": "c"\n'
+'}'"#,
);
assert_eq!(actual, expected);
}
Expand Down Expand Up @@ -404,10 +404,7 @@ fn json_parse_object_with_reviver() {
fn json_parse_sets_prototypes() {
let mut context = Context::new();
let init = r#"
const jsonString = "{
\"ob\":{\"ject\":1},
\"arr\": [0,1]
}";
const jsonString = "{\"ob\":{\"ject\":1},\"arr\": [0,1]}";
const jsonObj = JSON.parse(jsonString);
"#;
eprintln!("{}", forward(&mut context, init));
Expand Down
36 changes: 24 additions & 12 deletions boa/src/builtins/string/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,34 +533,46 @@ fn test_match() {
#[test]
fn trim() {
let mut context = Context::new();
assert_eq!(forward(&mut context, "'Hello'.trim()"), "\"Hello\"");
assert_eq!(forward(&mut context, "' \nHello'.trim()"), "\"Hello\"");
assert_eq!(forward(&mut context, "'Hello \n\r'.trim()"), "\"Hello\"");
assert_eq!(forward(&mut context, "' Hello '.trim()"), "\"Hello\"");
assert_eq!(forward(&mut context, r#"'Hello'.trim()"#), "\"Hello\"");
assert_eq!(forward(&mut context, r#"' \nHello'.trim()"#), "\"Hello\"");
assert_eq!(forward(&mut context, r#"'Hello \n\r'.trim()"#), "\"Hello\"");
assert_eq!(forward(&mut context, r#"' Hello '.trim()"#), "\"Hello\"");
}

#[test]
fn trim_start() {
let mut context = Context::new();
assert_eq!(forward(&mut context, "'Hello'.trimStart()"), "\"Hello\"");
assert_eq!(forward(&mut context, "' \nHello'.trimStart()"), "\"Hello\"");
assert_eq!(forward(&mut context, r#"'Hello'.trimStart()"#), "\"Hello\"");
assert_eq!(
forward(&mut context, "'Hello \n'.trimStart()"),
forward(&mut context, r#"' \nHello'.trimStart()"#),
"\"Hello\""
);
assert_eq!(
forward(&mut context, r#"'Hello \n'.trimStart()"#),
"\"Hello \n\""
);
assert_eq!(forward(&mut context, "' Hello '.trimStart()"), "\"Hello \"");
assert_eq!(
forward(&mut context, r#"' Hello '.trimStart()"#),
"\"Hello \""
);
}

#[test]
fn trim_end() {
let mut context = Context::new();
assert_eq!(forward(&mut context, "'Hello'.trimEnd()"), "\"Hello\"");
assert_eq!(forward(&mut context, r#"'Hello'.trimEnd()"#), "\"Hello\"");
assert_eq!(
forward(&mut context, "' \nHello'.trimEnd()"),
forward(&mut context, r#"' \nHello'.trimEnd()"#),
"\" \nHello\""
);
assert_eq!(forward(&mut context, "'Hello \n'.trimEnd()"), "\"Hello\"");
assert_eq!(forward(&mut context, "' Hello '.trimEnd()"), "\" Hello\"");
assert_eq!(
forward(&mut context, r#"'Hello \n'.trimEnd()"#),
"\"Hello\""
);
assert_eq!(
forward(&mut context, r#"' Hello '.trimEnd()"#),
"\" Hello\""
);
}

#[test]
Expand Down
Loading

0 comments on commit 8937bb2

Please sign in to comment.