File: 03-optional-spaces.t

package info (click to toggle)
libgetopt-declare-perl 1.14-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 328 kB
  • sloc: perl: 1,386; makefile: 8
file content (67 lines) | stat: -rw-r--r-- 1,503 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!perl

use lib 'lib';
use strict;
use warnings;
use Test::More tests => 31;

BEGIN { use_ok( 'Getopt::Declare' ); }


# Testing optional whitespaces

my ($spec, $args);
my ($val1, $val2) = (1, 10);


#------------------------------------------------------------------------------#

# No optional whitespaces

$spec = q{ --lines<start>..<stop>	Lines };

@ARGV = ( "--lines$val1..$val2" ); test_lines(1);

#------------------------------------------------------------------------------#

# Some optional whitespaces

$spec = q{ --lines <start>-<stop>	Lines };

@ARGV = ( "--lines$val1-$val2" ); test_lines(1);

@ARGV = ( "--lines", "$val1-$val2" ); test_lines();

#------------------------------------------------------------------------------#

# All whitespaces optional

$spec = q{ --lines <start> - <stop>	Lines };

@ARGV = ( "--lines", $val1, "-", $val2 ); test_lines(1);

@ARGV = ( "--lines", $val1, "-$val2" ); test_lines();

@ARGV = ( "--lines$val1", "-$val2" ); test_lines();

@ARGV = ( "--lines$val1-$val2" ); test_lines();

@ARGV = ( "--lines", "$val1-$val2" ); test_lines();

@ARGV = ( "--lines", "$val1-", $val2 ); test_lines();

@ARGV = ( "--lines$val1-", "$val2" ); test_lines();

#------------------------------------------------------------------------------#


sub test_lines {
  my ($print) = @_;
  my $desc;
  $desc = $spec if $print;
  ok $args = Getopt::Declare->new($spec), $desc;
  is $args->{'--lines'}{'<start>'}, $val1;
  is $args->{'--lines'}{'<stop>'}, $val2;
  return 1;
}