Removed C style flow control
This commit is contained in:
@@ -99,17 +99,17 @@ pub fn test_block_expr() {
|
||||
}
|
||||
|
||||
pub fn test_if_expr() {
|
||||
let x = if (true) { 1 } else { 2 };
|
||||
let x = if true { 1 } else { 2 };
|
||||
assert_eq!(x, 1);
|
||||
|
||||
let y = if (false) { 1 } else { 2 };
|
||||
let y = if false { 1 } else { 2 };
|
||||
assert_eq!(y, 2);
|
||||
}
|
||||
|
||||
pub fn test_range_expr() {
|
||||
let r = 0..5;
|
||||
let mut count = 0;
|
||||
for (i : r) {
|
||||
for i in r {
|
||||
count++;
|
||||
}
|
||||
assert_eq!(count, 5);
|
||||
|
||||
@@ -18,12 +18,12 @@ pub fn test_var_decl_with_init() {
|
||||
pub fn test_if_statement() {
|
||||
let mut x = 0;
|
||||
|
||||
if (true) {
|
||||
if true {
|
||||
x = 1;
|
||||
}
|
||||
assert_eq!(x, 1);
|
||||
|
||||
if (false) {
|
||||
if false {
|
||||
x = 2;
|
||||
} else {
|
||||
x = 3;
|
||||
@@ -34,9 +34,9 @@ pub fn test_if_statement() {
|
||||
pub fn test_if_else_if() {
|
||||
let mut x = 0;
|
||||
|
||||
if (x == 1) {
|
||||
if x == 1 {
|
||||
x = 10;
|
||||
} else if (x == 0) {
|
||||
} else if x == 0 {
|
||||
x = 20;
|
||||
} else {
|
||||
x = 30;
|
||||
@@ -47,7 +47,7 @@ pub fn test_if_else_if() {
|
||||
pub fn test_while_loop() {
|
||||
let mut count = 0;
|
||||
|
||||
while (count < 5) {
|
||||
while count < 5 {
|
||||
count++;
|
||||
}
|
||||
assert_eq!(count, 5);
|
||||
@@ -56,7 +56,7 @@ pub fn test_while_loop() {
|
||||
pub fn test_for_loop() {
|
||||
let mut sum = 0;
|
||||
|
||||
for (i : 0..4) {
|
||||
for i in 0..4 {
|
||||
sum += i;
|
||||
}
|
||||
assert_eq!(sum, 6);
|
||||
@@ -67,7 +67,7 @@ pub fn test_loop_stmt() {
|
||||
|
||||
loop {
|
||||
count++;
|
||||
if (count >= 3) {
|
||||
if count >= 3 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -77,11 +77,11 @@ pub fn test_loop_stmt() {
|
||||
pub fn test_break_continue() {
|
||||
let mut sum = 0;
|
||||
|
||||
for (i : 0..10) {
|
||||
if (i % 2 == 0) {
|
||||
for i in 0..10 {
|
||||
if i % 2 == 0 {
|
||||
continue;
|
||||
}
|
||||
if (i >= 7) {
|
||||
if i >= 7 {
|
||||
break;
|
||||
}
|
||||
sum += i;
|
||||
@@ -105,7 +105,7 @@ pub fn test_match_literal() {
|
||||
let x = 2;
|
||||
let result;
|
||||
|
||||
match (x) {
|
||||
match x {
|
||||
1 => { result = 10; }
|
||||
2 => { result = 20; }
|
||||
3 => { result = 30; }
|
||||
@@ -118,7 +118,7 @@ pub fn test_match_or_pattern() {
|
||||
let x = 1;
|
||||
let result i32;
|
||||
|
||||
match (x) {
|
||||
match x {
|
||||
1 | 2 => { result = 100; }
|
||||
3 => { result = 200; }
|
||||
_ => panic!();
|
||||
@@ -130,7 +130,7 @@ pub fn test_match_default() {
|
||||
let x = 99;
|
||||
let result;
|
||||
|
||||
match (x) {
|
||||
match x {
|
||||
1 => { result = 10; }
|
||||
y => { result = y; }
|
||||
}
|
||||
@@ -141,7 +141,7 @@ pub fn test_for_with_pattern_destructure() {
|
||||
let pairs = [(1, "a"), (2, "b")];
|
||||
let mut keys = 0;
|
||||
|
||||
for ([k, _] : pairs) {
|
||||
for [k, _] in pairs {
|
||||
keys += k;
|
||||
}
|
||||
assert_eq!(keys, 3);
|
||||
|
||||
Reference in New Issue
Block a user