aboutsummaryrefslogtreecommitdiffstats
path: root/tests/modelica_ast.rs
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-11-30 21:44:52 -0800
committerbnewbold <bnewbold@robocracy.org>2016-11-30 21:44:52 -0800
commit53f703416730ed277cd1b76d886d4256a0063bcb (patch)
tree09ed38b10c5f61016a2e68a21350c9d9c9f6cd4a /tests/modelica_ast.rs
parenta2d795d2ce787841a4f149ccf3ff25b39f73c5b5 (diff)
downloadmodelthing-53f703416730ed277cd1b76d886d4256a0063bcb.tar.gz
modelthing-53f703416730ed277cd1b76d886d4256a0063bcb.zip
move tests from in-file to separate dir
Diffstat (limited to 'tests/modelica_ast.rs')
-rw-r--r--tests/modelica_ast.rs56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/modelica_ast.rs b/tests/modelica_ast.rs
new file mode 100644
index 0000000..b6233f3
--- /dev/null
+++ b/tests/modelica_ast.rs
@@ -0,0 +1,56 @@
+
+extern crate modelthing;
+
+use std::collections::HashSet;
+use std::iter::FromIterator;
+use modelthing::modelica_ast::*;
+
+fn set_eq(a: Vec<String>, b: Vec<String>) -> bool {
+ let set_a: HashSet<String> = HashSet::from_iter(a);
+ let set_b: HashSet<String> = HashSet::from_iter(b);
+ return set_a == set_b;
+}
+
+#[test]
+fn test_expr_identifiers() {
+ use modelthing::modelica_ast::Expr::*;
+
+ assert!(set_eq(
+ vec![],
+ Integer(0).identifiers()));
+ assert!(set_eq(
+ vec!["x".to_string()],
+ Ident("x".to_string()).identifiers()));
+ assert!(set_eq(
+ vec!["x".to_string(), "y".to_string(), "z".to_string()],
+ BinExpr(BinOperator::Add,
+ Box::new(Abs(Box::new(Ident("z".to_string())))),
+ Box::new(BinExpr(BinOperator::Add,
+ Box::new(Abs(Box::new(Ident("x".to_string())))),
+ Box::new(Abs(Box::new(Ident("y".to_string()))))))).identifiers()));
+ assert!(set_eq(
+ vec!["z".to_string()],
+ BinExpr(BinOperator::Add,
+ Box::new(Ident("z".to_string())),
+ Box::new(Ident("z".to_string()))).identifiers()));
+}
+
+#[test]
+fn test_eqn_identifiers() {
+ use modelthing::modelica_ast::Expr::*;
+
+ assert!(set_eq(
+ vec![],
+ SimpleEquation{
+ lhs: Integer(0),
+ rhs: Integer(0),
+ }.identifiers()));
+ assert!(set_eq(
+ vec!["z".to_string()],
+ SimpleEquation{
+ lhs: Ident("z".to_string()),
+ rhs: BinExpr(BinOperator::Add,
+ Box::new(Ident("z".to_string())),
+ Box::new(Ident("z".to_string()))),
+ }.identifiers()));
+}