-
Notifications
You must be signed in to change notification settings - Fork 260
/
Copy pathmain.nr
55 lines (44 loc) · 1.91 KB
/
main.nr
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
fn main() {
comptime
{
// Check Expr::as_function_call
let expr = quote { foo(bar) }.as_expr().unwrap();
let (_function, args) = expr.as_function_call().unwrap();
assert_eq(args.len(), 1);
// Check Expr::as_index
let expr = quote { foo[bar] }.as_expr().unwrap();
let _ = expr.as_index().unwrap();
// Check Expr::as_tuple
let expr = quote { (1, 2) }.as_expr().unwrap();
let tuple_exprs = expr.as_tuple().unwrap();
assert_eq(tuple_exprs.len(), 2);
// Check Expr::as_if
let expr = quote { if 1 { 2 } }.as_expr().unwrap();
let (_condition, _consequence, alternative) = expr.as_if().unwrap();
assert(alternative.is_none());
let expr = quote { if 1 { 2 } else { 3 } }.as_expr().unwrap();
let (_condition, _consequence, alternative) = expr.as_if().unwrap();
assert(alternative.is_some());
// Check parenthesized expression is automatically unwrapped
let expr = quote { ((if 1 { 2 })) }.as_expr().unwrap();
assert(expr.as_if().is_some());
// Check Expr::as_bool
let expr = quote { false }.as_expr().unwrap();
assert(expr.as_bool().unwrap() == false);
let expr = quote { true }.as_expr().unwrap();
assert_eq(expr.as_bool().unwrap(), true);
// Check Expr::as_unary_op
let expr = quote { -x }.as_expr().unwrap();
let (op, _) = expr.as_unary_op().unwrap();
assert(op.is_minus());
let expr = quote { !x }.as_expr().unwrap();
let (op, _) = expr.as_unary_op().unwrap();
assert(op.is_not());
let expr = quote { &mut x }.as_expr().unwrap();
let (op, _) = expr.as_unary_op().unwrap();
assert(op.is_mutable_reference());
let expr = quote { *x }.as_expr().unwrap();
let (op, _) = expr.as_unary_op().unwrap();
assert(op.is_dereference());
}
}