2024-02-15 01:53:42 +00:00
|
|
|
use dust_lang::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn simple_enum() {
|
|
|
|
let result = interpret(
|
|
|
|
"
|
|
|
|
enum Foobar {
|
|
|
|
Foo,
|
|
|
|
Bar,
|
|
|
|
}
|
|
|
|
|
|
|
|
new Foobar:Foo
|
|
|
|
",
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
result,
|
2024-02-15 03:38:45 +00:00
|
|
|
Ok(Value::Enum(EnumInstance::new(
|
|
|
|
"Foobar".to_string(),
|
|
|
|
"Foo".to_string(),
|
2024-02-15 15:33:25 +00:00
|
|
|
Some(Value::none())
|
2024-02-15 03:38:45 +00:00
|
|
|
)))
|
2024-02-15 01:53:42 +00:00
|
|
|
);
|
|
|
|
}
|
2024-02-15 03:46:14 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn nested_enum() {
|
|
|
|
let result = interpret(
|
|
|
|
"
|
|
|
|
enum Fizzbuzz {
|
|
|
|
Fizz,
|
|
|
|
Buzz,
|
|
|
|
}
|
|
|
|
enum Foobar {
|
|
|
|
Foo,
|
|
|
|
Bar(Fizzbuzz),
|
|
|
|
}
|
|
|
|
|
|
|
|
new Foobar:Bar(new Fizzbuzz:Fizz)
|
|
|
|
",
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
result,
|
|
|
|
Ok(Value::Enum(EnumInstance::new(
|
|
|
|
"Foobar".to_string(),
|
|
|
|
"Bar".to_string(),
|
2024-02-15 15:33:25 +00:00
|
|
|
Some(Value::Enum(EnumInstance::new(
|
2024-02-15 03:46:14 +00:00
|
|
|
"Fizzbuzz".to_string(),
|
|
|
|
"Fizz".to_string(),
|
2024-02-15 15:33:25 +00:00
|
|
|
Some(Value::none())
|
|
|
|
)))
|
2024-02-15 03:46:14 +00:00
|
|
|
)))
|
|
|
|
);
|
|
|
|
}
|