From 65d2fd3270b25692a7eb5bcb4b87fd46b20bc970 Mon Sep 17 00:00:00 2001 From: Jeff Date: Wed, 6 Mar 2024 23:21:07 -0500 Subject: [PATCH] Add and pass test --- src/parser.rs | 4 ++-- tests/variables.rs | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index c090ccd..f97749a 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -107,10 +107,10 @@ pub fn parser<'src>() -> DustParser<'src> { infix(left(1), just(Token::Operator("<=")), |left, right| { Expression::Logic(Box::new(Logic::LessOrEqual(left, right))) }), - infix(right(1), just(Token::Operator("&&")), |left, right| { + infix(left(1), just(Token::Operator("&&")), |left, right| { Expression::Logic(Box::new(Logic::And(left, right))) }), - infix(right(1), just(Token::Operator("||")), |left, right| { + infix(left(1), just(Token::Operator("||")), |left, right| { Expression::Logic(Box::new(Logic::Or(left, right))) }), )) diff --git a/tests/variables.rs b/tests/variables.rs index 00cf89f..b41fe46 100644 --- a/tests/variables.rs +++ b/tests/variables.rs @@ -1,6 +1,32 @@ -use dust_lang::*; +use dust_lang::{ + abstract_tree::Type, + error::{Error, TypeCheckError, ValidationError}, + *, +}; #[test] fn set_and_get_variable() { assert_eq!(interpret("foobar = true; foobar"), Ok(Value::boolean(true))); } + +#[test] +fn set_variable_with_type() { + assert_eq!( + interpret("foobar: bool = true; foobar"), + Ok(Value::boolean(true)) + ); +} + +#[test] +fn set_variable_with_type_error() { + assert_eq!( + interpret("foobar: str = true"), + Err(vec![Error::Validation { + error: ValidationError::TypeCheck(TypeCheckError { + actual: Type::Boolean, + expected: Type::String + }), + span: (0..18).into() + }]) + ); +}