1
0
dust/tests/enums.rs

82 lines
1.4 KiB
Rust
Raw Normal View History

2024-03-18 20:00:04 +00:00
use dust_lang::{
abstract_tree::Type,
error::{Error, TypeConflict, ValidationError},
*,
};
2024-03-18 16:21:42 +00:00
#[test]
2024-03-18 20:00:04 +00:00
fn simple_enum_type_check() {
assert_eq!(
interpret(
"
enum FooBar {
Foo(int),
Bar,
}
foo = FooBar::Foo('yo')
foo
",
),
Err(vec![Error::Validation {
error: ValidationError::TypeCheck {
conflict: TypeConflict {
actual: Type::String,
expected: Type::Integer,
},
2024-03-18 20:52:09 +00:00
actual_position: (123, 127).into(),
expected_position: (47, 50).into()
2024-03-18 20:00:04 +00:00
},
2024-03-18 20:52:09 +00:00
position: (105, 141).into()
2024-03-18 20:00:04 +00:00
}])
)
}
#[test]
fn simple_enum() {
interpret(
"
enum FooBar {
Foo(int),
Bar,
}
foo = FooBar::Foo(1)
foo
",
)
.unwrap();
}
#[test]
fn simple_enum_with_type_argument() {
2024-03-18 16:21:42 +00:00
interpret(
"
enum FooBar(F) {
Foo(F),
Bar,
}
2024-03-18 20:00:04 +00:00
foo = FooBar(int)::Foo(1)
2024-03-18 16:21:42 +00:00
foo
",
)
.unwrap();
}
2024-03-18 20:00:04 +00:00
#[test]
fn complex_enum_with_type_arguments() {
interpret(
"
enum FooBar(F, B) {
Foo(F),
Bar(B),
}
bar = FooBar(int, str)::Bar('bar')
bar
",
)
.unwrap();
}