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(
|
2024-02-15 21:02:27 +00:00
|
|
|
Identifier::new("Foobar"),
|
|
|
|
Identifier::new("Foo"),
|
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(
|
2024-02-15 21:02:27 +00:00
|
|
|
Identifier::new("Foobar"),
|
|
|
|
Identifier::new("Bar"),
|
2024-02-15 15:33:25 +00:00
|
|
|
Some(Value::Enum(EnumInstance::new(
|
2024-02-15 21:02:27 +00:00
|
|
|
Identifier::new("Fizzbuzz"),
|
|
|
|
Identifier::new("Fizz"),
|
2024-02-15 15:33:25 +00:00
|
|
|
Some(Value::none())
|
|
|
|
)))
|
2024-02-15 03:46:14 +00:00
|
|
|
)))
|
|
|
|
);
|
|
|
|
}
|