PageRenderTime 19ms CodeModel.GetById 1ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/run-pass/expr-if.rs

http://github.com/jruderman/rust
Rust | 55 lines | 41 code | 12 blank | 2 comment | 30 complexity | 7145a1048792703e3d873a546cec09b5 MD5 | raw file
 1
 2
 3
 4// -*- rust -*-
 5
 6// Tests for if as expressions
 7fn test_if() { let rs: bool = if true { true } else { false }; assert (rs); }
 8
 9fn test_else() {
10    let rs: bool = if false { false } else { true };
11    assert (rs);
12}
13
14fn test_elseif1() {
15    let rs: bool = if true { true } else if true { false } else { false };
16    assert (rs);
17}
18
19fn test_elseif2() {
20    let rs: bool = if false { false } else if true { true } else { false };
21    assert (rs);
22}
23
24fn test_elseif3() {
25    let rs: bool = if false { false } else if false { false } else { true };
26    assert (rs);
27}
28
29fn test_inferrence() {
30    let rs = if true { true } else { false };
31    assert (rs);
32}
33
34fn test_if_as_if_condition() {
35    let rs1 = if if false { false } else { true } { true } else { false };
36    assert (rs1);
37    let rs2 = if if true { false } else { true } { false } else { true };
38    assert (rs2);
39}
40
41fn test_if_as_block_result() {
42    let rs = if true { if false { false } else { true } } else { false };
43    assert (rs);
44}
45
46fn main() {
47    test_if();
48    test_else();
49    test_elseif1();
50    test_elseif2();
51    test_elseif3();
52    test_inferrence();
53    test_if_as_if_condition();
54    test_if_as_block_result();
55}