From 4e1bcfccc6b711e64abffa5188616c811700ed99 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Thu, 11 Jan 2018 11:22:07 -0500 Subject: [PATCH] Test .succ/.pred on allomorphs Closes https://github.com/rakudo/rakudo/issues/1387 Rakudo fix: https://github.com/rakudo/rakudo/commit/631875fcdf --- S02-literals/allomorphic.t | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/S02-literals/allomorphic.t b/S02-literals/allomorphic.t index 88e0f0f30c..626f9cc9d7 100644 --- a/S02-literals/allomorphic.t +++ b/S02-literals/allomorphic.t @@ -7,7 +7,7 @@ use Test::Util; # L -plan 110; +plan 112; ## Sanity tests (if your compiler fails these, there's not much hope for the ## rest of the test) @@ -342,3 +342,39 @@ subtest '.ACCEPTS' => { isa-ok val(<1 2 3> ), List, 'val List candidate returns List by default (2)'; isa-ok val(<1 2 3>.Slip), Slip, 'val List candidate preserves slip-ness if passed Slip'; } + +# https://github.com/rakudo/rakudo/issues/1387 +subtest '.succ on allomorphs' => { + # math on allomorphs collapses them to standard numerics + plan 5*my @tests = <2> => 3, <2e0> => 3e0, <2.1> => 3.1, <2+1i > => <3+1i>; + + for @tests -> (:key($from), :value($to)) { + is-deeply $from.succ, $to, '.succ'; + + my $post = $from; + is-deeply $post++, $from, 'postincrement, return value'; + is-deeply $post, $to, 'postincrement, result'; + + my $pre = $from; + is-deeply ++$pre, $to, 'preincrement, return value'; + is-deeply $pre, $to, 'preincrement, result'; + } +} + +# https://github.com/rakudo/rakudo/issues/1387 +subtest '.pred on allomorphs' => { + # math on allomorphs collapses them to standard numerics + plan 5*my @tests = <2> => 1, <2e0> => 1e0, <2.1> => 1.1, <2+1i > => <1+1i>; + + for @tests -> (:key($from), :value($to)) { + is-deeply $from.pred, $to, '.pred'; + + my $post = $from; + is-deeply $post--, $from, 'postdecrement, return value'; + is-deeply $post, $to, 'postdecrement, result'; + + my $pre = $from; + is-deeply --$pre, $to, 'predecrement, return value'; + is-deeply $pre, $to, 'predecrement, result'; + } +}