1
0

Pass tests

This commit is contained in:
Jeff 2024-03-08 21:05:56 -05:00
parent 62185ff087
commit 05c9e70d49
2 changed files with 14 additions and 4 deletions

View File

@ -50,7 +50,17 @@ impl AbstractTree for ValueNode {
Ok(r#type) Ok(r#type)
} }
fn validate(&self, _context: &Context) -> Result<(), ValidationError> { fn validate(&self, context: &Context) -> Result<(), ValidationError> {
if let ValueNode::Map(map_assignments) = self {
for (_identifier, r#type, expression) in map_assignments {
if let Some(expected_type) = r#type {
let actual_type = expression.expected_type(context)?;
expected_type.check(&actual_type)?;
}
}
}
Ok(()) Ok(())
} }

View File

@ -126,7 +126,7 @@ fn map_types() {
map.insert(Identifier::new("foo"), Value::string("bar".to_string())); map.insert(Identifier::new("foo"), Value::string("bar".to_string()));
assert_eq!( assert_eq!(
interpret("{ x <int> = 1, foo <str> = 'bar' }"), interpret("{ x : int = 1, foo : str = 'bar' }"),
Ok(Some(Value::map(map))) Ok(Some(Value::map(map)))
); );
} }
@ -134,13 +134,13 @@ fn map_types() {
#[test] #[test]
fn map_type_errors() { fn map_type_errors() {
assert_eq!( assert_eq!(
interpret("{ foo <bool> = 'bar' }"), interpret("{ foo : bool = 'bar' }"),
Err(vec![Error::Validation { Err(vec![Error::Validation {
error: ValidationError::TypeCheck(TypeCheckError { error: ValidationError::TypeCheck(TypeCheckError {
actual: Type::String, actual: Type::String,
expected: Type::Boolean expected: Type::Boolean
}), }),
span: (0..0).into() span: (0..22).into()
}]) }])
); );
} }