2024-02-15 05:53:43 +00:00
|
|
|
use dust_lang::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn simple_struct() {
|
|
|
|
let result = interpret(
|
|
|
|
"
|
|
|
|
struct Foo {
|
|
|
|
bar <int> = 0
|
|
|
|
baz <str>
|
|
|
|
}
|
|
|
|
|
2024-02-18 15:34:59 +00:00
|
|
|
Foo::{
|
2024-02-15 05:53:43 +00:00
|
|
|
baz = 'hiya'
|
|
|
|
}
|
|
|
|
",
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut map = Map::new();
|
|
|
|
|
2024-02-15 21:02:27 +00:00
|
|
|
map.set(Identifier::new("bar"), Value::Integer(0));
|
|
|
|
map.set(Identifier::new("baz"), Value::String("hiya".to_string()));
|
2024-02-15 05:53:43 +00:00
|
|
|
|
2024-02-15 21:02:27 +00:00
|
|
|
let expected = Ok(Value::Struct(StructInstance::new(
|
|
|
|
Identifier::new("Foo"),
|
|
|
|
map,
|
|
|
|
)));
|
2024-02-15 05:53:43 +00:00
|
|
|
|
|
|
|
assert_eq!(result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn nested_struct() {
|
2024-02-15 05:58:14 +00:00
|
|
|
let result = interpret(
|
2024-02-15 05:53:43 +00:00
|
|
|
"
|
|
|
|
struct Foo {
|
|
|
|
bar <Bar>
|
|
|
|
}
|
|
|
|
struct Bar {}
|
|
|
|
|
2024-02-18 15:34:59 +00:00
|
|
|
Foo::{
|
|
|
|
bar = Bar::{}
|
2024-02-15 05:53:43 +00:00
|
|
|
}
|
|
|
|
",
|
|
|
|
);
|
2024-02-15 05:58:14 +00:00
|
|
|
let mut foo_map = Map::new();
|
2024-02-15 05:53:43 +00:00
|
|
|
|
2024-02-15 05:58:14 +00:00
|
|
|
foo_map.set(
|
2024-02-15 21:02:27 +00:00
|
|
|
Identifier::new("bar"),
|
|
|
|
Value::Struct(StructInstance::new(Identifier::new("Bar"), Map::new())),
|
2024-02-15 05:58:14 +00:00
|
|
|
);
|
2024-02-15 05:53:43 +00:00
|
|
|
|
2024-02-15 05:58:14 +00:00
|
|
|
let expected = Ok(Value::Struct(StructInstance::new(
|
2024-02-15 21:02:27 +00:00
|
|
|
Identifier::new("Foo"),
|
2024-02-15 05:58:14 +00:00
|
|
|
foo_map,
|
|
|
|
)));
|
2024-02-15 05:53:43 +00:00
|
|
|
|
2024-02-15 05:58:14 +00:00
|
|
|
assert_eq!(result, expected)
|
2024-02-15 05:53:43 +00:00
|
|
|
}
|