Skip to content

Commit 4bcf18f

Browse files
committed
Test .base for Str argument as well
1 parent 2a3e1f9 commit 4bcf18f

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

S32-num/base.t

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use v6;
22
use Test;
33

4-
plan 48;
4+
plan 60;
55

66
# Int
77
{
@@ -19,7 +19,22 @@ plan 48;
1919
is 121.base(11,0), '100', 'Integer with 0 digits fraction leaves off radix point';
2020
isa-ok 1.base(10, -1), Failure, "negative digits arg fails";
2121
}
22-
22+
# Int with Str argument
23+
{
24+
is 0.base('8'), '0', '0.base(something)';
25+
is 10.base('1'), '1111111111', '10.base(1)';
26+
# RT #112872
27+
is 0.base('2'), '0', '0.base(2)';
28+
is 42.base('10'), '42', '42.base(10)';
29+
is 42.base('16'), '2A', '42.base(16)';
30+
is 42.base('2') , '101010', '42.base(2)';
31+
is 35.base('36'), 'Z', '35.base(36)';
32+
is 36.base('36'), '10', '36.base(36)';
33+
is (-12).base('16'), '-C', '(-12).base(16)';
34+
is 121.base('11',3), '100.000', 'Integer digits are 0s';
35+
is 121.base('11',0), '100', 'Integer with 0 digits fraction leaves off radix point';
36+
isa-ok 1.base('10', -1), Failure, "negative digits arg fails";
37+
}
2338
# Rat
2439
# RT #112900
2540
#?niecza skip "Rat.base NYI"

S32-str/parse-base.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use v6;
22
use Test;
33

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

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

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

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

7979
# vim: ft=perl6

0 commit comments

Comments
 (0)