|
3 | 3 | use warnings; |
4 | 4 | use strict; |
5 | 5 |
|
6 | | -use Test::More tests => 19; |
| 6 | +use Test::More tests => 9; |
7 | 7 |
|
8 | 8 | use lib 't'; |
9 | 9 | use Util; |
10 | 10 |
|
11 | 11 | prep_environment(); |
12 | 12 |
|
13 | 13 | # Checks also beginning of file. |
14 | | -BEFORE: { |
15 | | - my @expected = line_split( <<'HERE' ); |
16 | | -I met a traveller from an antique land |
17 | | --- |
18 | | -Stand in the desert... Near them, on the sand, |
19 | | -Half sunk, a shattered visage lies, whose frown, |
20 | | -HERE |
21 | | - |
22 | | - my $regex = 'a'; |
23 | | - my @files = qw( t/text/ozymandias.txt ); |
24 | | - my @args = ( '-w', '-B1', $regex ); |
25 | | - |
26 | | - ack_lists_match( [ @args, @files ], \@expected, "Looking for $regex - before" ); |
27 | | -} |
28 | | - |
29 | | -BEFORE_WITH_LINE_NO: { |
30 | | - my $target_file = reslash( 't/text/ozymandias.txt' ); |
31 | | - my @expected = line_split( <<"HERE" ); |
32 | | -$target_file-1-I met a traveller from an antique land |
33 | | -$target_file-2-Who said: Two vast and trunkless legs of stone |
34 | | -$target_file:3:Stand in the desert... Near them, on the sand, |
35 | | --- |
36 | | -$target_file-12-Nothing beside remains. Round the decay |
37 | | -$target_file-13-Of that colossal wreck, boundless and bare |
38 | | -$target_file:14:The lone and level sands stretch far away. |
39 | | -HERE |
40 | | - |
41 | | - my $regex = 'sand'; |
42 | | - my @files = qw( t/text/ozymandias.txt t/text/bill-of-rights.txt ); # So we don't pick up constitution.txt |
43 | | - my @args = ( '--sort-files', '-B2', $regex ); |
44 | | - |
45 | | - ack_lists_match( [ @args, @files ], \@expected, "Looking for $regex - before with line numbers" ); |
46 | | -} |
47 | | - |
48 | | -# Checks also end of file. |
49 | | -AFTER: { |
50 | | - my @expected = line_split( <<'HERE' ); |
51 | | -The lone and level sands stretch far away. |
52 | | -HERE |
53 | | - |
54 | | - my $regex = 'sands'; |
55 | | - my @files = qw( t/text/ozymandias.txt ); |
56 | | - my @args = ( '-A2', $regex ); |
57 | | - |
58 | | - ack_lists_match( [ @args, @files ], \@expected, "Looking for $regex - after" ); |
59 | | -} |
60 | | - |
61 | | -# Context defaults to 2. |
62 | | -CONTEXT_DEFAULT: { |
63 | | - my @expected = line_split( <<'HERE' ); |
64 | | -"Yes,"I said, "let us be gone." |
65 | 14 |
|
66 | | -"For the love of God, Montresor!" |
67 | 15 |
|
68 | | -"Yes," I said, "for the love of God!" |
69 | | -HERE |
70 | | - |
71 | | - my $regex = 'Montresor'; |
72 | | - my @files = qw( t/text/amontillado.txt ); |
73 | | - my @args = ( '-w', '-C', $regex ); |
74 | | - |
75 | | - ack_lists_match( [ @args, @files ], \@expected, "Looking for $regex - context defaults to 2" ); |
76 | | -} |
77 | | - |
78 | | -# Try context 1. |
79 | | -CONTEXT_ONE: { |
80 | | - my @expected = line_split( <<'HERE' ); |
81 | | -
|
82 | | -"For the love of God, Montresor!" |
83 | | -HERE |
84 | | - |
85 | | - push( @expected, '' ); # Since split eats the last line. |
86 | | - |
87 | | - my $regex = 'Montresor'; |
88 | | - my @files = qw( t/text/amontillado.txt ); |
89 | | - my @args = ( '-w', '-C', 1, $regex ); |
90 | | - |
91 | | - ack_lists_match( [ @args, @files ], \@expected, "Looking for $regex - context=1" ); |
92 | | -} |
93 | | - |
94 | | -# --context=0 means no context. |
95 | | -CONTEXT_ONE: { |
96 | | - my @expected = line_split( <<'HERE' ); |
97 | | -"For the love of God, Montresor!" |
98 | | -HERE |
99 | | - |
100 | | - my $regex = 'Montresor'; |
101 | | - my @files = qw( t/text/amontillado.txt ); |
102 | | - my @args = ( '-w', '-C', 0, $regex ); |
103 | | - |
104 | | - ack_lists_match( [ @args, @files ], \@expected, "Looking for $regex - context=0" ); |
105 | | -} |
106 | | - |
107 | | -# -1 must not stop the ending context from displaying. |
108 | | -CONTEXT_DEFAULT: { |
109 | | - my @expected = line_split( <<'HERE' ); |
110 | | -or prohibiting the free exercise thereof; or abridging the freedom of |
111 | | -speech, or of the press; or the right of the people peaceably to assemble, |
112 | | -and to petition the Government for a redress of grievances. |
113 | | -HERE |
114 | | - |
115 | | - my $regex = 'right'; |
116 | | - my @files = qw( t/text/bill-of-rights.txt ); |
117 | | - my @args = ( '-1', '-C1', $regex ); |
118 | | - |
119 | | - ack_lists_match( [ @args, @files ], \@expected, "Looking for $regex with -1" ); |
120 | | -} |
121 | | - |
122 | | -# -C with overlapping contexts (adjacent lines) |
123 | | -CONTEXT_OVERLAPPING: { |
124 | | - my @expected = line_split( <<'HERE' ); |
125 | | -This is line 03 |
126 | | -This is line 04 |
127 | | -This is line 05 |
128 | | -This is line 06 |
129 | | -This is line 07 |
130 | | -This is line 08 |
131 | | -HERE |
132 | | - |
133 | | - my $regex = '05|06'; |
134 | | - my @files = qw( t/text/numbered-text.txt ); |
135 | | - my @args = ( '-C', $regex ); |
136 | | - |
137 | | - ack_lists_match( [ @args, @files ], \@expected, "Looking for $regex with overlapping contexts" ); |
138 | | -} |
139 | | - |
140 | | -# -C with contexts that touch. |
141 | | -CONTEXT_ADJACENT: { |
142 | | - my @expected = line_split( <<'HERE' ); |
143 | | -This is line 01 |
144 | | -This is line 02 |
145 | | -This is line 03 |
146 | | -This is line 04 |
147 | | -This is line 05 |
148 | | -This is line 06 |
149 | | -This is line 07 |
150 | | -This is line 08 |
151 | | -This is line 09 |
152 | | -This is line 10 |
153 | | -HERE |
154 | | - |
155 | | - my $regex = '03|08'; |
156 | | - my @files = qw( t/text/numbered-text.txt ); |
157 | | - my @args = ( '-C', $regex ); |
158 | | - |
159 | | - ack_lists_match( [ @args, @files ], \@expected, "Looking for $regex with contexts that touch" ); |
160 | | -} |
161 | | - |
162 | | -# -C with contexts that just don't touch. |
163 | | -CONTEXT_NONADJACENT: { |
164 | | - my @expected = line_split( <<'HERE' ); |
165 | | -This is line 01 |
166 | | -This is line 02 |
167 | | -This is line 03 |
168 | | -This is line 04 |
169 | | -This is line 05 |
170 | | --- |
171 | | -This is line 07 |
172 | | -This is line 08 |
173 | | -This is line 09 |
174 | | -This is line 10 |
175 | | -This is line 11 |
176 | | -HERE |
177 | | - |
178 | | - my $regex = '03|09'; |
179 | | - my @files = qw( t/text/numbered-text.txt ); |
180 | | - my @args = ( '-C', $regex ); |
181 | | - |
182 | | - ack_lists_match( [ @args, @files ], \@expected, "Looking for $regex with contexts that just don't touch" ); |
183 | | -} |
184 | 16 |
|
185 | 17 | CONTEXT_OVERLAPPING_COLOR: { |
186 | 18 | my $match_start = "\e[30;43m"; |
|
0 commit comments