Skip to content

Commit 88ffb77

Browse files
committed
Update tests
1 parent c7416fc commit 88ffb77

3 files changed

Lines changed: 46 additions & 194 deletions

File tree

libcc2rs-macros/tests/control_flow.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2022-present INESC-ID.
22
// Distributed under the MIT license that can be found in the LICENSE file.
33

4-
use libcc2rs_macros::{goto_block, switch, switch_break};
4+
use libcc2rs_macros::{goto_block, switch};
55

66
#[test]
77
fn switch_dispatch_each_case() {
@@ -10,19 +10,19 @@ fn switch_dispatch_each_case() {
1010
switch!(match input {
1111
0 => {
1212
out = "zero";
13-
switch_break!();
13+
break;
1414
}
1515
1 => {
1616
out = "one";
17-
switch_break!();
17+
break;
1818
}
1919
2 => {
2020
out = "two";
21-
switch_break!();
21+
break;
2222
}
2323
_ => {
2424
out = "default";
25-
switch_break!();
25+
break;
2626
}
2727
});
2828
assert_eq!(out, expected, "input = {}", input);
@@ -38,11 +38,11 @@ fn switch_fallthrough() {
3838
} // fall-through
3939
1 => {
4040
v += 10;
41-
switch_break!();
41+
break;
4242
}
4343
_ => {
4444
v = -1;
45-
switch_break!();
45+
break;
4646
}
4747
});
4848
assert_eq!(v, 11);
@@ -60,11 +60,11 @@ fn switch_fallthrough_chain() {
6060
}
6161
2 => {
6262
v += 100;
63-
switch_break!();
63+
break;
6464
}
6565
_ => {
6666
v = -1;
67-
switch_break!();
67+
break;
6868
}
6969
});
7070
assert_eq!(v, 111);
@@ -76,15 +76,15 @@ fn switch_break_exits() {
7676
switch!(match 1 {
7777
0 => {
7878
v = 999;
79-
switch_break!();
79+
break;
8080
}
8181
1 => {
8282
v = 1;
83-
switch_break!();
83+
break;
8484
}
8585
_ => {
8686
v = 2;
87-
switch_break!();
87+
break;
8888
}
8989
});
9090
assert_eq!(v, 1);
@@ -96,11 +96,11 @@ fn switch_default_case() {
9696
switch!(match 42 {
9797
0 => {
9898
v = 1;
99-
switch_break!();
99+
break;
100100
}
101101
_ => {
102102
v = 2;
103-
switch_break!();
103+
break;
104104
}
105105
});
106106
assert_eq!(v, 2);
@@ -113,11 +113,11 @@ fn switch_or_pattern() {
113113
switch!(match x {
114114
1 | 2 | 3 => {
115115
v = "low";
116-
switch_break!();
116+
break;
117117
}
118118
_ => {
119119
v = "other";
120-
switch_break!();
120+
break;
121121
}
122122
});
123123
let expected = if x <= 3 { "low" } else { "other" };
@@ -132,15 +132,15 @@ fn switch_guard_stacked_cases() {
132132
switch!(match x {
133133
v if v == 1 || v == 2 || v == 3 => {
134134
r = 100;
135-
switch_break!();
135+
break;
136136
}
137137
v if v == 4 || v == 5 => {
138138
r = 200;
139-
switch_break!();
139+
break;
140140
}
141141
_ => {
142142
r = 300;
143-
switch_break!();
143+
break;
144144
}
145145
});
146146
assert_eq!(r, expected, "x = {}", x);
@@ -156,11 +156,11 @@ fn switch_guard_fallthrough() {
156156
}
157157
w if w == 2 => {
158158
v += 10;
159-
switch_break!();
159+
break;
160160
}
161161
_ => {
162162
v = -1;
163-
switch_break!();
163+
break;
164164
}
165165
});
166166
assert_eq!(v, 11);
@@ -172,15 +172,15 @@ fn switch_guard_no_match_hits_default() {
172172
switch!(match 42 {
173173
v if v == 1 => {
174174
r = 1;
175-
switch_break!();
175+
break;
176176
}
177177
v if v == 2 || v == 3 => {
178178
r = 2;
179-
switch_break!();
179+
break;
180180
}
181181
_ => {
182182
r = 99;
183-
switch_break!();
183+
break;
184184
}
185185
});
186186
assert_eq!(r, 99);
@@ -192,15 +192,15 @@ fn switch_range_pattern() {
192192
switch!(match 50i32 {
193193
0..=9 => {
194194
v = 1;
195-
switch_break!();
195+
break;
196196
}
197197
10..=99 => {
198198
v = 2;
199-
switch_break!();
199+
break;
200200
}
201201
_ => {
202202
v = 3;
203-
switch_break!();
203+
break;
204204
}
205205
});
206206
assert_eq!(v, 2);
@@ -218,10 +218,10 @@ fn switch_nested_loop_break_targets_inner() {
218218
sum += i;
219219
}
220220
sum += 100;
221-
switch_break!();
221+
break;
222222
}
223223
_ => {
224-
switch_break!();
224+
break;
225225
}
226226
});
227227
assert_eq!(sum, 103);
@@ -256,10 +256,10 @@ fn switch_in_loop() {
256256
switch!(match x {
257257
0 | 2 | 4 => {
258258
count += 1;
259-
switch_break!();
259+
break;
260260
}
261261
_ => {
262-
switch_break!();
262+
break;
263263
}
264264
});
265265
}

libcc2rs-macros/tests/ui/forbidden.rs

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,20 @@
11
// Copyright (c) 2022-present INESC-ID.
22
// Distributed under the MIT license that can be found in the LICENSE file.
33

4-
use libcc2rs_macros::{goto, goto_block, switch, switch_break};
4+
use libcc2rs_macros::{goto, switch};
55

6-
fn switch_bare_break() {
6+
fn continue_with_no_outer_loop() {
77
let mut v = 0;
8+
// No outer loop to continue
89
switch!(match 0 {
9-
0 => { v = 1; break; } // should be switch_break!()
10+
0 => { v = 1; continue; }
1011
_ => { v = 2; }
1112
});
1213
let _ = v;
1314
}
1415

15-
fn switch_bare_continue() {
16-
let mut v = 0;
17-
switch!(match 0 {
18-
0 => { v = 1; continue; } // no continue, switch! does not act as a loop
19-
_ => { v = 2; }
20-
});
21-
let _ = v;
22-
}
23-
24-
fn switch_labeled_break() {
25-
let mut v = 0;
26-
'outer: loop {
27-
switch!(match 0 {
28-
0 => { v = 1; break 'outer; } // no break with named label
29-
_ => { v = 2; }
30-
});
31-
}
32-
let _ = v;
33-
}
34-
35-
fn switch_break_inside_nested_loop() {
36-
let mut v = 0;
37-
switch!(match 0 {
38-
0 => {
39-
for _ in 0..3 {
40-
switch_break!(); // break inside loop cannot exit the swich
41-
}
42-
v = 1;
43-
}
44-
_ => { v = 2; }
45-
});
46-
let _ = v;
47-
}
48-
49-
fn goto_block_bare_break() {
50-
let mut v = 0;
51-
goto_block! {
52-
'a => { v = 1; break; },
53-
'b => { v = 2; },
54-
};
55-
let _ = v;
56-
}
57-
58-
fn goto_block_labeled_continue() {
59-
let mut v = 0;
60-
'outer: loop {
61-
goto_block! {
62-
'a => { v = 1; continue 'outer; },
63-
'b => { v = 2; },
64-
};
65-
break;
66-
}
67-
let _ = v;
68-
}
69-
70-
fn switch_break_outside_switch() {
71-
// no switch_break!() outside switch!
72-
switch_break!();
73-
}
74-
7516
fn goto_outside_goto_block() {
76-
// no goto!() outside goto_block!
17+
// goto!() used outside goto_block!
7718
goto!('nowhere);
7819
}
7920

0 commit comments

Comments
 (0)