Created
January 29, 2015 21:10
-
-
Save usev6/19baafe3390a274d87d0 to your computer and use it in GitHub Desktop.
Attempt to make subst-mutate work on variables of type Numeric
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat subst-mutate-numeric.t | |
use v6; | |
use Test; | |
plan 10; | |
my $foo = 70; | |
my $match = $foo.subst-mutate(7, 2); | |
is $foo, 20, 'can use subst-mutate with variable of type Int'; | |
is $match.Str, 7, 'matched text is correct'; | |
isa_ok $foo, Str, 'type changed to Str after applying method subst-mutate'; | |
$foo = 2/5; | |
$match = $foo.subst-mutate(2, 3); | |
is $foo, 0.4, 'can use subst-mutate with variable of type Rat'; | |
isa_ok $match, Any, 'no match returned'; | |
isa_ok $foo, Str, 'type changed to Str after applying method subst-mutate'; | |
$foo = 2/5; | |
$match = $foo.subst-mutate(4, 6); | |
is $foo, 0.6, 'substition happens after stringification (1)'; | |
is $match.Str, 4, 'matched text is correct'; | |
$foo = pi; | |
$match = $foo.subst-mutate(3, 4, :g); | |
is $foo, 4.14159265458979, 'substition happens after stringification (2)'; | |
is $match.Str, '3 3', 'matched text is correct'; | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And the corresponding change to src/core/Cool.pm (naive approach):