From 6c76006ad9c0a0edf30ae3c322dd64b5ccb3d116 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 17 Sep 2024 13:39:12 -0400 Subject: [PATCH] Improve test --- dust-lang/src/parser/mod.rs | 1 - dust-lang/src/parser/tests.rs | 32 +++++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/dust-lang/src/parser/mod.rs b/dust-lang/src/parser/mod.rs index 5a89537..7e5e5db 100644 --- a/dust-lang/src/parser/mod.rs +++ b/dust-lang/src/parser/mod.rs @@ -340,7 +340,6 @@ impl<'src> Parser<'src> { } self.emit_instruction(instruction, operator_position); - self.increment_register()?; Ok(()) diff --git a/dust-lang/src/parser/tests.rs b/dust-lang/src/parser/tests.rs index 583a23f..cf924fa 100644 --- a/dust-lang/src/parser/tests.rs +++ b/dust-lang/src/parser/tests.rs @@ -2,6 +2,11 @@ use crate::Local; use super::*; +#[test] +fn empty() { + assert_eq!(parse(""), Ok(Chunk::with_data(vec![], vec![], vec![])),); +} + #[test] fn set_local() { assert_eq!( @@ -44,24 +49,37 @@ fn parentheses_precedence() { } #[test] -fn add_multiply_precedence() { +fn math_operator_precedence() { assert_eq!( - parse("1 + 2 * 3"), + parse("1 + 2 - 3 * 4 / 5"), Ok(Chunk::with_data( vec![ ( - *Instruction::multiply(0, 1, 2) + *Instruction::multiply(1, 2, 3) .set_first_argument_to_constant() .set_second_argument_to_constant(), - Span(6, 7) + Span(10, 11) ), ( - *Instruction::add(1, 0, 0).set_first_argument_to_constant(), + *Instruction::add(0, 0, 1) + .set_first_argument_to_constant() + .set_second_argument_to_constant(), Span(2, 3) ), - (Instruction::r#return(), Span(0, 9)), + ( + *Instruction::divide(2, 1, 4).set_second_argument_to_constant(), + Span(14, 15) + ), + (Instruction::subtract(3, 0, 2), Span(6, 7)), + (Instruction::r#return(), Span(0, 17)), + ], + vec![ + Value::integer(1), + Value::integer(2), + Value::integer(3), + Value::integer(4), + Value::integer(5), ], - vec![Value::integer(1), Value::integer(2), Value::integer(3)], vec![] )) );