rust/src/test/run-pass/ternary.rs
Brian Anderson c53402846e Remove all xfail-stage0 directives
While it is still technically possible to test stage 0, it is not part of any
of the main testing rules and maintaining xfail-stage0 is a chore. Nobody
should worry about how tests fare in stage0.
2011-08-03 10:55:59 -07:00

43 lines
877 B
Rust

fn test_simple() { let x = true ? 10 : 11; assert (x == 10); }
fn test_precedence() {
let x;
x = true || true ? 10 : 11;
assert (x == 10);
x = true == false ? 10 : 11;
assert (x == 11);
x = true ? false ? 10 : 11 : 12;
assert (x == 11);
let y = true ? 0xF0 : 0x0 | 0x0F;
assert (y == 0xF0);
y = true ? 0xF0 | 0x0F : 0x0;
assert (y == 0xFF);
}
fn test_associativity() {
// Ternary is right-associative
let x = false ? 10 : false ? 11 : 12;
assert (x == 12);
}
fn test_lval() {
let box1: @mutable int = @mutable 10;
let box2: @mutable int = @mutable 10;
*(true ? box1 : box2) = 100;
assert (*box1 == 100);
}
fn test_as_stmt() { let s; true ? s = 10 : s = 12; assert (s == 10); }
fn main() {
test_simple();
test_precedence();
test_associativity();
test_lval();
test_as_stmt();
}