mirror of
https://github.com/BrianHicks/elm-duet.git
synced 2024-09-11 13:45:23 +03:00
add a function returning void
This commit is contained in:
parent
6337bfb47c
commit
514716e9b3
@ -7,6 +7,8 @@ pub enum TSType {
|
||||
Scalar(&'static str),
|
||||
StringScalar(String),
|
||||
Union(Vec<TSType>),
|
||||
/// We never need return values in interop, so everything can be void!
|
||||
FunctionReturningVoid(BTreeMap<String, TSType>),
|
||||
}
|
||||
|
||||
impl TSType {
|
||||
@ -59,10 +61,26 @@ impl TSType {
|
||||
out.push_str(&type_.to_source())
|
||||
}
|
||||
}
|
||||
Self::FunctionReturningVoid(args) => {
|
||||
out.push('(');
|
||||
for (i, (name, type_)) in args.iter().enumerate() {
|
||||
if i != 0 {
|
||||
out.push_str(", ");
|
||||
}
|
||||
out.push_str(name);
|
||||
out.push_str(": ");
|
||||
out.push_str(&type_.to_source());
|
||||
}
|
||||
out.push_str("): void");
|
||||
}
|
||||
}
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
fn new_function(args: BTreeMap<String, TSType>) -> Self {
|
||||
Self::FunctionReturningVoid(args)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -114,4 +132,17 @@ mod tests {
|
||||
|
||||
assert_eq!(type_.to_source(), "\"a\" | \"b\"".to_string())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_function() {
|
||||
let type_ = TSType::new_function(BTreeMap::from([
|
||||
("one".to_string(), TSType::Scalar("number")),
|
||||
("two".to_string(), TSType::Scalar("string")),
|
||||
]));
|
||||
|
||||
assert_eq!(
|
||||
type_.to_source(),
|
||||
"(one: number, two: string): void".to_string()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user