diff options
Diffstat (limited to 'tests/icon/accept')
22 files changed, 132 insertions, 0 deletions
diff --git a/tests/icon/accept/bound_global.expected b/tests/icon/accept/bound_global.expected new file mode 100644 index 0000000..938d790 --- /dev/null +++ b/tests/icon/accept/bound_global.expected @@ -0,0 +1 @@ +1 10 10 diff --git a/tests/icon/accept/bound_global.zc b/tests/icon/accept/bound_global.zc new file mode 100644 index 0000000..f49a76b --- /dev/null +++ b/tests/icon/accept/bound_global.zc @@ -0,0 +1,13 @@ +include rt; +include run; +include icon; +int counter = 6; +fn main() { + let q = run.tokens("counter += 4; return counter;"); + let frame = icon.begin(q); + rt.put_n(icon.bind_global(frame, "counter")); rt.put_c(' '); + icon.resume(frame, 3); + rt.put_n(counter); rt.put_c(' '); rt.put_n(icon.result(frame)); rt.put_c(10); + icon.close(d*frame); + return 0; +} diff --git a/tests/icon/accept/branch_edit.expected b/tests/icon/accept/branch_edit.expected new file mode 100644 index 0000000..9c1b765 --- /dev/null +++ b/tests/icon/accept/branch_edit.expected @@ -0,0 +1 @@ +9 7 diff --git a/tests/icon/accept/branch_edit.zc b/tests/icon/accept/branch_edit.zc new file mode 100644 index 0000000..b360a6a --- /dev/null +++ b/tests/icon/accept/branch_edit.zc @@ -0,0 +1,11 @@ +include rt; +include run; +include icon; +fn main() { + let q = run.tokens("if (1) { return 7; } else { return 9; }"); + let pattern = run.tokens("if ($expr:condition) { $stmt:yes } else { $stmt:no }"); + let replacement = run.tokens("if ($condition) { $no } else { $yes }"); + let edited = icon.rewrite(q, pattern, replacement); + rt.put_n(run.eval(edited)); rt.put_c(' '); rt.put_n(run.eval(q)); rt.put_c(10); + return 0; +} diff --git a/tests/icon/accept/calculate.expected b/tests/icon/accept/calculate.expected new file mode 100644 index 0000000..d81cc07 --- /dev/null +++ b/tests/icon/accept/calculate.expected @@ -0,0 +1 @@ +42 diff --git a/tests/icon/accept/calculate.zc b/tests/icon/accept/calculate.zc new file mode 100644 index 0000000..77ba7ea --- /dev/null +++ b/tests/icon/accept/calculate.zc @@ -0,0 +1,8 @@ +include rt; +include run; +include icon; +fn main() { + let q = run.tokens("(3 + 4) * (8 - 2)"); + rt.put_n(icon.calculate(q, 0, q[0])); rt.put_c(10); + return 0; +} diff --git a/tests/icon/accept/edit_declaration.expected b/tests/icon/accept/edit_declaration.expected new file mode 100644 index 0000000..f599e28 --- /dev/null +++ b/tests/icon/accept/edit_declaration.expected @@ -0,0 +1 @@ +10 diff --git a/tests/icon/accept/edit_declaration.zc b/tests/icon/accept/edit_declaration.zc new file mode 100644 index 0000000..59b7eb8 --- /dev/null +++ b/tests/icon/accept/edit_declaration.zc @@ -0,0 +1,12 @@ +include rt; +include run; +include icon; +fn main() { + let q = run.tokens("int discarded = 8; int n = 5; return n * 2;"); + let a = icon.undeclare(q, "discarded"); + let type = run.tokens("i32"), block = run.tokens("int extra = 2;"); + let b = icon.change_type(a, "n", type); + let c = icon.insert_block(b, 0, block); + rt.put_n(run.eval(c)); rt.put_c(10); + return 0; +} diff --git a/tests/icon/accept/function_step.expected b/tests/icon/accept/function_step.expected new file mode 100644 index 0000000..c2096ed --- /dev/null +++ b/tests/icon/accept/function_step.expected @@ -0,0 +1 @@ +13 5 diff --git a/tests/icon/accept/function_step.zc b/tests/icon/accept/function_step.zc new file mode 100644 index 0000000..6bdf344 --- /dev/null +++ b/tests/icon/accept/function_step.zc @@ -0,0 +1,12 @@ +include rt; +include run; +include icon; +int target(int value) { int n = value * 2; return n + 1; } +fn main() { + let frame = icon.begin_function(target); + icon.set_local(frame, "value", 6); + icon.resume(frame, 8); + rt.put_n(icon.result(frame)); rt.put_c(' '); rt.put_n(target(2)); rt.put_c(10); + icon.close(d*frame); + return 0; +} diff --git a/tests/icon/accept/literal_replace.expected b/tests/icon/accept/literal_replace.expected new file mode 100644 index 0000000..9c67935 --- /dev/null +++ b/tests/icon/accept/literal_replace.expected @@ -0,0 +1 @@ +1 4 diff --git a/tests/icon/accept/literal_replace.zc b/tests/icon/accept/literal_replace.zc new file mode 100644 index 0000000..70f7527 --- /dev/null +++ b/tests/icon/accept/literal_replace.zc @@ -0,0 +1,9 @@ +include rt; +include run; +include icon; +int addition() { return 7 + 3; } +fn main() { + let changed = icon.find_replace(addition, ${ $int + $int }, ${ $int - $int }); + rt.put_n(changed); rt.put_c(' '); rt.put_n(addition()); rt.put_c(10); + return 0; +} diff --git a/tests/icon/accept/loop_step.expected b/tests/icon/accept/loop_step.expected new file mode 100644 index 0000000..15d5109 --- /dev/null +++ b/tests/icon/accept/loop_step.expected @@ -0,0 +1 @@ +1 8 1 diff --git a/tests/icon/accept/loop_step.zc b/tests/icon/accept/loop_step.zc new file mode 100644 index 0000000..7a0368e --- /dev/null +++ b/tests/icon/accept/loop_step.zc @@ -0,0 +1,12 @@ +include rt; +include run; +include icon; +fn main() { + let q = run.tokens("int n = 0; while (n < limit) { n += 1; } if (n == 4) { n *= 2; } else { n = 99; } return n;"); + let frame = icon.begin(q); + icon.set_global(frame, "limit", 4); + icon.resume(frame, 3); rt.put_n(icon.local(frame, "n")); rt.put_c(' '); + icon.resume(frame, 30); rt.put_n(icon.result(frame)); rt.put_c(' '); rt.put_n(icon.state(frame)); rt.put_c(10); + icon.close(d*frame); + return 0; +} diff --git a/tests/icon/accept/named_capture.expected b/tests/icon/accept/named_capture.expected new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/tests/icon/accept/named_capture.expected @@ -0,0 +1 @@ +8 diff --git a/tests/icon/accept/named_capture.zc b/tests/icon/accept/named_capture.zc new file mode 100644 index 0000000..258004d --- /dev/null +++ b/tests/icon/accept/named_capture.zc @@ -0,0 +1,10 @@ +include rt; +include run; +include icon; +fn main() { + let q = run.tokens("return (2 + 5) * (2 + 5);"); + let p = run.tokens("$expr:x * $expr:x"), r = run.tokens("$x + 1"); + let changed = icon.rewrite(q, p, r); + rt.put_n(run.eval(changed)); rt.put_c(10); + return 0; +} diff --git a/tests/icon/accept/nested_declaration.expected b/tests/icon/accept/nested_declaration.expected new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/tests/icon/accept/nested_declaration.expected @@ -0,0 +1 @@ +5 diff --git a/tests/icon/accept/nested_declaration.zc b/tests/icon/accept/nested_declaration.zc new file mode 100644 index 0000000..9b360e8 --- /dev/null +++ b/tests/icon/accept/nested_declaration.zc @@ -0,0 +1,11 @@ +include rt; +include run; +include icon; +fn main() { + let q = run.tokens("int n = 2; { int unused = 9; int added = 3; n += added; } return n;"); + let type = run.tokens("i32"); + let a = icon.undeclare(q, "unused"); + let b = icon.change_type(a, "added", type); + rt.put_n(run.eval(b)); rt.put_c(10); + return 0; +} diff --git a/tests/icon/accept/step.expected b/tests/icon/accept/step.expected new file mode 100644 index 0000000..a370d71 --- /dev/null +++ b/tests/icon/accept/step.expected @@ -0,0 +1 @@ +4 12 14 diff --git a/tests/icon/accept/step.zc b/tests/icon/accept/step.zc new file mode 100644 index 0000000..d394e1e --- /dev/null +++ b/tests/icon/accept/step.zc @@ -0,0 +1,12 @@ +include rt; +include run; +include icon; +fn main() { + let q = run.tokens("int n = 4; n = n * 3; return n + bias;"); + let frame = icon.begin(q); + icon.set_global(frame, "bias", 2); + icon.step(frame); rt.put_n(icon.local(frame, "n")); rt.put_c(' '); + icon.step(frame); rt.put_n(icon.local(frame, "n")); rt.put_c(' '); + icon.step(frame); rt.put_n(icon.result(frame)); rt.put_c(10); + return 0; +} diff --git a/tests/icon/accept/token_replace.expected b/tests/icon/accept/token_replace.expected new file mode 100644 index 0000000..8351c19 --- /dev/null +++ b/tests/icon/accept/token_replace.expected @@ -0,0 +1 @@ +14 diff --git a/tests/icon/accept/token_replace.zc b/tests/icon/accept/token_replace.zc new file mode 100644 index 0000000..bf80548 --- /dev/null +++ b/tests/icon/accept/token_replace.zc @@ -0,0 +1,11 @@ +include rt; +include run; +include icon; +fn main() { + let source = run.tokens("return (9 + 2) * 3;"); + let pattern = run.tokens("$expr:left * $int:right"); + let replacement = run.tokens("$left + $right"); + let edited = icon.rewrite(source, pattern, replacement); + rt.put_n(run.eval(edited)); rt.put_c(10); + return 0; +} |
