From 0e3a3e94c899ae8944aed5f4932d6886324ed63d Mon Sep 17 00:00:00 2001 From: Jeff Date: Sun, 11 Aug 2024 22:47:52 -0400 Subject: [PATCH] Add context tests --- dust-lang/src/context.rs | 50 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/dust-lang/src/context.rs b/dust-lang/src/context.rs index 61faea7..27b2d70 100644 --- a/dust-lang/src/context.rs +++ b/dust-lang/src/context.rs @@ -143,4 +143,54 @@ mod tests { assert_eq!(context.variables.len(), 1); } + + #[test] + fn context_removes_used_variables() { + let source = " + x = 5 + y = 10 + z = x + y + z + "; + let mut context = Context::new(); + + run_with_context(source, &mut context).unwrap(); + + assert_eq!(context.variables.len(), 0); + } + + #[test] + fn context_does_not_remove_variables_during_loop() { + let source = " + x = 5 + y = 10 + z = x + y + while z < 10 { + z = z + 1 + } + "; + let mut context = Context::new(); + + run_with_context(source, &mut context).unwrap(); + + assert_eq!(context.variables.len(), 1); + } + + #[test] + fn context_removes_variables_after_loop() { + let source = " + x = 5 + y = 10 + z = x + y + while z < 10 { + z = z + 1 + } + z + "; + let mut context = Context::new(); + + run_with_context(source, &mut context).unwrap(); + + assert_eq!(context.variables.len(), 0); + } }