Skip to content

Commit

Permalink
Test .base for Str argument as well
Browse files Browse the repository at this point in the history
  • Loading branch information
samcv committed Feb 9, 2017
1 parent 2a3e1f9 commit 4bcf18f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
19 changes: 17 additions & 2 deletions S32-num/base.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 48;
plan 60;

# Int
{
Expand All @@ -19,7 +19,22 @@ plan 48;
is 121.base(11,0), '100', 'Integer with 0 digits fraction leaves off radix point';
isa-ok 1.base(10, -1), Failure, "negative digits arg fails";
}

# Int with Str argument
{
is 0.base('8'), '0', '0.base(something)';
is 10.base('1'), '1111111111', '10.base(1)';
# RT #112872
is 0.base('2'), '0', '0.base(2)';
is 42.base('10'), '42', '42.base(10)';
is 42.base('16'), '2A', '42.base(16)';
is 42.base('2') , '101010', '42.base(2)';
is 35.base('36'), 'Z', '35.base(36)';
is 36.base('36'), '10', '36.base(36)';
is (-12).base('16'), '-C', '(-12).base(16)';
is 121.base('11',3), '100.000', 'Integer digits are 0s';
is 121.base('11',0), '100', 'Integer with 0 digits fraction leaves off radix point';
isa-ok 1.base('10', -1), Failure, "negative digits arg fails";
}
# Rat
# RT #112900
#?niecza skip "Rat.base NYI"
Expand Down
4 changes: 2 additions & 2 deletions S32-str/parse-base.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 56 * 2;
plan 55 * 2 + 1;

constant $fancy-nums = '໕໖໗۶۷៤៥123';
constant $fancy-nums-value = 5676745123;
Expand All @@ -20,7 +20,6 @@ for &parse-base, Str.^lookup('parse-base') -> &pb {

is-deeply pb('1111', $_), +":{$_}<1111>", "1111 in base-$_" ~ $t
for 2..36;
is-deeply pb('1111', 1), 4, "1111 in base-1 is 4";
is-approx pb($all-chars, 36), $all-chars-result,
'full character set' ~ $t;

Expand Down Expand Up @@ -75,5 +74,6 @@ for &parse-base, Str.^lookup('parse-base') -> &pb {
reason => /'base-9'/, :2pos, :source<1.x>,
'invalid char in first position of fractional part, base 9' ~ $t;
}
is-deeply '1111'.parse-base(1), 4, "parse-base 1111 in base-1 is 4";

# vim: ft=perl6

0 comments on commit 4bcf18f

Please sign in to comment.