Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

start to systematically test string numification

Also corrects a test in num.t, and removes another wrong test
  • Loading branch information...
commit 0fd99d317c08228a160b831db9a6feaf722ba037 1 parent b32ed21
@moritz moritz authored
Showing with 41 additions and 8 deletions.
  1. +2 −8 S02-builtin_data_types/num.t
  2. +39 −0 S32-str/numeric.t
View
10 S02-builtin_data_types/num.t
@@ -4,7 +4,7 @@ use Test;
#L<S02/Built-In Data Types/Perl intrinsically supports big integers>
-plan 66;
+plan 64;
#?rakudo todo "Num.perl doesn't report the decimal part if it is 0 (RT 69869)"
isa_ok( eval(1.Num.perl), Num, 'eval 1.Num.perl is Num' );
@@ -149,12 +149,6 @@ isa_ok(1 / 1, Rat);
#L<S02/Built-In Data Types/Num may support arbitrary-precision floating-point>
-{
- my $a = "1.01";
- isa_ok(+$a, "Num");
- is(+$a, 1.01, "1.01 numifies to 1.01");
-}
-
#?rakudo todo 'smart numification'
{
my $a = "0d01.01";
@@ -175,7 +169,7 @@ isa_ok(1 / 1, Rat);
#?rakudo todo 'smart numification'
{
my $a = "0d0101";
- isa_ok(+$a, Rat);
+ isa_ok(+$a, Int);
is(+$a, 101, "0d0101 numifies to 101");
}
View
39 S32-str/numeric.t
@@ -0,0 +1,39 @@
+use v6;
+use Test;
+
+#?DOES 2
+sub check($str, $expected_type, $expected_number, $desc?) {
+ my $result = +$str;
+ my $description = $desc // $str;
+ is $result.WHAT.gist, $expected_type.gist, "$description (type)";
+ ok $result == $expected_number, "$description (value)"
+ or diag(
+ "got: $result\n"
+ ~ "expected: $expected_number"
+ );
+}
+
+check '123', Int, 123;
+check '+123', Int, 123;
+check '-123', Int, -123;
+
+check '123.', Rat, 123;
+check '123.0', Rat, 123;
+check '-123.0', Rat, 123;
+check '+123.0', Rat, 123;
+
+check '123e0', Num, 123;
+check '-123e0', Num, -123;
+check '+123e0', Num, 123;
+check '123e-0', Num, 123;
+check '-123e+0', Num, -123;
+check '123E0', Num, 123;
+check '-123E0', Num, -123;
+check '+123E0', Num, 123;
+check '123E-0', Num, 123;
+check '-123E+0', Num, -123;
+
+
+done;
+
+# vim: ft=perl6
Please sign in to comment.
Something went wrong with that request. Please try again.