Add and pass test

This commit is contained in:
Jeff 2024-03-06 23:21:07 -05:00
parent fdf6983ab2
commit 65d2fd3270
2 changed files with 29 additions and 3 deletions

View File

@ -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)))
}),
))

View File

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