1
0
dust/tests/enums.rs

56 lines
1016 B
Rust
Raw Normal View History

2024-02-15 01:53:42 +00:00
use dust_lang::*;
#[test]
fn simple_enum() {
let result = interpret(
"
enum Foobar {
Foo,
Bar,
}
2024-02-18 15:19:38 +00:00
Foobar::Foo
2024-02-15 01:53:42 +00:00
",
);
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),
}
2024-02-18 15:19:38 +00:00
Foobar::Bar(Fizzbuzz::Fizz)
2024-02-15 03:46:14 +00:00
",
);
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
)))
);
}