class TestCase {
version "1.001003004000";
use TestCase::EnumA;
use TestCase::EnumB;
use TestCase::EnumC;
use TestCase::EnumD;
use TestCase::Simple as TS;
use TestCase::Minimal;
use TestCase::Destructor;
use TestCase::Callback1;
use TestCase::Callback2;
use TestCase::ImplementCallback1;
use TestCase::ImplementCallback2;
use TestCase::Comparator;
use TestCase::Comparator::Byte;
use TestCase::Pointer;
use TestCase::ComplexCalc;
use TestCase::Minimal::XGetter;
use TestCase::Point_3b;
use TestCase::Point_3s;
use TestCase::Point_3i;
use TestCase::Point_3l;
use TestCase::Point_3f;
use TestCase::Point_3d;
use TestCase::DumpTest1;
use TestCase::Complex_2f;
use TestCase::Complex_2d;
use TestCase::CommonInterface;
use TestCase::MinimalExtend;
=pod
ABCDE
=cut ppppp
=head1 NAME
SPVM::Test - SPVM test class
=cut
our $CLASS_VAR_INT : public int;
our $CLASS_VAR_TEST_CASE : public TestCase;
our $CLASS_VAR_RW : public rw int;
our $BEGIN_INIT : int;
our $TYPE_COMMENT : Byte of Byte;
INIT {
$BEGIN_INIT = 7;
}
has next_test : public TestCase;
has minimal : public TestCase::Minimal;
has x_byte : public byte;
has x_short : public short;
has x_int : public int;
has x_long : public long;
has x_float : public float;
has x_double : public double;
has private_field : public int;
has x_rw : public rw int;
has type_comemnt : Byte of Byte;
static method BYTE_MAX : byte () { return (byte)127; }
static method BYTE_MIN : byte () { return (byte)-128; }
static method SHORT_MAX : short () { return (short)32767; }
static method SHORT_MIN : short () { return (short)-32768; }
static method INT_MAX : int () { return 2147483647; }
static method INT_MIN : int () { return -2147483648; }
static method LONG_MAX : long () { return 9223372036854775807L; }
static method LONG_MIN : long () { return -9223372036854775808L; }
static method FLOAT_PRECICE : float () { return 32767f; }
static method DOUBLE_PRECICE : double () { return 2147483647.0; }
static method INT8_MIN : byte () { return -128; }
static method INT8_MAX : byte () { return 127; }
static method INT16_MIN : short () { return -32768; }
static method INT16_MAX : short () { return 32767; }
static method INT32_MIN : int () { return -2147483648; }
static method INT32_MAX : int () { return 2147483647; }
static method INT64_MIN : long () { return -9223372036854775808L; }
static method INT64_MAX : long () { return 9223372036854775807L; }
static method UINT32_MAX : int () { return 0xFFFFFFFF; }
static method UINT64_MAX : long () { return 0xFFFFFFFFFFFFFFFFL; }
static method type_comment_method : Int of Int ($foo : Int of Int) {
}
static method optional_args_byte0 : byte ($value : byte = 0) {
return $value;
}
static method main : int () {
{
my $message = <<'EOS';
Hello
Good Night
EOS
# aaaa
print $message;
}
{
my $string = "あいう";
}
my $start_file = CommandInfo->PROGRAM_NAME;
my $args = CommandInfo->ARGV;
{
my $args_width = args_width;
}
{
my $nums = new int[3];
if ($nums is_type Int) {
warn "is_type";
}
}
# for-each
{
my $nums = [1, 2, 3];
for my $num (@$nums) {
print "$num\n";
}
for my $num (@$nums) {
}
for my $num (@{$nums}) {
}
}
# Optional arguments
{
{
my $value = &optional_args_byte0;
warn $value;
}
}
{
my $minimal_extend = TestCase::MinimalExtend->new;
$minimal_extend->{x} = 1;
$minimal_extend->{y} = 2;
$minimal_extend->{z} = 3;
my $shared1 = $minimal_extend->shared1;
my $string = "$minimal_extend->{x},$minimal_extend->{y},$minimal_extend->{z}";
warn $string;
$minimal_extend->clear;
my $common_interface = (TestCase::CommonInterface)$minimal_extend;
$minimal_extend->{x} = 4;
$minimal_extend->{y} = 5;
$minimal_extend->{z} = 6;
$minimal_extend->SUPER::clear;
warn "$minimal_extend->{x},$minimal_extend->{y},$minimal_extend->{z}";
$minimal_extend->{x} = 4;
$minimal_extend->{y} = 5;
$minimal_extend->{z} = 6;
$minimal_extend->clear;
warn "$minimal_extend->{x},$minimal_extend->{y},$minimal_extend->{z}";
$minimal_extend->{x} = 4;
$minimal_extend->{y} = 5;
$minimal_extend->{z} = 6;
$common_interface->clear;
warn "$minimal_extend->{x},$minimal_extend->{y},$minimal_extend->{z}";
}
my $basic_type_id = basic_type_id TestCase;
warn "$basic_type_id";
# Only default
{
my $success : int;
switch (1) {
default: {
$success = 1;
}
}
}
# Type comment
{
my $type_comment : Int of Int;
}
{
my $minimal = TestCase::Minimal->new;
my $interface : TestCase::CommonInterface = $minimal;
my $can_share2 = $interface can shared2;
warn $can_share2;
if ($interface can shared2) {
warn $can_share2;
}
my $can_share3 = $interface can shared3;
warn $can_share3;
}
{
my $minimal = (TestCase::Minimal)undef;
eval { $minimal->clear; };
}
{
{
my $minimal = TestCase::Minimal->new;
my $interface : TestCase::CommonInterface = $minimal;
eval { $interface->shared3; };
eval { $interface->shared4($minimal); };
}
{
my $minimal = TestCase::Minimal->new;
my $interface : TestCase::CommonInterface = $minimal;
warn $interface->shared1;
warn $interface->shared2;
}
{
my $simple = TestCase::Simple->new;
my $interface : TestCase::CommonInterface = $simple;
warn $interface->shared1;
warn $interface->shared2;
}
{
my $minimal = TestCase::Minimal->new;
my $interface : TestCase::CommonInterface = $minimal;
my $object = (object)$interface;
my $interface_again = (TestCase::CommonInterface)$object;
warn $interface_again->shared1;
warn $interface_again->shared2;
}
}
{
my $string = copy "abc";
warn $string;
}
{
my $const_string = "abc";
warn is_read_only $const_string;
eval { my $string = (mutable string)$const_string; };
}
{
my $string = new_string_len 3;
make_read_only $string;
my $is_read_only = is_read_only $string;
}
{
my $message = new_string_len 3;
}
{
my $uint_max = &UINT32_MAX;
# 0 = -1 / 3
my $ret_div = $uint_max / 3;
# 1431655765 = 4,294,967,295 / 3
my $ret_divui = $uint_max div_uint 3;
warn "$ret_div $ret_divui";
}
{
my $ulong_max = &UINT64_MAX;
# 0 = -1 / 3
my $ret_div = $ulong_max / 3L;
# 6,148,914,691,236,517,205 = 18,446,744,073,709,551,615 / 3
my $ret_divui = $ulong_max div_ulong 3L;
warn "$ret_div $ret_divui";
}
{
my $uint_max = &UINT32_MAX;
# -1 = -1 % 3
my $ret_rem = $uint_max % 3;
# 0 = 4,294,967,295 mod_uint 3
my $ret_remui = $uint_max mod_uint 3;
warn "$ret_rem $ret_remui";
}
{
my $ulong_max = &UINT64_MAX;
# -1 = -1 % 3
my $ret_rem = $ulong_max % 3L;
# 0 = 18,446,744,073,709,551,615 mod_ulong 3
my $ret_remui = $ulong_max mod_ulong 3L;
warn "$ret_rem $ret_remui";
}
{
my $string : mutable string = (mutable string)new_string_len 3;
$string->[0] = 'd';
warn $string;
}
# Starting file
warn $start_file;
warn dump $args;
print($args->[0] . "\n");
print($args->[1] . "\n");
# dump
{
# string
{
my $string = "Hello";
warn dump $string;
}
# undef
{
my $string = (string)undef;
warn dump $string;
}
# byte array
{
my $array = [(byte)1, 2];
warn dump $array;
}
# short array
{
my $array = [(short)1, 2];
warn dump $array;
}
# int array
{
my $array = [(int)1, 2];
warn dump $array;
}
# long array
{
my $array = [(long)1, 2];
warn dump $array;
}
# float array
{
my $array = [(float)1.2f, 2.4f];
warn dump $array;
}
# double array
{
my $array = [(double)1.2, 2.4];
warn dump $array;
}
# byte muti numeric array
{
my $array = new TestCase::Point_3b[2];
$array->[0]{x} = 1;
$array->[0]{y} = 2;
$array->[0]{z} = 3;
$array->[1]{x} = 4;
$array->[1]{y} = 5;
$array->[1]{z} = 6;
warn dump $array;
}
# short muti numeric array
{
my $array = new TestCase::Point_3s[2];
$array->[0]{x} = 1;
$array->[0]{y} = 2;
$array->[0]{z} = 3;
$array->[1]{x} = 4;
$array->[1]{y} = 5;
$array->[1]{z} = 6;
warn dump $array;
}
# int muti numeric array
{
my $array = new TestCase::Point_3i[2];
$array->[0]{x} = 1;
$array->[0]{y} = 2;
$array->[0]{z} = 3;
$array->[1]{x} = 4;
$array->[1]{y} = 5;
$array->[1]{z} = 6;
warn dump $array;
}
# long muti numeric array
{
my $array = new TestCase::Point_3f[2];
$array->[0]{x} = 1;
$array->[0]{y} = 2;
$array->[0]{z} = 3;
$array->[1]{x} = 4;
$array->[1]{y} = 5;
$array->[1]{z} = 6;
warn dump $array;
}
# float muti numeric array
{
my $array = new TestCase::Point_3f[2];
$array->[0]{x} = 1.1f;
$array->[0]{y} = 2.1f;
$array->[0]{z} = 3.1f;
$array->[1]{x} = 4.1f;
$array->[1]{y} = 5.1f;
$array->[1]{z} = 6.1f;
warn dump $array;
}
# double muti numeric array
{
my $array = new TestCase::Point_3d[2];
$array->[0]{x} = 1.1;
$array->[0]{y} = 2.1;
$array->[0]{z} = 3.1;
$array->[1]{x} = 4.1;
$array->[1]{y} = 5.1;
$array->[1]{z} = 6.1;
warn dump $array;
}
# string array
{
my $array = ["abc", "def", undef];
warn dump $array;
}
# string array of array
{
my $array = [["abc", "def", undef], ["a", "b"]];
warn dump $array;
}
# object
{
my $object = new TestCase::DumpTest1;
$object->{byte_value} = 1;
$object->{short_value} = 2;
$object->{int_value} = 3;
$object->{long_value} = 4;
$object->{float_value} = 1.1f;
$object->{double_value} = 1.2;
$object->{string_value} = "a";
$object->{int_array} = [1, 2, 3];
$object->{object_value} = new TestCase::DumpTest1;
warn dump $object;
}
# object array, reuse, object[]
{
my $object = new TestCase::DumpTest1;
$object->{object_value} = $object;
weaken $object->{object_value};
my $array = [(object)$object, $object, $object];
warn dump $array;
}
}
{
my $array = {};
}
{
my $array = {foo => 1, bar => 2};
}
{
my $minimal = TestCase::Minimal->new;
my $name = type_name $minimal;
}
{
my $simple = TS->new;
my $minimal = TestCase::Minimal->new;
$simple->set_minimal($minimal);
$simple->minimal->x;
}
{
# my $nums : byte[] = "abc";
# my $string : string = new byte[3];
1;
}
{
my $nums : byte[] = (byte[])"abc";
warn "$nums->[0] $nums->[1] $nums->[2]";
my $byte_array = new byte[3];
$byte_array->[0] = 97;
$byte_array->[1] = 98;
$byte_array->[2] = 99;
my $string : string = (string)$byte_array;
warn $string;
}
{
warn "PPP";
warn "QQQ\n";
}
{
my $foo = 2;
my $bar = 3;
my $str = "foo $foo ${bar} rrr";
}
{
my $foo = 2;
my $str = "foo $foo bar";
}
{
"aaaa$";
}
{
"aaaa\\";
}
{
my $i = 0;
switch ($i) {
case 1: {
1;
break;
}
}
}
{
my $z1 : TestCase::Complex_2d;
my $z2 : TestCase::Complex_2d;
$z1->{re} = 1;
$z1->{im} = 2;
$z2->{re} = 3;
$z2->{im} = 4;
my $z3 : TestCase::Complex_2d;
$z3->{re} = $z1->{re} + $z2->{re};
$z3->{im} = $z1->{im} + $z2->{im};
print($z3->{re} . " " . $z3->{im} . "\n");
}
{
my $cb = method : int () {
return 386;
};
warn $cb->();
}
{
my $z = (1, 2, 3);
}
{
my $minimals = new TestCase::Minimal[3];
$minimals->[0] = TestCase::Minimal->new;
$minimals->[0]{x} = 1;
my $nums : object[] = $minimals;
my $nums2 : object[] = $nums;
my $len = @$nums;
warn "$len";
# my $nums3 : TestCase::Minimal[] = $nums;
my $nums4 = (TestCase::Minimal[])$nums;
warn $nums4->[0]{x};
my $elem = $nums->[0];
my $minimal = (TestCase::Minimal)$elem;
warn $minimal->{x};
$nums->[1] = TestCase::Minimal->new;
# $nums->[1] = TestCase::Simple->new;
$nums->[1] = $nums->[0];
}
{
my $object = (object)['a', 'b', 'c'];
my $bytes = (byte[])$object;
warn "AAAAAAAAA $bytes->[0]";
}
{
my $object = (object)"aaaa";
my $str2 = (string)$object;
warn "AAAAAAAAA $str2";
}
{
my $string = "\N{U+3042}\N{U+3044}\N{U+3046}";
}
{
my $string = "abc";
unless (length $string == 3) {
return 0;
}
}
{
my $concat_constant = "abc" . "def";
print("$concat_constant\n");
}
print TestCase::Simple->file . "\n";
print __FILE__ . "\n";
print __LINE__ . "\n";
print __PACKAGE__ . "\n";
{
my $minimal = TestCase::Minimal->new;
$minimal->set_x(78);
my $x_getter = TestCase::Minimal::XGetter->new;
print($x_getter->($minimal) . "\n");
}
{
my $x_getter : TestCase::Minimal::XGetter;
if (require TestCase::Minimal) {
warn "reauire";
}
}
if (require PPP) {
PPP->x(1);
}
{
print($BEGIN_INIT . "\n");
}
{
&SET_CLASS_VAR_RW(6);
my $class_var_rw = &CLASS_VAR_RW;
print("$class_var_rw\n");
}
{
my $test_case = new TestCase;
$test_case->set_x_rw(5);
my $test_case_x_rw = $test_case->x_rw;
print("$test_case_x_rw\n");
}
{
my $string_length = length "abc";
print("$string_length\n");
}
{
my $var1 = 1;
my $var2 = 2;
my $string = "a $var1 ppp $var2 qqq";
}
{
my $capture1 = 7;
my $capture2 = 10;
my $cb_obj = [has capture1 : int = $capture1, has capture2 : int = $capture2] method : int ($x1 : object, $x2 : object) {
my $capture1 = $self->{capture1};
my $capture2 = $self->{capture2};
print($capture1 . "\n");
print($capture2 . "\n");
$self->{capture1} = 5;
print($self->{capture1} . "\n");
return -1;
};
$cb_obj->(undef, undef);
}
{
my $cb_obj = method : int ($x1 : object, $x2 : object) {
return -1;
};
my $ret = $cb_obj->(undef, undef);
print($ret . "\n");
my $comparator : TestCase::Comparator = $cb_obj;
my $ret2 = $comparator->(undef, undef);
print($ret . "\n");
}
{
my $i : int;
my $p = $i++;
warn $p;
warn $i;
}
{
my $values_point_byte = new TestCase::Point_3b[1];
my $values_point_short = new TestCase::Point_3s[1];
my $values_point_int = new TestCase::Point_3i[1];
my $values_point_long = new TestCase::Point_3l[1];
my $values_point_float = new TestCase::Point_3f[1];
my $values_point_double = new TestCase::Point_3d[1];
$values_point_byte->[0]{x} = (byte)TestCase->INT8_MIN();
$values_point_short->[0]{x} = (short)TestCase->INT16_MIN();
$values_point_int->[0]{x} = TestCase->INT32_MIN();
$values_point_long->[0]{x} = TestCase->INT64_MIN();
$values_point_float->[0]{x} = 1.5f;
$values_point_double->[0]{x} = 1.25;
my $value_byte2 = ++$values_point_byte->[0]{x};
my $value_short2 = ++$values_point_short->[0]{x};
my $value_int2 = ++$values_point_int->[0]{x};
my $value_long2 = ++$values_point_long->[0]{x};
my $value_float2 = ++$values_point_float->[0]{x};
my $value_double2 = ++$values_point_double->[0]{x};
}
# Increment long
{
my $nums = new int[2];
++$nums->[0];
warn $nums->[0];
}
{
my $nums = new int[2];
my $var2 = $nums->[0] = $nums->[1] = 1;
}
{
my $nums = new int[1];
my $var2 = $nums->[0] = 5;
warn $var2;
}
{
my $v1 : int;
my $v2 : int;
my $v3 : int;
$v3 = $v2 = $v1 = 543;
warn $v2;
warn $v3;
}
{
my $nums = new int[1];
my $var1 = 5;
my $var2 = $nums->[0] = $var1;
warn $var2;
}
{
my $num : string = 1;
}
{
my $point1 : TestCase::Point_3d;
$point1->{x} = 1.25;
$point1->{y} = 0.5;
$point1->{z} = 0.125;
my $point1_ref = \$point1;
my $point2 = $$point1_ref;
if ($point2->{x} == 1.25 && $point2->{y} == 0.5 && $point2->{z} == 0.125) {
1;
}
}
{
my $z : TestCase::Complex_2d;
$z->{re} = 0.25;
$z->{im} = 0.5;
my $z_ref = \$z;
my $z_re = $z_ref->{re};
my $z_im = $z_ref->{im};
print($z_re . " " . $z_im . "\n");
my $out : TestCase::Complex_2d;
TestCase->ref_sum_complex($z, $z, \$out);
print($out->{re} . " " . $out->{im} . "\n");
}
{
my $z1 : TestCase::Complex_2d;
$z1->{re} = 0.25;
$z1->{im} = 0.5;
my $z1_ref = \$z1;
my $z2 = $$z1_ref;
}
{
my $out : double;
TestCase->ref_sum(0.25, 0.5, \$out);
print($out . "\n");
}
{
my $num = 4;
my $num_ref = \$num;
my $num2 = $$num_ref;
$$num_ref = 5;
print($num2 . "\n");
print($num . "\n");
}
{
my $cb_obj = method : long ($x1 : long, $x2 : long) {
return $x1 * $x2;
};
my $ret = $cb_obj->(4L, 5L);
print($ret . "\n");
}
{
my $array = [1, 2, 5, 7, 9, 3, 4, 10];
print($array->[7] . "\n");
}
{
my $strings = ["abc", "def", "hij"];
print($strings->[2] . "\n");
}
{
my $nums1 = new TestCase::Complex_2d[10];
$nums1->[9]{re} = 5;
$nums1->[9]{im} = 9;
my $nums1_9_re = $nums1->[9]{re};
my $nums1_9_im = $nums1->[9]{im};
print($nums1->[9]{re} . "\n");
print($nums1_9_im . "\n");
my $nums2 = $nums1->[9];
print($nums1->[9]{re} . "\n");
print($nums1->[9]{im} . "\n");
$nums1->[5] = $nums2;
print($nums1->[5]{re} . "\n");
print($nums1->[5]{im} . "\n");
}
{
my $z1 : TestCase::Complex_2d;
$z1->{re} = 0.5;
$z1->{im} = 0.25;
my $z2 : TestCase::Complex_2d;
$z2->{re} = 1.0;
$z2->{im} = 0.5;
my $z3 = TestCase::ComplexCalc->add($z1, $z2);
my $z3_re = $z3->{re};
my $z3_im = $z3->{im};
print($z3_re . "\n");
print($z3_im . "\n");
}
{
my $z : TestCase::Complex_2d;
$z->{re} = 0.5;
$z->{im} = 0.25;
my $re = $z->{re};
my $im = $z->{im};
print($re . "\n");
print($im . "\n");
my $z2 = $z;
my $z2_re = $z2->{re};
my $z2_im = $z2->{im};
print($z2_re . "\n");
print($z2_im . "\n");
}
{
my $total = TestCase->sum0(TestCase->sum0(1, 2), TestCase->sum0(3, 4));
}
# Multi array init
{
my $nums1 = [
[1, 2, 3],
[5, 6, 7]
];
}
{
my $nums1 = [1, 2, 3];
my $nums2 = [1.0, 2, 3];
print($nums2->[2] . "\n");
}
# Pre increment and assign
{
my $num1 = 0;
my $num2 = ++$num1;
print($num2 . "\n");
}
# Pre decrement and assign
{
my $num1 = 0;
my $num2 = --$num1;
print($num2 . "\n");
}
# Post increment and assign
{
my $num1 = 0;
my $num2 = $num1++;
print($num2 . "\n");
}
# Post decrement and assign
{
my $num1 = 0;
my $num2 = $num1--;
print($num2 . "\n");
}
# UNDEF
{
$CLASS_VAR_TEST_CASE = undef;
$@ = undef;
{
my $test_case = new TestCase;
$test_case->{minimal} = undef;
}
{
my $nums = new TestCase[3];
$nums->[0] = undef;
}
{
my $minimal = TestCase::Minimal->new;
$minimal = undef;
}
{
TestCase->receive_undef(undef);
}
}
# Concat
{
my $str1 = "a";
my $str2 = "b";
$str2 .= $str1;
}
# Create object in loop
for (my $i = 0; $i < 3; $i++) {
my $minimal = TestCase::Minimal->new;
}
# Assign same variable
{
my $var1 = TestCase::Minimal->new;
$var1 = $var1;
}
print(2.23e-9 . "\n");
# sort
{
my $minimals = new TestCase::Minimal[3];
$minimals->[0] = TestCase::Minimal->new;
$minimals->[0]{x} = 3;
$minimals->[1] = TestCase::Minimal->new;
$minimals->[1]{x} = 1;
$minimals->[2] = TestCase::Minimal->new;
$minimals->[2]{x} = 2;
TestCase->sort_objectect($minimals, method : int ($object1 : object, $object2 : object) {
my $minimal1 = (TestCase::Minimal)$object1;
my $minimal2 = (TestCase::Minimal)$object2;
my $x1 = $minimal1->{x};
my $x2 = $minimal2->{x};
if ($x1 > $x2) {
return 1;
}
elsif ($x1 < $x2) {
return -1;
}
else {
return 0;
}
});
print($minimals->[0]{x} . " " . $minimals->[1]{x} . " " . $minimals->[2]{x} . "\n");
}
if (!(1 == 2)) {
}
# isa
{
my $minimal = TestCase::Minimal->new;
if ($minimal isa TestCase::Minimal) {
print("isa OK\n");
}
if ($minimal isa TestCase::Simple) {
print("isa NOT OK\n");
}
}
# String comparison operator
{
my $string1 = "abc";
my $string2 = "abc";
if ($string1 eq $string2) {
print("String is same\n");
}
}
{
my $string1 = "abc";
my $string2 = "ab";
if ($string1 ne $string2) {
print("String is different\n");
}
}
my $byte_string = (string)(byte)23;
my $short_string = (string)(short)23;
my $int_string = (string)23;
my $long_string = (string)23L;
my $float_string = (string)0.25f;
my $double_string = (string)0.25;
print($byte_string . "\n");
print($short_string . "\n");
print($int_string . "\n");
print($long_string . "\n");
print($float_string . "\n");
print($double_string . "\n");
{
my $object : object = TestCase::Minimal->new;
my $implement_callback1 : TestCase::Callback1 = TestCase::ImplementCallback1->new;
my $implement_callback2 : TestCase::Callback1 = TestCase::ImplementCallback2->new;
print($implement_callback1->(0, 0) . "\n");
print($implement_callback2->(0, 0) . "\n");
my $minimal = (TestCase::Minimal)$object;
$minimal->{x} = 4;
}
my $num : byte = 127;
eval {
TestCase->exception_die_return_object();
};
=pod
{
my $NUM = 0;
}
=cut
{
my $num = TestCase->sum0(1, 2);
print($num . "\n");
}
{
$TestCase::CLASS_VAR_TEST_CASE = undef;
}
{
my $num = 0xFFFFFFF0;
my $num2 = ~$num;
}
{
my $values = [1, 2, 3];
print($values->[0] . "\n");
}
{
my $values : int[];
$values = [1, 2, 3];
}
{
my $var = $CLASS_VAR_INT;
$CLASS_VAR_INT = 1;
if ($CLASS_VAR_INT == 0) {
$CLASS_VAR_INT = 1;
if ($CLASS_VAR_INT == 1) {
return 1;
}
}
my $str = "" . $CLASS_VAR_INT;
}
{
my $var = $TestCase::CLASS_VAR_INT;
$TestCase::CLASS_VAR_INT = 1;
if ($TestCase::CLASS_VAR_INT == 0) {
$TestCase::CLASS_VAR_INT = 1;
if ($TestCase::CLASS_VAR_INT == 1) {
return 1;
}
}
my $str = "" . $TestCase::CLASS_VAR_INT;
}
=pod
{
my $simple1 = new TestCase::Simple;
$simple1->{private_field};
}
=cut
{
my $test_case = new TestCase;
$test_case->{private_field};
}
warn "warn";
warn 1;
warn 1L;
warn 0.5f;
warn 0.5;
warn "warn";
warn 1;
warn 1L;
warn 0.5f;
warn 0.5;
# .
{
my $foo = "abc" . "def";
}
{
my $num = 1;
$num += 4;
print($num . "\n");
}
{
TestCase->error_eval_call();
}
{
# error_call_stack();
1;
}
{
my $ret = TestCase->error_eval();
print($ret . "\n");
}
TestCase->error_eval();
my $dest = TestCase::Destructor->new();
# enum
{
TestCase->BYTE_MAX();
TestCase->BYTE_MIN();
TestCase->SHORT_MAX();
TestCase->SHORT_MIN();
TestCase->INT_MAX();
TestCase->INT_MIN();
TestCase->LONG_MAX();
TestCase->LONG_MIN();
}
# Field set and get
{
my $test = new TestCase;
$test->{x_byte} = TestCase->BYTE_MAX();
$test->{x_short} = TestCase->SHORT_MAX();
$test->{x_int} = TestCase->INT_MAX();
$test->{x_long} = TestCase->LONG_MAX();
$test->{x_float} = TestCase->FLOAT_PRECICE();
$test->{x_double} = TestCase->DOUBLE_PRECICE();
}
# Weaken
{
my $num = TestCase->weaken_reference_count1_object();
}
# Weaken
{
my $test = new TestCase;
$test->{next_test} = $test;
weaken $test->{next_test};
}
TestCase->call_void();
print("a" . "\n");
# Default return value object
if (TestCase->default_return_value_object_method() == undef) {
if (TestCase->default_return_value_object_method_empty() == undef) {
1;
}
}
# Get object from freelist
{
TestCase->check_freelist();
my $result = new int[65];
$result->[64] = 0;
}
my $ppp = [
1,
2,
3
];
# Logical or
{
if (1 || 0) {
print("Logical or" . "\n");
}
}
# Logical and
{
if (1 && 1) {
print("Logical and" . "\n");
}
}
# Constant e
{
my $num = 0.25E+3;
print($num . "\n");
}
# Constant e
{
my $num = 0.25E-3f;
print($num . "\n");
}
# Convert to string to byte[]
{
my $string = "abc";
# my $byte = $string->[0];
}
# MIN long constant;
{
my $num = -9223372036854775808L;
print($num . "\n");
}
{
my $var = 3;
while (my $var = 964) {
print($var . "\n");
last;
}
}
{
my $error = "First";
$@ = "Error";
if (my $error = $@) {
print($error . "\n");
}
}
# Check for third part bug
{
for (my $i = 0; $i < 260; $i++) {
}
}
# Exception variable
{
$@ = "Exception";
print($@ . "\n");
}
# $array->[0]{x}
{
my $objs = new TestCase::Minimal[3];
$objs->[0] = TestCase::Minimal->new();
$objs->[0]{x} = 111;
print($objs->[0]{x} . "\n");
}
# $obj->{x}[0]
{
my $obj = TestCase::Simple->new();
$obj->{values1} = new int[5];
$obj->{values1}[0] = 221;
print($obj->{values1}[0] . "\n");
}
# Call new method without variable
{
TestCase::Minimal->new();
TestCase->sum0(1, 3);
}
# Create temporary varialbe
{
TestCase::Minimal->new();
TestCase::Minimal->new();
TestCase::Minimal->new()->{x};
}
my $object1 = TestCase::Minimal->new();
# last
{
while (1) {
my $object1 = TestCase::Minimal->new();
my $object2 = TestCase::Minimal->new();
{
my $obj3 = TestCase::Minimal->new();
last;
next;
}
}
}
# String escape character
{
my $string = "abc\"\'\\\n\t\b\r\fdef";
print($string . "\n");
}
# Escape sequence
{
my $ch1 = '\"';
my $ch2 = '\'';
my $ch3 = '\\';
my $ch4 = '\n';
my $ch5 = '\t';
my $ch6 = '\x08';
my $ch7 = '\r';
my $ch8 = '\f';
}
# char null string
{
my $ch : byte = (byte)0x04;
}
# char
{
my $ch : byte = 'a';
}
# Malloc mutil array
{
my $nums : int[][] = new int[][3];
$nums->[0] = new int[1];
$nums->[0][0] = 178;
print($nums->[0][0] . "\n");
}
# Declare mutil array
{
my $nums : int[][];
}
# Core functions
{
print((byte)1 . "\n");
print((short)1 . "\n");
print(1 . "\n");
print(1L . "\n");
print(1f . "\n");
print(1.0 . "\n");
print("end\n");
}
{
my $nums = new int[258];
my $len = @$nums;
for (my $i = 0; $i < $len; $i++) {
$nums->[$i] = $i;
}
for (my $i = 0; $i < @$nums; $i++) {
$nums->[$i] = $i;
}
}
{
my $nums = new int[2000000];
my $len = scalar @$nums;
my $i = 0;
for ($i = 0; $i < $len; $i = $i + 1) {
$nums->[$i] = $i;
}
print($i . "\n");
print($nums->[$i - 1] . "\n");
}
{
my $nums = new int[2000000];
my $len = scalar @{$nums};
my $i = 0;
for ($i = 0; $i < $len; $i = $i + 1) {
$nums->[$i] = $i;
}
print($i . "\n");
print($nums->[$i - 1] . "\n");
}
# object to get long field is undef
#{
# my $obj : TestCase::Minimal;
# $obj{x} = 1L;
#}
# object to get long field is undef
#{
# my $obj : TestCase::Minimal;
# $obj{x};
#}
# Index is out of range
#{
# my $nums = new int[3];
# $nums->[3] = 1;
#}
# Index is out of range
#{
# my $nums = new int[3];
# $nums->[-1] = 3;
#}
# Array is undef
#{
# my $nums : int[];
# $nums->[0] = 1;
#}
# Index is out of range
#{
# my $nums = new int[3];
# $nums->[3];
#}
# Index is out of range
#{
# my $nums = new int[3];
# $nums->[-1];
#}
# Array is undef
#{
# my $nums : int[];
# $nums->[0];
#}
{
TestCase::Minimal->new();
}
{
my $object1 = TestCase::Minimal->new();
my $object2 : TestCase::Minimal;
my $obj3 : TestCase::Minimal = undef;
}
# Increment byte
{
my $num = (byte)1;
$num++;
print($num . "\n");
}
# Increment short
{
my $num = (short)1;
$num++;
print($num . "\n");
}
# increment int
{
my $var = 4;
$var++;
$var--;
--$var;
++$var;
}
# Increment long
{
my $var = (long)4;
$var++;
$var--;
--$var;
++$var;
}
eval {
TestCase->sum0(1, 2);
3;
TestCase->sum0(3, 4);
die "Catch error";
1;
};
{
TestCase->sum0(5, 6);
2;
print("Error" . "\n");
}
{
my $string = "ace";
print($string . "\n");
}
{
my $string = "ace";
print($string . "\n");
}
{
my $num = (byte)3;
print($num . "\n");
my $num2 = (long)1 + (long)$num;
print($num2 . "\n");
}
# get and set field
{
my $m = TestCase::Minimal->new();
$m->{x} = 99;
$m->{y} = 100;
print($m->{x} . "\n");
print($m->{y} . "\n");
}
# Free when assignment
{
my $m = TestCase::Minimal->new();
$m = TestCase::Minimal->new();
}
# left is object, right is undef
{
my $obj : TestCase::Minimal = undef;
}
if (1) {
2;
if (3) {
4;
}
elsif (8) {
9;
}
else {
5;
}
}
else {
6;
}
7;
print(TestCase->sum0(1, 1) . "\n");
print(TestCase->sum2(1, 2) . "\n");
# Constant float
print(0.3f . "\n");
print(1f . "\n");
print(2f . "\n");
print(1.2f . "\n");
# Constant double
print(0d . "\n");
print(1d . "\n");
print(1.2 . "\n");
# Constant int
print(-2147483648 . "\n");
print(-32769 . "\n");
print(-32768 . "\n");
print(-129 . "\n");
print(-128 . "\n");
print(-2 . "\n");
print(-1 . "\n");
print(0 . "\n");
print(1 . "\n");
print(2 . "\n");
print(3 . "\n");
print(4 . "\n");
print(5 . "\n");
print(6 . "\n");
print(127 . "\n");
print(128 . "\n");
print(255 . "\n");
print(256 . "\n");
print(32767 . "\n");
print(32768 . "\n");
print(65535 . "\n");
print(65536 . "\n");
print(2147483647 . "\n");
# Constant long
print(-1L . "\n");
print(0L . "\n");
print(1L . "\n");
print(2L . "\n");
print(9223372036854775807L . "\n");
print(-9223372036854775807L . "\n");
print(-2147483648L . "\n");
print(-32769L . "\n");
print(-32768L . "\n");
print(-129L . "\n");
print(-128L . "\n");
print(-2L . "\n");
print(-1L . "\n");
print(0L . "\n");
print(1L . "\n");
print(2L . "\n");
print(3L . "\n");
print(4L . "\n");
print(5L . "\n");
print(6L . "\n");
print(127L . "\n");
print(128L . "\n");
print(255L . "\n");
print(256L . "\n");
print(32767L . "\n");
print(32768L . "\n");
print(65535L . "\n");
print(65536L . "\n");
print(2147483647L . "\n");
print(0xFFL . "\n");
"abc";
# Table switch int
{
my $num = 3;
switch($num) {
case TestCase::EnumD->THREE(): {
print(1 . "\n");
break;
}
case TestCase::EnumD->FORE(): {
print(2 . "\n");
break;
}
case 5: {
print(3 . "\n");
break;
}
default: {
print(5 . "\n");
}
}
}
# Lookup switch int
{
my $num = 3;
switch ($num) {
case 1: {
print(1 . "\n");
break;
}
case 3: {
print(2 . "\n");
break;
}
case 10000: {
print(2 . "\n");
break;
}
default: {
print(5 . "\n");
}
}
}
# {
# my $num = 5;
# switch($num) {
# default:
# print(5 . "\n");
# }
# }
# my $num;
# my $num1 = undef;
if (1) {
3;
if (2) {
4;
}
5;
}
6;
my $simple3 : TestCase::Simple = TestCase::Simple->new();
print($simple3->{x} . "\n");
$simple3->{x};
$simple3->{y} = 2;
$simple3->{x};
$simple3->{y};
my $simple2 : TestCase::Simple = TestCase::Simple->new();
if (1) { }
if (1 == 1) {
}
if (1 != 1) {
}
if (1 <= 1) {
}
if (1 < 1) {
}
if (1 >= 1) {
}
if (1 > 1) {
}
if (!1) { }
if (1L) { }
if (1.5) { }
if ($simple2) { }
if (undef) {
}
if ($simple2 == undef) {
}
if (undef == $simple2) {
}
if (undef == undef) {
}
if (undef != undef) {
}
if (5L || 6L) {
}
if (5L && 6L) {
}
if (!1L) {
}
if (1L > 2L) {
3L;
4L;
};
5L;
if (1.2 > 2.0) {};
if (1.2 >= 2.0) {};
if (1.2 < 2.0) {};
if (1.2 <= 2.0) {};
if (1.2 == 1.0) { }
if (1.2 != 2.0) { };
if (1 > 2) {};
if (1 >= 2) {};
if (1 < 2) {};
if (1 <= 2) {};
if (1 == 1) { }
if (1 != 2) { };
{
my $nums = new int[3];
$nums->[0] = 13;
$nums->[1] = 14;
print($nums->[0] . "\n");
print($nums->[1] . "\n");
}
{
my $nums : long[] = new long[3];
$nums->[0] = 11L;
$nums->[1] = 12L;
print($nums->[0] . "\n");
print($nums->[1] . "\n");
print(@$nums . "\n");
my $nums_length : int = @$nums;
}
my $simple : TestCase::Simple = TestCase::Simple->new();
my $v1 : int;
my $v2 : int;
my $v3 : int;
$v3 = $v2 = $v1 = 543;
print($v3 . "\n");
100;
1000;
1 << 2;
1 >> 2;
1 >>> 2;
TestCase::EnumA->ONE();
TestCase::EnumA->TWO();
TestCase::EnumA->ONE();
TestCase::EnumA->ONE();
# Basic operation byte
{
1;
}
# Basic operation short
{
1;
}
# Basic operation int
{
1 ^ 4;
1 & 2;
1 | 2;
-3 + +2;
3 - (1 + 2);
5 + 19;
1 + 2;
1 - 2;
1 * 2;
1 / 3;
4 % 6;
}
# Basic operation long
{
1L ^ 4L;
1L & 2L;
1L | 2L;
-3L + +2L;
3L - (1L + 2L);
5L + 19L;
1L + 2L;
1L - 2L;
1L * 2L;
1L / 3L;
4L % 6L;
}
1.2 / 3.0;
1.2f / 3.0f;
1.2 * 4.0;
1.2f * 4.0f;
1.2 + 3.0;
1.2f + 3.0f;
1.2 - 3.0;
1.2f - 3.0f;
# Compare long
{
if (1L > 2L) {};
if (1L >= 2L) {};
if (1L < 2L) {};
if (1L <= 2L) {};
if (1L == 1L) { }
if (1L != 2L) { };
}
my $bar : double = (double)1;
undef;
TestCase->sum0(1, 2);
TestCase->sum0(1, 2);
TestCase->test1();
while (1) {
1;
last;
}
# for (my $i : int = 0; $i < 5; $i = $i + 1) {
# 1;
# last;
# next;
# }
{
my $num0 = (byte)0;
my $num1 = (byte)1;
my $num2 = (byte)2;
my $num3 = (byte)((int)$num0 + (int)$num1 + (int)$num2);
print($num3 . "\n");
}
{
my $num0 = (short)0;
my $num1 = (short)1;
my $num2 = (short)2;
my $num3 = (short)((int)$num0 + (int)$num1 + (int)$num2);
print($num3 . "\n");
}
# my $error : String = "Error";
# die $error;
return 0;
}
# Call void function
static method call_void_method : void ($nums : int[]) {
$nums->[0] = 5;
}
static method call_void : int () {
my $nums = [1];
TestCase->call_void_method($nums);
if ($nums->[0] == 5) {
return 1;
}
return 0;
}
static method test1 : int () {
my $num0 = 1;
my $num1 = 2;
my $num2 = 3;
my $num3 = 4;
my $num4 = 5;
return 0;
}
static method sum4 : long ($num1 : long, $num2 : long) {
return $num1 + $num2;
}
static method sum3 : int ($simple : TestCase::Simple, $foo : long, $bar : float) {
if (3) {
}
if (3) {
1;
}
elsif (4) {
4;
}
else {
}
if (3) {
1;
}
elsif (4) {
4;
}
elsif (5) {
}
else {
}
if (1) {
}
else {
}
TestCase->array_new();
return 2;
}
static method sum1 : long ($num1 : long, $num2 : long) {
return $num1 + $num2;
}
static method sum0 : int ($num1 : int, $num2 : int) {
return $num1 + $num2;
}
static method sum2 : int ($num1 : int, $num2 : int) {
# die "Error";
my $num3 = TestCase->sum0($num1, $num2);
return $num3 + 3;
}
static method increfcount : int ($test : TestCase::Minimal, $num : int) {
my $aaa = TestCase::Minimal->new();
}
static method decinctest : int ($num1 : TestCase::Minimal, $num2 : int, $num3 : TestCase::Minimal) {
{
my $num4 = TestCase::Minimal->new();
my $num5 = TestCase::Minimal->new();
}
return 2;
}
static method return_object : TestCase::Minimal () {
my $obj0 = TestCase::Minimal->new();
{
my $object1 = TestCase::Minimal->new();
my $object2 : TestCase::Minimal;
my $obj3 : TestCase::Minimal = undef;
return $object2;
}
}
static method eval_block : void () {
my $obj0 = TestCase::Minimal->new();
eval {
my $object1 = TestCase::Minimal->new();
my $object2 : TestCase::Minimal;
my $obj3 : TestCase::Minimal = undef;
my $obj_error1 = "Error1";
die $obj_error1;
};
{
my $obj4 = TestCase::Minimal->new();
my $obj5 : TestCase::Minimal;
my $obj6 : TestCase::Minimal = undef;
my $obj_error2 = "Error2";
die $obj_error2;
}
}
static method array_new : int () {
my $nums = new int[3];
return @$nums;
}
static method check_freelist : int[] () {
my $result = new int[63];
my $true_result = new int[1];
return $true_result;
}
static method default_return_value_object_method : TestCase () {
1;
}
static method default_return_value_object_method_empty : TestCase () {
}
static method weaken_reference_count1_object : int (){
my $minimal = TestCase::Minimal->new();
my $test = new TestCase;
$test->{minimal} = $minimal;
$minimal = undef;
weaken $test->{minimal};
if ($test->{minimal} == undef) {
return 1;
}
return 0;
}
static method error : int () {
die "ERROR";
}
static method error_call_stack : int () {
TestCase->error();
}
static method error_eval : int () {
eval {
die "ERROR";
};
if ($@) {
return 1;
}
else {
return 0;
}
}
static method error_eval_call : int () {
eval {
TestCase->error();
};
if ($@) {
return 1;
}
else {
return 0;
}
}
static method exception_die_return_object : TestCase::Minimal () {
die "Error";
}
static method new : TestCase () {
return new TestCase;
}
static method call_method_args_convertion_stab1 : double ($var6 : double) {
return ($var6);
}
static method call_method_args_convertion : int () {
my $return_value1 = TestCase->call_method_args_convertion_stab1(16);
return 0;
}
static method sort_objectect : void ($values : object[], $comparator : TestCase::Comparator) {
my $change_cnt = @$values - 1;
while( $change_cnt > 0){
for (my $i = 0; $i < $change_cnt; $i++) {
my $ret = $comparator->($values->[$i], $values->[$i + 1]);
if ($comparator->($values->[$i], $values->[$i + 1]) == 1) {
my $tmp_value = $values->[$i];
$values->[$i] = $values->[$i + 1];
$values->[$i + 1] = $tmp_value;
}
}
$change_cnt--;
}
}
static method receive_undef : void ($test_case : TestCase) {
}
static method ref_sum : double ($x_in1 : double, $x_in2 : double, $x_out : double*) {
$$x_out = $x_in1 + $x_in2;
}
static method ref_sum_complex : double ($x_in1 : TestCase::Complex_2d, $x_in2 : TestCase::Complex_2d, $x_out : TestCase::Complex_2d*) {
$x_out->{re} = $x_in1->{re} + $x_in2->{re};
$x_out->{im} = $x_in1->{im} + $x_in2->{im};
}
}
=head1 NAME
SPVM::Test - SPVM test class