1
0
dust/tests/structs.rs

56 lines
1.0 KiB
Rust
Raw Normal View History

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>
}
new Foo {
baz = 'hiya'
}
",
);
let mut map = Map::new();
map.set("bar".to_string(), Value::Integer(0));
map.set("baz".to_string(), Value::String("hiya".to_string()));
let expected = Ok(Value::Struct(StructInstance::new("Foo".to_string(), map)));
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 {}
new Foo {
bar = new Bar {}
}
",
);
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(
"bar".to_string(),
Value::Struct(StructInstance::new("Bar".to_string(), Map::new())),
);
2024-02-15 05:53:43 +00:00
2024-02-15 05:58:14 +00:00
let expected = Ok(Value::Struct(StructInstance::new(
"Foo".to_string(),
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
}