Skip to content

Commit d50110c

Browse files
committed
Starting on t/context.yaml
1 parent f7e015c commit d50110c

File tree

4 files changed

+110
-170
lines changed

4 files changed

+110
-170
lines changed

MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ t/config-finder.t
8484
t/config-loader.t
8585
t/context-with-newlines.t
8686
t/context.t
87+
t/context.yaml
8788
t/default-filter.t
8889
t/double-hyphen.yaml
8990
t/empty-lines.t

t/context.t

Lines changed: 1 addition & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -3,184 +3,16 @@
33
use warnings;
44
use strict;
55

6-
use Test::More tests => 19;
6+
use Test::More tests => 9;
77

88
use lib 't';
99
use Util;
1010

1111
prep_environment();
1212

1313
# 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."
6514

66-
"For the love of God, Montresor!"
6715

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-
}
18416

18517
CONTEXT_OVERLAPPING_COLOR: {
18618
my $match_start = "\e[30;43m";

t/context.yaml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
name: Checks also beginning of file.
3+
args: a -w -B1 t/text/ozymandias.txt
4+
ordered: true
5+
stdout: |
6+
I met a traveller from an antique land
7+
--
8+
Stand in the desert... Near them, on the sand,
9+
Half sunk, a shattered visage lies, whose frown,
10+
11+
---
12+
name: Before with line number
13+
args: sand --sort-files -B2 t/text/ozymandias.txt t/text/bill-of-rights.txt
14+
ordered: true
15+
stdout: |
16+
t/text/ozymandias.txt-1-I met a traveller from an antique land
17+
t/text/ozymandias.txt-2-Who said: Two vast and trunkless legs of stone
18+
t/text/ozymandias.txt:3:Stand in the desert... Near them, on the sand,
19+
--
20+
t/text/ozymandias.txt-12-Nothing beside remains. Round the decay
21+
t/text/ozymandias.txt-13-Of that colossal wreck, boundless and bare
22+
t/text/ozymandias.txt:14:The lone and level sands stretch far away.
23+
24+
---
25+
name: Checks also end of file.
26+
args: sands -A2 t/text/ozymandias.txt
27+
ordered: true
28+
stdout: |
29+
The lone and level sands stretch far away.
30+
31+
---
32+
name: Context defaults to 2.
33+
args: Montresor -w -C t/text/amontillado.txt
34+
stdout: |
35+
"Yes,"I said, "let us be gone."
36+
37+
"For the love of God, Montresor!"
38+
39+
"Yes," I said, "for the love of God!"
40+
41+
---
42+
name: Context 1
43+
args: foot -w -C 1 t/text/amontillado.txt
44+
stdout: |
45+
requesting him to be cautious as he followed. We came at length to
46+
the foot of the descent, and stood together on the damp ground of
47+
the catacombs of the Montresors.
48+
--
49+
50+
"A huge human foot d'or, in a field azure; the foot crushes a serpent
51+
rampant whose fangs are imbedded in the heel."
52+
53+
---
54+
name: Context 0 means no context
55+
args: Montresor -w -C 0 t/text/amontillado.txt
56+
stdout: |
57+
"For the love of God, Montresor!"
58+
59+
---
60+
name: -1 must not stop the ending context from displaying.
61+
args: right -1 -C1 t/text/bill-of-rights.txt
62+
stdout: |
63+
or prohibiting the free exercise thereof; or abridging the freedom of
64+
speech, or of the press; or the right of the people peaceably to assemble,
65+
and to petition the Government for a redress of grievances.
66+
67+
---
68+
name: -C with overlapping contexts (adjacent lines)
69+
args: -C 05|06 t/text/numbered-text.txt
70+
stdout: |
71+
This is line 03
72+
This is line 04
73+
This is line 05
74+
This is line 06
75+
This is line 07
76+
This is line 08
77+
78+
---
79+
name: -C with contexts that touch.
80+
args: -C 03|08 t/text/numbered-text.txt
81+
stdout: |
82+
This is line 01
83+
This is line 02
84+
This is line 03
85+
This is line 04
86+
This is line 05
87+
This is line 06
88+
This is line 07
89+
This is line 08
90+
This is line 09
91+
This is line 10
92+
93+
---
94+
name: -C with contexts that just don't touch.
95+
args: -C 03|09 t/text/numbered-text.txt
96+
stdout: |
97+
This is line 01
98+
This is line 02
99+
This is line 03
100+
This is line 04
101+
This is line 05
102+
--
103+
This is line 07
104+
This is line 08
105+
This is line 09
106+
This is line 10
107+
This is line 11

t/yaml.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use warnings;
44
use strict;
55

6-
use Test::More tests => 23;
6+
use Test::More tests => 24;
77

88
use lib 't';
99
use Util;

0 commit comments

Comments
 (0)