File: test_list.t

package info (click to toggle)
libregexp-common-perl 2024080801-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,328 kB
  • sloc: perl: 17,842; makefile: 2
file content (93 lines) | stat: -rwxr-xr-x 1,439 bytes parent folder | download | duplicates (7)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# VOODOO LINE-NOISE
my($C,$M,$P,$N,$S);END{print"1..$C\n$M";print"\nfailed: $N\n"if$N}
sub ok{$C++; $M.= ($_[0]||!@_)?"ok $C\n":($N++,"not ok $C (".
((caller 1)[1]||(caller 0)[1]).":".((caller 1)[2]||(caller 0)[2]).")\n")}
sub try{$P=qr/^$_[0]$/}sub fail{ok($S=$_[0]!~$P)}sub pass{ok($S=$_[0]=~$P)}

# LOAD

use Regexp::Common;
ok;

# TEST COMMA-SEPARATED

try $RE{list};

fail "a";
pass "a,b";
pass "a,  b";
pass "a,b,c";
pass "a, b, c";
fail "a b";
fail "a   b";
fail "a b c";
fail "a  b  c";


# TEST TAB-SEPARATED

try $RE{list}{"-sep$;\t"};

fail "a";
pass "a\tb";
pass "a\tb";
pass "a\tb\tc";
pass "a\tb\tc";
fail "a b";
fail "a   b";
pass "a b\tc";
fail "a  b  c";


# TEST WORDS

try $RE{list}{and};

fail "a";
pass "a and b";
pass "a, b, and c";
pass "a, b and c";
fail "a,b,c";
fail "a, b, c";

try $RE{list}{conj};

fail "a";
pass "a and b";
pass "a, b, and c";
pass "a, b and c";
pass "a, b, or c";
pass "a, b or c";
fail "a,b,c";
fail "a, b, c";

try $RE{list}{conj}{-word => 'ou'};

fail "a";
pass "a ou b";
pass "a, b, ou c";
pass "a, b ou c";
fail "a,b,c";
fail "a, b, c";


# TRY NESTED PATTERNS


try $RE{list}{"-pat$;$RE{quoted}"};

fail q{a};
pass q{'a', 'b'};
fail q{'a', 'b' and 'c'};
pass q{'a', "b", `c`};
fail q{a, b, c};


try $RE{list}{"-pat$;$RE{quoted}"}{-lastsep => '\s*(and|or)\s*'};

fail q{a};
pass q{'a' and 'b'};
pass q{'a', 'b' and 'c'};
fail q{'a', "b", `c`};
pass q{'a', "b" or `c`};
fail q{a, b, c};