Begin implementing and testing type defintions

This commit is contained in:
Jeff 2024-01-23 15:35:26 -05:00
parent 6c4efadb10
commit bdef5db051
2 changed files with 44 additions and 0 deletions

View File

@ -32,6 +32,25 @@ impl Map {
}
}
pub fn from_structure(structure: Structure) -> Self {
let mut variables = BTreeMap::new();
for (key, (value_option, r#type)) in structure.inner() {
variables.insert(
key.clone(),
(
value_option.clone().unwrap_or(Value::none()),
r#type.clone(),
),
);
}
Map {
variables: Arc::new(RwLock::new(variables)),
structure: Some(structure),
}
}
pub fn with_variables(variables: BTreeMap<String, (Value, Type)>) -> Self {
Map {
variables: Arc::new(RwLock::new(variables)),

View File

@ -16,3 +16,28 @@ fn simple_structure() {
assert_eq!(expected, result);
}
#[test]
fn new_structure() {
let result = interpret(
"
Coords = struct {
x <float> = 0.0
x <float> = 0.0
}
new Coords {
x = 1.5
y = 4.2
}
",
);
let mut map = BTreeMap::new();
map.insert("x".to_string(), (Some(Value::Integer(0)), Type::Integer));
let expected = Value::Map(Map::from_structure(Structure::new(map)));
assert_eq!(Ok(expected), result);
}