Pass enum tests

This commit is contained in:
Jeff 2024-02-19 11:13:04 -05:00
parent 37fd722fa6
commit 0eac67eb3a
3 changed files with 21 additions and 5 deletions

View File

@ -100,12 +100,14 @@ impl AbstractTree for For {
if let Value::Range(range) = expression_run {
if self.is_async {
range.into_par_iter().try_for_each(|integer| {
self.context.add_allowance(key)?;
self.context
.set_value(key.clone(), Value::Integer(integer))?;
self.block.run(source, &self.context).map(|_value| ())
})?;
} else {
for i in range {
self.context.add_allowance(key)?;
self.context.set_value(key.clone(), Value::Integer(i))?;
self.block.run(source, &self.context)?;
}
@ -117,6 +119,7 @@ impl AbstractTree for For {
if let Value::List(list) = &expression_run {
if self.is_async {
list.items()?.par_iter().try_for_each(|value| {
self.context.add_allowance(key)?;
self.context.set_value(key.clone(), value.clone())?;
self.block.run(source, &self.context).map(|_value| ())
})?;

View File

@ -179,6 +179,13 @@ impl AbstractTree for ValueNode {
}
}
ValueNode::Map(map_node) => map_node.validate(_source, context)?,
ValueNode::Enum { name, variant, expression } => {
name.validate(_source, context)?;
if let Some(expression) = expression {
expression.validate(_source, context)?;
}
}
_ => {},
}

View File

@ -56,24 +56,30 @@ fn nested_enum() {
#[test]
fn enum_with_argument() {
env_logger::builder().is_test(true).try_init().unwrap();
let result = interpret(
"
enum FooBar<T> {
Foo<T>,
Bar,
Foo<T>
Bar
}
enum FizzBuzz {
Fizz
Buzz
}
Foobar::Bar(Fizzbuzz::Fizz)
FooBar::Bar(FizzBuzz::Fizz)
",
);
assert_eq!(
result,
Ok(Value::Enum(EnumInstance::new(
Identifier::new("Foobar"),
Identifier::new("FooBar"),
Identifier::new("Bar"),
Some(Value::Enum(EnumInstance::new(
Identifier::new("Fizzbuzz"),
Identifier::new("FizzBuzz"),
Identifier::new("Fizz"),
Some(Value::none())
)))