use insta::assert_snapshot;
use monty::MontyRun;
use monty_types::CompileOptions;
#[test]
fn deeply_nested_parentheses_do_not_stack_overflow() {
let depth = 5000;
let mut code = String::with_capacity(depth * 2 + 1);
for _ in 0..depth {
code.push('(');
}
code.push('1');
for _ in 0..depth {
code.push(')');
}
let result = MontyRun::new(code, "test.py", vec![], CompileOptions::default());
let err = result.expect_err("expected parse error for deeply nested parentheses");
assert_snapshot!(err.message().unwrap_or(""), @"Source is too deeply nested");
}
#[test]
fn deeply_nested_attribute_access_does_not_stack_overflow() {
let depth = 200;
let mut code = String::with_capacity(depth * 2 + 1);
code.push('a');
for _ in 0..depth {
code.push_str(".x");
}
let result = MontyRun::new(code, "test.py", vec![], CompileOptions::default());
let err = result.expect_err("expected parse error for deeply nested attribute access");
assert_snapshot!(err.message().unwrap_or(""), @"Source is too deeply nested");
}