1
0

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 let Value::Range(range) = expression_run {
if self.is_async { if self.is_async {
range.into_par_iter().try_for_each(|integer| { range.into_par_iter().try_for_each(|integer| {
self.context.add_allowance(key)?;
self.context self.context
.set_value(key.clone(), Value::Integer(integer))?; .set_value(key.clone(), Value::Integer(integer))?;
self.block.run(source, &self.context).map(|_value| ()) self.block.run(source, &self.context).map(|_value| ())
})?; })?;
} else { } else {
for i in range { for i in range {
self.context.add_allowance(key)?;
self.context.set_value(key.clone(), Value::Integer(i))?; self.context.set_value(key.clone(), Value::Integer(i))?;
self.block.run(source, &self.context)?; self.block.run(source, &self.context)?;
} }
@ -117,6 +119,7 @@ impl AbstractTree for For {
if let Value::List(list) = &expression_run { if let Value::List(list) = &expression_run {
if self.is_async { if self.is_async {
list.items()?.par_iter().try_for_each(|value| { list.items()?.par_iter().try_for_each(|value| {
self.context.add_allowance(key)?;
self.context.set_value(key.clone(), value.clone())?; self.context.set_value(key.clone(), value.clone())?;
self.block.run(source, &self.context).map(|_value| ()) 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::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] #[test]
fn enum_with_argument() { fn enum_with_argument() {
env_logger::builder().is_test(true).try_init().unwrap();
let result = interpret( let result = interpret(
" "
enum FooBar<T> { enum FooBar<T> {
Foo<T>, Foo<T>
Bar, Bar
}
enum FizzBuzz {
Fizz
Buzz
} }
Foobar::Bar(Fizzbuzz::Fizz) FooBar::Bar(FizzBuzz::Fizz)
", ",
); );
assert_eq!( assert_eq!(
result, result,
Ok(Value::Enum(EnumInstance::new( Ok(Value::Enum(EnumInstance::new(
Identifier::new("Foobar"), Identifier::new("FooBar"),
Identifier::new("Bar"), Identifier::new("Bar"),
Some(Value::Enum(EnumInstance::new( Some(Value::Enum(EnumInstance::new(
Identifier::new("Fizzbuzz"), Identifier::new("FizzBuzz"),
Identifier::new("Fizz"), Identifier::new("Fizz"),
Some(Value::none()) Some(Value::none())
))) )))