From ce0ca17beb924abad83e0f36f50309f713559e28 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 30 Jan 2024 00:24:13 -0500 Subject: [PATCH] Write tests --- tests/for_loop.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/for_loop.rs b/tests/for_loop.rs index 7023062..2352242 100644 --- a/tests/for_loop.rs +++ b/tests/for_loop.rs @@ -26,3 +26,48 @@ fn modify_value() { result ); } + +#[test] +fn modify_iteration_values() { + let result = interpret( + " + list = [1 2 3] + for i in list { i += i } + list + ", + ); + + assert_eq!( + Ok(Value::List(List::with_items(vec![ + Value::Integer(2), + Value::Integer(3), + Value::Integer(4), + ]))), + result + ); +} + +#[test] +fn r#break() { + let result = interpret( + " + list = [] + for i in [1 2 3] { + if i > 2 { + break + } else { + list += i + } + } + list + ", + ); + + assert_eq!( + Ok(Value::List(List::with_items(vec![ + Value::Integer(1), + Value::Integer(2), + ]))), + result + ); +}