1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
extern crate modelica_parser;
use std::collections::HashSet;
use std::iter::FromIterator;
use modelica_parser::*;
#[test]
fn test_expr_identifiers() {
use modelica_parser::Expr::*;
assert_eq!(
HashSet::new(),
Integer(0).identifiers());
assert_eq!(
HashSet::from_iter(vec!["x".to_string()]),
Ident("x".to_string()).identifiers());
assert_eq!(
HashSet::from_iter(vec!["x".to_string(), "y".to_string(), "z".to_string()]),
BinExpr(BinOperator::Add,
Box::new(Sign(Box::new(Ident("z".to_string())))),
Box::new(BinExpr(BinOperator::Add,
Box::new(Sign(Box::new(Ident("x".to_string())))),
Box::new(Sign(Box::new(Ident("y".to_string()))))))).identifiers());
assert_eq!(
HashSet::from_iter(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::Expr::*;
assert_eq!(
HashSet::new(),
SimpleEquation{
lhs: Integer(0),
rhs: Integer(0),
}.identifiers());
assert_eq!(
HashSet::from_iter(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());
}
|