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() + }]) + ); +}