2018-12-20 16:25:19 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
require 5.008;
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
require TestDriver;
|
|
|
|
|
|
|
|
my $td = new TestDriver('numrange');
|
|
|
|
|
|
|
|
my @nrange_tests = (
|
|
|
|
[",5",
|
2024-01-01 14:51:05 +00:00
|
|
|
"error at * in numeric range *,5: invalid range syntax",
|
2018-12-20 16:25:19 +00:00
|
|
|
2],
|
|
|
|
["4,,5",
|
2024-01-01 14:51:05 +00:00
|
|
|
"error at * in numeric range 4,*,5: invalid range syntax",
|
2018-12-20 16:25:19 +00:00
|
|
|
2],
|
|
|
|
["4,5,",
|
2024-01-01 14:51:05 +00:00
|
|
|
"error at * in numeric range 4,5,*: trailing comma",
|
2018-12-20 16:25:19 +00:00
|
|
|
2],
|
|
|
|
["z1,",
|
2024-01-01 14:51:05 +00:00
|
|
|
"error at * in numeric range *z1,: invalid range syntax",
|
2018-12-20 16:25:19 +00:00
|
|
|
2],
|
|
|
|
["1z,",
|
2024-01-01 14:51:05 +00:00
|
|
|
"error at * in numeric range *1z,: invalid range syntax",
|
2018-12-20 16:25:19 +00:00
|
|
|
2],
|
|
|
|
["1-5?",
|
2024-01-01 14:51:05 +00:00
|
|
|
"error at * in numeric range *1-5?: invalid range syntax",
|
2018-12-20 16:25:19 +00:00
|
|
|
2],
|
|
|
|
["1-30",
|
2024-01-01 14:51:05 +00:00
|
|
|
"error at * in numeric range *1-30: number 30 out of range",
|
2018-12-20 16:25:19 +00:00
|
|
|
2],
|
|
|
|
["1-10,0,5",
|
2024-01-01 14:51:05 +00:00
|
|
|
"error at * in numeric range 1-10,*0,5: number 0 out of range",
|
2018-12-20 16:25:19 +00:00
|
|
|
2],
|
|
|
|
["1-10,1234,5",
|
2024-01-01 14:51:05 +00:00
|
|
|
"error at * in numeric range 1-10,*1234,5: number 1234 out of range",
|
2018-12-20 16:25:19 +00:00
|
|
|
2],
|
|
|
|
["1,r,3",
|
2024-01-01 14:51:05 +00:00
|
|
|
"error at * in numeric range 1,*r,3: invalid range syntax",
|
2018-12-20 16:25:19 +00:00
|
|
|
2],
|
|
|
|
["1,r16,3",
|
2024-01-01 14:51:05 +00:00
|
|
|
"error at * in numeric range 1,*r16,3: number 0 out of range",
|
2018-12-20 16:25:19 +00:00
|
|
|
2],
|
|
|
|
["1,3,5-10,z-13,13,9,z,2,r2-r4",
|
|
|
|
"numeric range 1,3,5-10,z-13,13,9,z,2,r2-r4" .
|
|
|
|
" -> 1 3 5 6 7 8 9 10 15 14 13 13 9 15 2 14 13 12",
|
|
|
|
0],
|
|
|
|
["r1-r15", # r\d+ at end
|
|
|
|
"numeric range r1-r15" .
|
|
|
|
" -> 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
|
|
|
|
0],
|
2019-11-09 16:54:16 +00:00
|
|
|
["1-10:quack",
|
2024-01-01 14:51:05 +00:00
|
|
|
"error at * in numeric range 1-10*:quack: expected :even or :odd",
|
2019-11-09 16:54:16 +00:00
|
|
|
2],
|
|
|
|
["1-10:",
|
2024-01-01 14:51:05 +00:00
|
|
|
"error at * in numeric range 1-10*:: expected :even or :odd",
|
2019-11-09 16:54:16 +00:00
|
|
|
2],
|
|
|
|
["1-10,r:",
|
2024-01-01 14:51:05 +00:00
|
|
|
"error at * in numeric range 1-10,r*:: expected :even or :odd",
|
2019-11-09 16:54:16 +00:00
|
|
|
2],
|
|
|
|
["1-10,:",
|
2024-01-01 14:51:05 +00:00
|
|
|
"error at * in numeric range 1-10,*:: expected :even or :odd",
|
2019-11-09 16:54:16 +00:00
|
|
|
2],
|
|
|
|
["1-6,8-12:odd",
|
|
|
|
"numeric range 1-6,8-12:odd -> 1 3 5 8 10 12",
|
|
|
|
0],
|
|
|
|
["1-6,8-12:even",
|
|
|
|
"numeric range 1-6,8-12:even -> 2 4 6 9 11",
|
|
|
|
0],
|
2024-01-01 15:14:01 +00:00
|
|
|
["x1",
|
|
|
|
"error at * in numeric range *x1: first range group may not be an exclusion",
|
|
|
|
2],
|
|
|
|
["4-10,x7-9,12-8,xr5",
|
|
|
|
"numeric range 4-10,x7-9,12-8,xr5 -> 4 5 6 10 12 10 9 8",
|
|
|
|
0],
|
2018-12-20 16:25:19 +00:00
|
|
|
);
|
|
|
|
foreach my $d (@nrange_tests)
|
|
|
|
{
|
|
|
|
my ($range, $output, $status) = @$d;
|
|
|
|
$td->runtest("numeric range $range",
|
|
|
|
{$td->COMMAND => ['numrange', $range],
|
|
|
|
$td->FILTER => "grep 'numeric range'"},
|
|
|
|
{$td->STRING => $output . "\n", $td->EXIT_STATUS => $status},
|
|
|
|
$td->NORMALIZE_NEWLINES);
|
|
|
|
}
|
|
|
|
|
|
|
|
$td->report(scalar(@nrange_tests));
|