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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use crate::opath::Expr::*;
#[test]
fn mul_add() {
assert_expr!("3 * 2 + 2",
Add(
Box::new(Mul(
Box::new(Integer(3)),
Box::new(Integer(2))
)),
Box::new(Integer(2))
)
)
}
#[test]
fn and_neg() {
assert_expr!("2 and 2 - 2",
And(
Box::new(Integer(2)),
Box::new(Sub(
Box::new(Integer(2)),
Box::new(Integer(2))
)),
)
)
}
#[test]
fn neg_mul() {
assert_expr!("-2 * 2",
Mul(
Box::new(Integer(-2)),
Box::new(Integer(2))
)
)
}
#[test]
fn neg_div() {
assert_expr!("-2 / 2",
Div(
Box::new(Integer(-2)),
Box::new(Integer(2))
)
)
}
#[test]
fn eq_not() {
assert_expr!("2 == !2",
Eq(
Box::new(Integer(2)),
Box::new(Boolean(false))
)
)
}
#[test]
fn ne_not() {
assert_expr!("2 != !2",
Ne(
Box::new(Integer(2)),
Box::new(Boolean(false))
)
)
}
#[test]
fn lt_not() {
assert_expr!("2 < !2",
Lt(
Box::new(Integer(2)),
Box::new(Boolean(false))
)
)
}
#[test]
fn le_not() {
assert_expr!("2 <= !2",
Le(
Box::new(Integer(2)),
Box::new(Boolean(false))
)
)
}
#[test]
fn gt_not() {
assert_expr!("2 > !2",
Gt(
Box::new(Integer(2)),
Box::new(Boolean(false))
)
)
}
#[test]
fn ge_not() {
assert_expr!("2 >= !2",
Ge(
Box::new(Integer(2)),
Box::new(Boolean(false))
)
)
}
#[test]
fn not_and() {
assert_expr!("!2 and 2",
And(
Box::new(Boolean(false)),
Box::new(Integer(2)),
)
)
}
#[test]
fn or_and() {
assert_expr!("!2 or 2",
Or(
Box::new(Boolean(false)),
Box::new(Integer(2)),
)
)
}