From b9d47d46f6d186ee318b6760102b0486af23573b Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Thu, 29 Nov 2018 22:38:34 +0100 Subject: [PATCH] Exec test cases of Rust Team --- exec/binary_ops.mj | 26 ++++++++++++++ exec/binary_ops.mj.out | 20 +++++++++++ exec/can_call.mj | 11 ++++++ exec/can_call.mj.out | 1 + exec/can_short_circuit.mj | 35 +++++++++++++++++++ exec/can_short_circuit.mj.out | 4 +++ exec/field_init.mj | 31 ++++++++++++++++ exec/field_init.mj.out | 4 +++ exec/if_else.mj | 15 ++++++++ exec/if_else.mj.out | 2 ++ exec/indirect_system_calls.mj | 6 ++++ exec/indirect_system_calls.mj.out | 1 + exec/invoke_object_returned_by_expression.mj | 19 ++++++++++ ...nvoke_object_returned_by_expression.mj.out | 1 + exec/multiassign.mj | 9 +++++ exec/multiassign.mj.out | 2 ++ exec/return.mj | 12 +++++++ exec/return.mj.out | 1 + exec/unary_ops.mj | 10 ++++++ exec/unary_ops.mj.out | 4 +++ exec/while.mj | 13 +++++++ exec/while.mj.out | 2 ++ 22 files changed, 229 insertions(+) create mode 100644 exec/binary_ops.mj create mode 100644 exec/binary_ops.mj.out create mode 100644 exec/can_call.mj create mode 100644 exec/can_call.mj.out create mode 100644 exec/can_short_circuit.mj create mode 100644 exec/can_short_circuit.mj.out create mode 100644 exec/field_init.mj create mode 100644 exec/field_init.mj.out create mode 100644 exec/if_else.mj create mode 100644 exec/if_else.mj.out create mode 100644 exec/indirect_system_calls.mj create mode 100644 exec/indirect_system_calls.mj.out create mode 100644 exec/invoke_object_returned_by_expression.mj create mode 100644 exec/invoke_object_returned_by_expression.mj.out create mode 100644 exec/multiassign.mj create mode 100644 exec/multiassign.mj.out create mode 100644 exec/return.mj create mode 100644 exec/return.mj.out create mode 100644 exec/unary_ops.mj create mode 100644 exec/unary_ops.mj.out create mode 100644 exec/while.mj create mode 100644 exec/while.mj.out diff --git a/exec/binary_ops.mj b/exec/binary_ops.mj new file mode 100644 index 0000000..da4fac0 --- /dev/null +++ b/exec/binary_ops.mj @@ -0,0 +1,26 @@ +class A { + public static void main(String[] args) { + System.out.println(2 - 1); // 1 + System.out.println(4 / 2); // 2 + System.out.println(1 + 2); // 3 + System.out.println(2 * 2); // 4 + System.out.println(11 % 6); // 5 + + if (false || true) { System.out.println(6); } + if (true || false) { System.out.println(7); } + if (true && false) { } else { System.out.println(8); } + if (true && true) { System.out.println(9); } + if (1 == 1) { System.out.println(10); } + if (1 == 2) { } else { System.out.println(11); } + if (1 != 2) { System.out.println(12); } + if (1 != 1) { } else { System.out.println(13); } + if (1 < 2) { System.out.println(14); } + if (1 < 1) { } else { System.out.println(15); } + if (2 > 1) { System.out.println(16); } + if (1 > 1) { } else { System.out.println(17); } + if (1 <= 1) { System.out.println(18); } + if (2 <= 1) { } else { System.out.println(19); } + if (1 >= 1) { System.out.println(20); } + if (1 >= 2) { } else { System.out.println(21); } + } +} diff --git a/exec/binary_ops.mj.out b/exec/binary_ops.mj.out new file mode 100644 index 0000000..759a7a3 --- /dev/null +++ b/exec/binary_ops.mj.out @@ -0,0 +1,20 @@ +1 +2 +3 +4 +5 +6 +7 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 diff --git a/exec/can_call.mj b/exec/can_call.mj new file mode 100644 index 0000000..d2b11f0 --- /dev/null +++ b/exec/can_call.mj @@ -0,0 +1,11 @@ +class Foo { + public int ret_int() { + return 48; + } + + public static void main(String[] args) { + Foo a = new Foo(); + int b = a.ret_int(); + System.out.println(b); + } +} diff --git a/exec/can_call.mj.out b/exec/can_call.mj.out new file mode 100644 index 0000000..21e72e8 --- /dev/null +++ b/exec/can_call.mj.out @@ -0,0 +1 @@ +48 diff --git a/exec/can_short_circuit.mj b/exec/can_short_circuit.mj new file mode 100644 index 0000000..3954359 --- /dev/null +++ b/exec/can_short_circuit.mj @@ -0,0 +1,35 @@ +class A { + public boolean side_effect() { + System.out.write(70); // + System.out.write(10); // newline + return false; + } + + public static void main(String[] args) { + A a = new A(); + if (true || a.side_effect()) { + System.out.write(79); // O + System.out.write(75); // K + System.out.write(10); // newline + } + + if (false && a.side_effect()) { + } else { + System.out.write(79); // O + System.out.write(75); // K + System.out.write(10); // newline + } + + if (!(false && a.side_effect())) { + System.out.write(79); // O + System.out.write(75); // K + System.out.write(10); // newline + } + + if ((true || a.side_effect()) && true) { + System.out.write(79); // O + System.out.write(75); // K + System.out.write(10); // newline + } + } +} diff --git a/exec/can_short_circuit.mj.out b/exec/can_short_circuit.mj.out new file mode 100644 index 0000000..b462a5a --- /dev/null +++ b/exec/can_short_circuit.mj.out @@ -0,0 +1,4 @@ +OK +OK +OK +OK diff --git a/exec/field_init.mj b/exec/field_init.mj new file mode 100644 index 0000000..1b088a1 --- /dev/null +++ b/exec/field_init.mj @@ -0,0 +1,31 @@ +class A { + public int a; + + public void print_as() { + System.out.println(a); + System.out.println(this.a); + } + + public static void main(String[] args) { + A a = new A(); + a.print_as(); + B b = new B(); + + if (b.b) { + System.out.println(1); + } else { + System.out.println(0); + } + + if (b.c == null) { + System.out.println(0); + } else { + System.out.println(1); + } + } +} + +class B { + public boolean b; + public A c; +} diff --git a/exec/field_init.mj.out b/exec/field_init.mj.out new file mode 100644 index 0000000..44e0be8 --- /dev/null +++ b/exec/field_init.mj.out @@ -0,0 +1,4 @@ +0 +0 +0 +0 diff --git a/exec/if_else.mj b/exec/if_else.mj new file mode 100644 index 0000000..62efd85 --- /dev/null +++ b/exec/if_else.mj @@ -0,0 +1,15 @@ +class Foo { + public static void main(String[] args) { + if (true) { + System.out.println(1); + } else { + System.out.println(0); + } + + if (false) { + System.out.println(0); + } else { + System.out.println(1); + } + } +} diff --git a/exec/if_else.mj.out b/exec/if_else.mj.out new file mode 100644 index 0000000..6ed281c --- /dev/null +++ b/exec/if_else.mj.out @@ -0,0 +1,2 @@ +1 +1 diff --git a/exec/indirect_system_calls.mj b/exec/indirect_system_calls.mj new file mode 100644 index 0000000..a0f74ca --- /dev/null +++ b/exec/indirect_system_calls.mj @@ -0,0 +1,6 @@ +class A { + + public static void main(String[] args) { + ((System).out).println(4); + } +} diff --git a/exec/indirect_system_calls.mj.out b/exec/indirect_system_calls.mj.out new file mode 100644 index 0000000..b8626c4 --- /dev/null +++ b/exec/indirect_system_calls.mj.out @@ -0,0 +1 @@ +4 diff --git a/exec/invoke_object_returned_by_expression.mj b/exec/invoke_object_returned_by_expression.mj new file mode 100644 index 0000000..d113020 --- /dev/null +++ b/exec/invoke_object_returned_by_expression.mj @@ -0,0 +1,19 @@ +class A { + public B get_object() { + return new B(); + } + + public static void main(String[] args) { + A a = new A(); + int res = (a.get_object()).get_number(); + System.out.println(res); + } +} + +class B { + + public int get_number() { + return 99; + } + +} diff --git a/exec/invoke_object_returned_by_expression.mj.out b/exec/invoke_object_returned_by_expression.mj.out new file mode 100644 index 0000000..3ad5abd --- /dev/null +++ b/exec/invoke_object_returned_by_expression.mj.out @@ -0,0 +1 @@ +99 diff --git a/exec/multiassign.mj b/exec/multiassign.mj new file mode 100644 index 0000000..05d333e --- /dev/null +++ b/exec/multiassign.mj @@ -0,0 +1,9 @@ +eass A { + + public static void main(String[] args) { + int x = 8; + int y = x = 4; + System.out.println(x); + System.out.println(y); + } +} diff --git a/exec/multiassign.mj.out b/exec/multiassign.mj.out new file mode 100644 index 0000000..7290ba8 --- /dev/null +++ b/exec/multiassign.mj.out @@ -0,0 +1,2 @@ +4 +4 diff --git a/exec/return.mj b/exec/return.mj new file mode 100644 index 0000000..0e5df5e --- /dev/null +++ b/exec/return.mj @@ -0,0 +1,12 @@ +class A { + + public int loopy_1() { + int i = 3; + while (i < 5) { return i; } + } + + public static void main(String[] args) { + System.out.println((new A()).loopy_1()); + } +} + diff --git a/exec/return.mj.out b/exec/return.mj.out new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/exec/return.mj.out @@ -0,0 +1 @@ +3 diff --git a/exec/unary_ops.mj b/exec/unary_ops.mj new file mode 100644 index 0000000..934bc55 --- /dev/null +++ b/exec/unary_ops.mj @@ -0,0 +1,10 @@ +class A { + public static void main(String[] args) { + int x = 4; + System.out.println(-x); + + if (!false) { System.out.println(-3); } + if (!true) { } else { System.out.println(-2); } + if (!!!true) { } else { System.out.println(-1); } + } +} diff --git a/exec/unary_ops.mj.out b/exec/unary_ops.mj.out new file mode 100644 index 0000000..cc86190 --- /dev/null +++ b/exec/unary_ops.mj.out @@ -0,0 +1,4 @@ +-4 +-3 +-2 +-1 diff --git a/exec/while.mj b/exec/while.mj new file mode 100644 index 0000000..2b966fb --- /dev/null +++ b/exec/while.mj @@ -0,0 +1,13 @@ +class A { + + public static void main(String[] args) { + int x = 0; + boolean a = false; + while(a) { x = 1; } + System.out.println(x); + + while(x < 5) { x = x + 1; } + System.out.println(x); + } +} + diff --git a/exec/while.mj.out b/exec/while.mj.out new file mode 100644 index 0000000..fd33066 --- /dev/null +++ b/exec/while.mj.out @@ -0,0 +1,2 @@ +0 +5 -- GitLab