1
0
dust/tests/enums.rs

89 lines
1.7 KiB
Rust
Raw Permalink 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,
2024-02-18 20:44:57 +00:00
Bar<Fizzbuzz>,
2024-02-15 03:46:14 +00:00
}
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
)))
);
}
2024-02-18 21:43:47 +00:00
#[test]
fn enum_with_argument() {
2024-02-19 16:13:04 +00:00
env_logger::builder().is_test(true).try_init().unwrap();
2024-02-18 21:43:47 +00:00
let result = interpret(
"
enum FooBar<T> {
2024-02-19 16:13:04 +00:00
Foo<T>
Bar
}
enum FizzBuzz {
Fizz
Buzz
2024-02-18 21:43:47 +00:00
}
2024-02-19 16:13:04 +00:00
FooBar::Bar(FizzBuzz::Fizz)
2024-02-18 21:43:47 +00:00
",
);
assert_eq!(
result,
Ok(Value::Enum(EnumInstance::new(
2024-02-19 16:13:04 +00:00
Identifier::new("FooBar"),
2024-02-18 21:43:47 +00:00
Identifier::new("Bar"),
Some(Value::Enum(EnumInstance::new(
2024-02-19 16:13:04 +00:00
Identifier::new("FizzBuzz"),
2024-02-18 21:43:47 +00:00
Identifier::new("Fizz"),
Some(Value::none())
)))
)))
);
}