| 1 | import os |
| 2 | |
| 3 | const vexe = @VEXE |
| 4 | |
| 5 | const vroot = os.real_path(@VMODROOT) |
| 6 | |
| 7 | const labelled_continue_scope_testdata = os.join_path(vroot, |
| 8 | 'vlib/v/gen/c/testdata/labelled_continue_scope.vv') |
| 9 | |
| 10 | struct LabelledContinueCase { |
| 11 | label string |
| 12 | var_name string |
| 13 | } |
| 14 | |
| 15 | fn test_labelled_continue_targets_reenter_at_the_loop_gate() { |
| 16 | os.chdir(vroot) or {} |
| 17 | cmd := '${os.quoted_path(vexe)} -o - ${os.quoted_path(labelled_continue_scope_testdata)}' |
| 18 | compilation := os.execute(cmd) |
| 19 | assert compilation.exit_code == 0 |
| 20 | generated_c := compilation.output.replace('\r\n', '\n') |
| 21 | cases := [ |
| 22 | LabelledContinueCase{'range_outer', 'issue_19973_range_var'}, |
| 23 | LabelledContinueCase{'cond_outer', 'issue_19973_cond_var'}, |
| 24 | LabelledContinueCase{'c_outer', 'issue_19973_c_var'}, |
| 25 | LabelledContinueCase{'c_multi_outer', 'issue_19973_c_multi_var'}, |
| 26 | ] |
| 27 | for tc in cases { |
| 28 | continue_flag := 'v__labeled_continue_${tc.label}' |
| 29 | continue_entry_label := '${tc.label}__continue_entry: {}' |
| 30 | continue_label := '${tc.label}__continue: {}' |
| 31 | continue_gate := 'if (${continue_flag}) goto ${tc.label}__continue;' |
| 32 | continue_assignment := '${continue_flag} = true;' |
| 33 | continue_goto := 'goto ${tc.label}__continue_entry;' |
| 34 | var_decl := 'string ${tc.var_name} =' |
| 35 | assert generated_c.contains('bool ${continue_flag} = false;') |
| 36 | assert generated_c.contains(continue_entry_label) |
| 37 | assert generated_c.contains(continue_gate) |
| 38 | assert generated_c.contains(continue_assignment) |
| 39 | assert generated_c.contains(continue_goto) |
| 40 | flag_idx := generated_c.index('bool ${continue_flag} = false;') or { |
| 41 | panic('missing continue flag for `${tc.label}`') |
| 42 | } |
| 43 | entry_idx := generated_c.index(continue_entry_label) or { |
| 44 | panic('missing continue entry label for `${tc.label}`') |
| 45 | } |
| 46 | var_idx := generated_c.index(var_decl) or { |
| 47 | panic('missing declaration for `${tc.var_name}`') |
| 48 | } |
| 49 | label_idx := generated_c.index(continue_label) or { |
| 50 | panic('missing continue label for `${tc.label}`') |
| 51 | } |
| 52 | assert flag_idx < entry_idx |
| 53 | assert entry_idx < var_idx |
| 54 | assert var_idx < label_idx |
| 55 | } |
| 56 | } |
| 57 | |