From e529d702ec5cc869a08be7486b82e06d23d4466a Mon Sep 17 00:00:00 2001 From: Hans Larsen Date: Fri, 13 Dec 2024 22:41:28 -0800 Subject: [PATCH] Add a stress test to the parser to parser multi-millions tokens (#4086) --- core/parser/src/parser/tests/mod.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/parser/src/parser/tests/mod.rs b/core/parser/src/parser/tests/mod.rs index f4cf4ce27b1..5cc9eb2842d 100644 --- a/core/parser/src/parser/tests/mod.rs +++ b/core/parser/src/parser/tests/mod.rs @@ -623,3 +623,14 @@ fn deny_unicode_escape_in_true_expression() { fn deny_unicode_escape_in_null_expression() { check_invalid_script(r"let x = n\u{75}ll;"); } + +#[test] +fn stress_test_operations() { + let src = ("1 * 2 + /* comment why not */ 3 / 4 % 5 + ".repeat(1_000) + + "1; // end of line\n\n") + .repeat(1_000); + + assert!(Parser::new(Source::from_bytes(&src)) + .parse_script(&Scope::new_global(), &mut Interner::default()) + .is_ok()); +}