2011-07-27 07:19:39 -05:00
|
|
|
fn test_simple() { let x = true ? 10 : 11; assert (x == 10); }
|
2011-06-23 17:15:50 -05:00
|
|
|
|
|
|
|
fn test_precedence() {
|
2011-07-27 07:19:39 -05:00
|
|
|
let x;
|
2011-06-23 17:15:50 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
x = true || true ? 10 : 11;
|
|
|
|
assert (x == 10);
|
2011-06-24 01:27:32 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
x = true == false ? 10 : 11;
|
|
|
|
assert (x == 11);
|
2011-06-23 17:15:50 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
x = true ? false ? 10 : 11 : 12;
|
|
|
|
assert (x == 11);
|
2011-06-23 17:15:50 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
let y = true ? 0xF0 : 0x0 | 0x0F;
|
|
|
|
assert (y == 0xF0);
|
2011-06-24 01:27:32 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
y = true ? 0xF0 | 0x0F : 0x0;
|
|
|
|
assert (y == 0xFF);
|
2011-06-23 17:15:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_associativity() {
|
2011-07-27 07:19:39 -05:00
|
|
|
// Ternary is right-associative
|
|
|
|
let x = false ? 10 : false ? 11 : 12;
|
|
|
|
assert (x == 12);
|
2011-06-23 17:15:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_lval() {
|
2011-07-27 07:19:39 -05:00
|
|
|
let box1: @mutable int = @mutable 10;
|
|
|
|
let box2: @mutable int = @mutable 10;
|
|
|
|
*(true ? box1 : box2) = 100;
|
|
|
|
assert (*box1 == 100);
|
2011-06-23 17:15:50 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn test_as_stmt() { let s; true ? s = 10 : s = 12; assert (s == 10); }
|
2011-06-23 17:15:50 -05:00
|
|
|
|
|
|
|
fn main() {
|
2011-07-27 07:19:39 -05:00
|
|
|
test_simple();
|
|
|
|
test_precedence();
|
|
|
|
test_associativity();
|
|
|
|
test_lval();
|
|
|
|
test_as_stmt();
|
2011-06-23 17:15:50 -05:00
|
|
|
}
|