1
0
dust/dust-lang/tests/scopes.rs

48 lines
1.1 KiB
Rust
Raw Normal View History

2024-08-31 11:24:45 +00:00
use dust_lang::*;
#[test]
fn block_scope_captures_parent() {
let source = "let x = 42; { x }";
assert_eq!(run(source), Ok(Some(Value::integer(42))));
}
#[test]
fn block_scope_does_not_capture_child() {
2024-09-05 15:32:31 +00:00
env_logger::builder().is_test(true).try_init().unwrap();
2024-08-31 11:24:45 +00:00
let source = "{ let x = 42; } x";
assert_eq!(
run(source),
Err(DustError::analysis(
[AnalysisError::UndefinedVariable {
identifier: Node::new(Identifier::new("x"), (16, 17))
}],
source
))
);
}
#[test]
fn block_scope_does_not_capture_sibling() {
let source = "{ let x = 42; } { x }";
assert_eq!(
run(source),
Err(DustError::analysis(
[AnalysisError::UndefinedVariable {
identifier: Node::new(Identifier::new("x"), (18, 19))
}],
source
))
);
}
#[test]
fn block_scope_does_not_pollute_parent() {
let source = "let x = 42; { let x = \"foo\"; let x = \"bar\"; } x";
assert_eq!(run(source), Ok(Some(Value::integer(42))));
}