Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add another range test case around the match operator, and an equival…

…ent test WRT string variables.

git-svn-id: http://svn.pugscode.org/pugs@27745 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
commit d4459dc2abffdce01401f869a33487ac608f65df 1 parent 0e9a37b
colomon authored
Showing with 29 additions and 3 deletions.
  1. +29 −3 S03-operators/range.t
View
32 S03-operators/range.t
@@ -2,7 +2,7 @@ use v6;
use Test;
-plan 90;
+plan 104;
# 3..2 must *not* produce "3 2". Use reverse to get a reversed range. -lwall
@@ -138,6 +138,21 @@ is (1..6 Z 'a' .. 'c').join, '1a2b3c', 'Ranges and infix:<Z>';
is (1..3).reduce({ $^a + $^b}), 6, '.reduce works on ranges';
}
+# test that range operands are handled in string context if strings
+{
+ my $range;
+ my $start = "100.B";
+ my $end = "102.B";
+ lives_ok { $range = $start..$end },
+ 'can make range from numeric string vars';
+ is $range.from, $start, 'range starts at start';
+ is $range.from.WHAT, "Str()", 'range start is a string';
+ is $range.to, $end, 'range ends at end';
+ is $range.to.WHAT, "Str()", 'range end is a string';
+ lives_ok { "$range" }, 'can stringify range';
+ is $range.list, ("100.B","101.B","102.B"), 'range is correct';
+}
+
# RT #67882
{
my $range;
@@ -147,7 +162,7 @@ is (1..6 Z 'a' .. 'c').join, '1a2b3c', 'Ranges and infix:<Z>';
is $range.to, 3, 'range ends at three';
#?rakudo 2 skip 'range from match vars'
lives_ok { "$range" }, 'can stringify range';
- is $range, (1,2,3), 'range is correct';
+ is $range.list, (1,2,3), 'range is correct';
}
{
my $range;
@@ -156,7 +171,18 @@ is (1..6 Z 'a' .. 'c').join, '1a2b3c', 'Ranges and infix:<Z>';
is $range.from, 1, 'range starts at one';
is $range.to, 3, 'range ends at three';
lives_ok { "$range" }, 'can stringify range';
- is $range, (1,2,3), 'range is correct';
+ is $range.list, (1,2,3), 'range is correct';
+}
+{
+ my $range;
+ lives_ok { '1 3' ~~ /(\d+) \s (\d+)/; $range = ~$0..~$1 },
+ 'can make range from match vars with string context forced';
+ is $range.from, 1, 'range starts at one';
+ is $range.from.WHAT, "Str()", 'range start is a string';
+ is $range.to, 3, 'range ends at three';
+ is $range.to.WHAT, "Str()", 'range end is a string';
+ lives_ok { "$range" }, 'can stringify range';
+ is $range.list, <1 2 3>, 'range is correct';
}
# For tests involving :by, see t/spec/S03-operators/range-by.t
Please sign in to comment.
Something went wrong with that request. Please try again.