|
1 | 1 | use QAST;
|
2 | 2 |
|
3 |
| -plan(149); |
| 3 | +plan(164); |
4 | 4 |
|
5 | 5 | # Following a test infrastructure.
|
6 | 6 | sub compile_qast($qast) {
|
@@ -1899,6 +1899,80 @@ test_qast_result(
|
1899 | 1899 | ok($r.twice eq '244', '...and it has the correct value');
|
1900 | 1900 | }
|
1901 | 1901 | );
|
| 1902 | + |
| 1903 | + test_qast_result( |
| 1904 | + QAST::CompUnit.new( |
| 1905 | + :hll<foo>, |
| 1906 | + QAST::Block.new( |
| 1907 | + QAST::Op.new(:op<takeclosure>, # needed for JVM |
| 1908 | + QAST::Block.new( |
| 1909 | + QAST::Var.new(:name<$foo>, :scope<local>, :decl<param>) |
| 1910 | + ) |
| 1911 | + ) |
| 1912 | + ) |
| 1913 | + ), |
| 1914 | + -> $block { |
| 1915 | + my int $int := 100; |
| 1916 | + my num $num := 10.5; |
| 1917 | + my str $str := 'hi'; |
| 1918 | + |
| 1919 | + |
| 1920 | + my $boxed_int := $block($int); |
| 1921 | + ok(nqp::istype($boxed_int, $int_boxer), 'the native int passed as arg is boxed to the correct type'); |
| 1922 | + is(nqp::unbox_i($boxed_int), 100, '...and has the right value'); |
| 1923 | + |
| 1924 | + my $boxed_num := $block($num); |
| 1925 | + ok(nqp::istype($boxed_num, $num_boxer), 'the native num passed as arg is boxed to the correct type'); |
| 1926 | + is(nqp::unbox_n($boxed_num), 10.5, '...and has the right value'); |
| 1927 | + |
| 1928 | + my $boxed_str := $block($str); |
| 1929 | + ok(nqp::istype($boxed_str, $str_boxer), 'the native str passed as arg is boxed to the correct type'); |
| 1930 | + is(nqp::unbox_s($boxed_str), 'hi', '...and has the right value'); |
| 1931 | + |
| 1932 | + my $autoboxed_int := $int; |
| 1933 | + my $not_boxed_twice_int := $block($autoboxed_int); |
| 1934 | + ok(nqp::eqaddr($autoboxed_int, $not_boxed_twice_int), "alread autoboxed ints don't get boxed twice"); |
| 1935 | + |
| 1936 | + my $autoboxed_str := $str; |
| 1937 | + my $not_boxed_twice_str := $block($autoboxed_str); |
| 1938 | + ok(nqp::eqaddr($autoboxed_str, $not_boxed_twice_str), "alread autoboxed strs don't get boxed twice"); |
| 1939 | + |
| 1940 | + my $autoboxed_num := $num; |
| 1941 | + my $not_boxed_twice_num := $block($autoboxed_num); |
| 1942 | + ok(nqp::eqaddr($autoboxed_num, $not_boxed_twice_num), "alread autoboxed nums don't get boxed twice"); |
| 1943 | + } |
| 1944 | + ); |
| 1945 | + |
| 1946 | + test_qast_result( |
| 1947 | + QAST::CompUnit.new( |
| 1948 | + :hll<foo>, |
| 1949 | + QAST::Block.new( |
| 1950 | + QAST::Op.new(:op<takeclosure>, # needed for JVM |
| 1951 | + QAST::Block.new( |
| 1952 | + QAST::Var.new(:name<$foo>, :scope<local>, :decl<param>, :slurpy) |
| 1953 | + ) |
| 1954 | + ) |
| 1955 | + ) |
| 1956 | + ), |
| 1957 | + -> $block { |
| 1958 | + my int $int := 100; |
| 1959 | + my num $num := 10.5; |
| 1960 | + my str $str := 'hi'; |
| 1961 | + |
| 1962 | + |
| 1963 | + my $boxed_int := $block($int)[0]; |
| 1964 | + ok(nqp::istype($boxed_int, $int_boxer), 'the native int passed as slurpy arg is boxed to the correct type'); |
| 1965 | + is(nqp::unbox_i($boxed_int), 100, '...and has the right value'); |
| 1966 | + |
| 1967 | + my $boxed_num := $block($num)[0]; |
| 1968 | + ok(nqp::istype($boxed_num, $num_boxer), 'the native num passed as slurpy arg is boxed to the correct type'); |
| 1969 | + is(nqp::unbox_n($boxed_num), 10.5, '...and has the right value'); |
| 1970 | + |
| 1971 | + my $boxed_str := $block($str)[0]; |
| 1972 | + ok(nqp::istype($boxed_str, $str_boxer), 'the native str passed as slurpy arg is boxed to the correct type'); |
| 1973 | + is(nqp::unbox_s($boxed_str), 'hi', '...and has the right value'); |
| 1974 | + } |
| 1975 | + ); |
1902 | 1976 | }
|
1903 | 1977 |
|
1904 | 1978 | test_qast_result(
|
|
0 commit comments