From a1dd7e3bb9a599f0d117752e02cb7833312a8168 Mon Sep 17 00:00:00 2001 From: Jeff Date: Wed, 18 Sep 2024 20:08:02 -0400 Subject: [PATCH] Add if/else test --- dust-lang/src/parser/tests.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/dust-lang/src/parser/tests.rs b/dust-lang/src/parser/tests.rs index 4cdce4f..d08ca85 100644 --- a/dust-lang/src/parser/tests.rs +++ b/dust-lang/src/parser/tests.rs @@ -2,6 +2,36 @@ use crate::Local; use super::*; +#[test] +fn if_else_expression() { + let source = "if 1 == 1 { 2 } else { 3 }"; + + assert_eq!( + parse(source), + Ok(Chunk::with_data( + vec![ + ( + *Instruction::equal(true, 0, 1) + .set_first_argument_to_constant() + .set_second_argument_to_constant(), + Span(5, 7) + ), + (Instruction::jump(1, true), Span(5, 7)), + (Instruction::load_constant(0, 2), Span(12, 13)), + (Instruction::load_constant(1, 3), Span(23, 24)), + (Instruction::r#return(), Span(0, 26)), + ], + vec![ + Value::integer(1), + Value::integer(1), + Value::integer(2), + Value::integer(3) + ], + vec![] + )), + ); +} + #[test] fn list_with_expression() { let source = "[1, 2 + 3, 4]";