diff options
Diffstat (limited to 'modelica-parser-lalrpop/tests/ast.rs')
-rw-r--r-- | modelica-parser-lalrpop/tests/ast.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/modelica-parser-lalrpop/tests/ast.rs b/modelica-parser-lalrpop/tests/ast.rs new file mode 100644 index 0000000..f9047cb --- /dev/null +++ b/modelica-parser-lalrpop/tests/ast.rs @@ -0,0 +1,56 @@ + +extern crate modelica_parser; + +use std::collections::HashSet; +use std::iter::FromIterator; +use modelica_parser::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 modelica_parser::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 modelica_parser::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())); +} |