Skip to content

Commit

Permalink
Fix highlighting on --not
Browse files Browse the repository at this point in the history
  • Loading branch information
petdance committed Dec 21, 2024
1 parent 0b8e85b commit 89a3386
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 18 deletions.
1 change: 1 addition & 0 deletions lib/App/Ack.pm
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ sub build_all_regexes {
# NOT: alpha NOT beta
elsif ( @parts = @{$opt->{not}} ) {
($re_match, $re_scan) = build_regex( $opt_regex, $opt );
$re_hilite = $re_match;

my @not_parts;
for my $part ( @parts ) {
Expand Down
165 changes: 147 additions & 18 deletions t/highlighting.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use warnings;
use strict;

use Test::More tests => 6;
use Test::More tests => 24;

use lib 't';
use Util;
Expand All @@ -23,13 +23,7 @@ BASIC: {
{309}:"For the love of God, (Montresor)!"
END

$expected_original = windows_slashify( $expected_original ) if is_windows;

my @expected = colorize( $expected_original );

my @results = run_ack( @args, @HIGHLIGHT );

is_deeply( \@results, \@expected, 'Basic highlights match' );
_check_it( $expected_original, @args, @HIGHLIGHT );
}


Expand All @@ -47,13 +41,7 @@ METACHARACTERS: {
{52}:"Though thy crest be shorn and shaven, thou," I said, "art sure no (craven),
END

$expected_original = windows_slashify( $expected_original ) if is_windows;

my @expected = colorize( $expected_original );

my @results = run_ack( @args, @HIGHLIGHT );

is_deeply( \@results, \@expected, 'Metacharacters match' );
_check_it( $expected_original, @args, @HIGHLIGHT );
}


Expand Down Expand Up @@ -81,11 +69,152 @@ CONTEXT: {
{24}-by the people, for the people, shall not perish from the earth.
END

$expected_original = windows_slashify( $expected_original ) if is_windows;
_check_it( $expected_original, @args, @HIGHLIGHT );
}


NOT: {
ORIGINAL: {
my @args = ( qw( judge -i ), 't/text/constitution.txt' );

my $expected_original = <<'END';
Each House shall be the (Judge) of the Elections, Returns and Qualifications
(Judge)s of the supreme Court, and all other Officers of the United States,
shall (judge) necessary and expedient; he may, on extraordinary Occasions,
time ordain and establish. The (Judge)s, both of the supreme and inferior
the Land; and the (Judge)s in every State shall be bound thereby, any Thing
END

_check_it( $expected_original, @args );
}

NOT: {
my @args = ( qw( judge --not judges -i ), 't/text/constitution.txt' );

my $expected_original = <<'END';
Each House shall be the (Judge) of the Elections, Returns and Qualifications
shall (judge) necessary and expedient; he may, on extraordinary Occasions,
END

_check_it( $expected_original, @args );
}

NOT_AGAIN: {
my @args = ( qw( judge --not all -i ), 't/text/constitution.txt' );

my $expected_original = <<'END';
time ordain and establish. The (Judge)s, both of the supreme and inferior
END

_check_it( $expected_original, @args );
}
}


AND: {
ORIGINAL: {
my @args = ( qw( judge -i ), 't/text/constitution.txt' );

my $expected_original = <<'END';
Each House shall be the (Judge) of the Elections, Returns and Qualifications
(Judge)s of the supreme Court, and all other Officers of the United States,
shall (judge) necessary and expedient; he may, on extraordinary Occasions,
time ordain and establish. The (Judge)s, both of the supreme and inferior
the Land; and the (Judge)s in every State shall be bound thereby, any Thing
END

_check_it( $expected_original, @args );
}

AND: {
my @args = ( qw( judge --and all -i ), 't/text/constitution.txt' );

my $expected_original = <<'END';
Each House sh(all) be the (Judge) of the Elections, Returns and Qualifications
(Judge)s of the supreme Court, and (all) other Officers of the United States,
sh(all) (judge) necessary and expedient; he may, on extraordinary Occasions,
the Land; and the (Judge)s in every State sh(all) be bound thereby, any Thing
END

_check_it( $expected_original, @args );
}

AND_AND: {
my @args = ( qw( judge --and all --and \bthe\b -i ), 't/text/constitution.txt' );

my $expected_original = <<'END';
Each House sh(all) be (the) (Judge) of (the) Elections, Returns and Qualifications
(Judge)s of (the) supreme Court, and (all) other Officers of (the) United States,
(the) Land; and (the) (Judge)s in every State sh(all) be bound thereby, any Thing
END

_check_it( $expected_original, @args );
}

}


OR: {
ORIGINAL: {
my @args = ( qw( judges -i ), 't/text/constitution.txt' );

my $expected_original = <<'END';
(Judges) of the supreme Court, and all other Officers of the United States,
time ordain and establish. The (Judges), both of the supreme and inferior
the Land; and the (Judges) in every State shall be bound thereby, any Thing
END

_check_it( $expected_original, @args );
}

OR: {
my @args = ( qw( judges --or judge -i ), 't/text/constitution.txt' );

my $expected_original = <<'END';
Each House shall be the (Judge) of the Elections, Returns and Qualifications
(Judges) of the supreme Court, and all other Officers of the United States,
shall (judge) necessary and expedient; he may, on extraordinary Occasions,
time ordain and establish. The (Judges), both of the supreme and inferior
the Land; and the (Judges) in every State shall be bound thereby, any Thing
END

_check_it( $expected_original, @args );
}

OR_OR: {
my @args = ( qw( judges --or judge --or amendment -i ), 't/text/constitution.txt' );

my $expected_original = <<'END';
Each House shall be the (Judge) of the Elections, Returns and Qualifications
Representatives; but the Senate may propose or concur with (Amendment)s
(Judges) of the supreme Court, and all other Officers of the United States,
shall (judge) necessary and expedient; he may, on extraordinary Occasions,
time ordain and establish. The (Judges), both of the supreme and inferior
shall propose (Amendment)s to this Constitution, or, on the Application
Convention for proposing (Amendment)s, which, in either Case, shall be
Ratification may be proposed by the Congress; Provided that no (Amendment)
the Land; and the (Judges) in every State shall be bound thereby, any Thing
END

_check_it( $expected_original, @args );
}
}


exit 0;


sub _check_it {
local $Test::Builder::Level = $Test::Builder::Level + 1;

my $expected = shift;
my @args = @_;

$expected = windows_slashify( $expected ) if is_windows;

my @expected = colorize( $expected_original );
my @expected = colorize( $expected );

my @results = run_ack( @args, @HIGHLIGHT );

is_deeply( \@results, \@expected, 'Context is all good' );
return is_deeply( \@results, \@expected, 'Context is all good' );
}

0 comments on commit 89a3386

Please sign in to comment.