From c1eccf049f5f2d1e4d900fc8c0177e9897bff4e2 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 24 Sep 2024 12:03:12 -0400 Subject: [PATCH] Add list test --- dust-lang/src/parser/tests.rs | 40 ++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/dust-lang/src/parser/tests.rs b/dust-lang/src/parser/tests.rs index 3afd8da..aa47a84 100644 --- a/dust-lang/src/parser/tests.rs +++ b/dust-lang/src/parser/tests.rs @@ -302,7 +302,45 @@ fn if_else_expression() { } #[test] -fn list_with_expression() { +fn list_with_complex_expression() { + let source = "[1, 2 + 3 - 4 * 5]"; + + assert_eq!( + parse(source), + Ok(Chunk::with_data( + vec![ + (Instruction::load_constant(0, 0), Span(1, 2)), + ( + *Instruction::add(1, 1, 2) + .set_first_argument_to_constant() + .set_second_argument_to_constant(), + Span(6, 7) + ), + ( + *Instruction::multiply(2, 3, 4) + .set_first_argument_to_constant() + .set_second_argument_to_constant(), + Span(14, 15) + ), + (Instruction::subtract(3, 1, 2), Span(10, 11)), + (Instruction::close(1, 3), Span(17, 18)), + (Instruction::load_list(4, 0, 2), Span(0, 18)), + (Instruction::end(true), Span(18, 18)), + ], + vec![ + Value::integer(1), + Value::integer(2), + Value::integer(3), + Value::integer(4), + Value::integer(5) + ], + vec![] + )), + ); +} + +#[test] +fn list_with_simple_expression() { let source = "[1, 2 + 3, 4]"; assert_eq!(