Skip to content

Commit 9dc957c

Browse files
author
Artem Krivopolenov
committed
Old PERL regexp updated
Tests updated
1 parent 6e33e61 commit 9dc957c

File tree

6 files changed

+47
-22
lines changed

6 files changed

+47
-22
lines changed

lib/Text/WordDiff.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ $VERSION = '0.08';
1111
# _Mastering Regular Expressions_, p. 132.
1212
my $BEGIN_WORD = $] >= 5.006
1313
? qr/(?:(?<!\p{IsWord})(?=\p{IsWord})|(?<!\p{IsPunct})(?=\p{IsPunct})|(?<!\p{IsCntrl})(?=\p{IsCntrl}))/msx
14-
: qr/(?<!\w)(?=\w)/msx;
14+
: qr/(?<!\w)(?=\w)|(?<![\]\[!"#$%&'()*+,\.\/:;<=>?@\^_`{|}~-])(?=[\]\[!"#$%&'()*+,\.\/:;<=>?@\^_`{|}~-])|(?<![\n\r\t])(?=[\n\r\v])/msx;;
1515

1616
my %styles = (
1717
ANSIColor => undef,

t/ansicolor.t

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,19 @@ my $time1 = localtime( (stat $filename1)[9] );
4545
my $time2 = localtime( (stat $filename2)[9] );
4646
my $header = "--- $filename1\t$time1\n+++ $filename2\t$time2\n";
4747

48-
my $file_diff = 'This is a ' . BOLD . RED . STRIKETHROUGH . "tst;\n"
49-
. 'it ' . RESET . BOLD . GREEN . UNDERLINE . "test.\n"
50-
. 'It ' . RESET . "is only a\n"
48+
my $file_diff = 'This is a ' . BOLD . RED . STRIKETHROUGH . "tst;"
49+
. RESET . BOLD . GREEN . UNDERLINE . "test." . RESET . "\n"
50+
. BOLD . RED . STRIKETHROUGH . "it " . RESET
51+
. BOLD . GREEN . UNDERLINE . "It " . RESET . "is only a\n"
5152
. 'test. Had ' . BOLD . RED . STRIKETHROUGH . 'it ' . RESET
5253
. BOLD . GREEN . UNDERLINE . 'this ' . RESET . "been an\n"
5354
. "actual diff, the results would\n"
54-
. 'have been output to ' . BOLD . RED . STRIKETHROUGH
55-
. "HTML.\n" . RESET . BOLD . GREEN . UNDERLINE
56-
. "the terminal.\n" . RESET;
55+
. 'have been output to ' . BOLD . RED . STRIKETHROUGH . "HTML"
56+
. RESET . BOLD . GREEN . UNDERLINE . "the terminal" . RESET . ".\n\n"
57+
. 'Some string with funny ' . BOLD . RED . STRIKETHROUGH . '$'
58+
. RESET . BOLD . GREEN . UNDERLINE . '@' . RESET . "\n"
59+
. 'chars in the end' . BOLD . RED . STRIKETHROUGH . '*'
60+
. RESET . BOLD . GREEN . UNDERLINE . '?' . RESET . "\n";
5761

5862
is word_diff($filename1, $filename2), $header . $file_diff,
5963
'Diff by file name should include a header';

t/data/left.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ it is only a
33
test. Had it been an
44
actual diff, the results would
55
have been output to HTML.
6+
7+
Some string with funny $
8+
chars in the end*

t/data/right.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ It is only a
33
test. Had this been an
44
actual diff, the results would
55
have been output to the terminal.
6+
7+
Some string with funny @
8+
chars in the end?

t/html.t

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,21 @@ my $time2 = localtime( (stat $filename2)[9] );
4545
my $header = qq{<span class="fileheader">--- $filename1\t$time1\n}
4646
. qq{+++ $filename2\t$time2\n</span>};
4747

48-
my $file_diff = qq{<div class="file">$header<span class="hunk">This is a }
49-
. qq{</span><span class="hunk"><del>tst;\nit </del><ins>test.\n}
50-
. qq{It </ins></span><span class="hunk">is only a\n}
51-
. qq{test. Had </span><span class="hunk"><del>it </del>}
52-
. qq{<ins>this </ins></span><span class="hunk">been an\n}
48+
my $file_diff = qq{<div class="file">$header<span class="hunk">This is a </span>}
49+
. qq{<span class="hunk"><del>tst;</del><ins>test.</ins></span>}
50+
. qq{<span class="hunk">\n</span>}
51+
. qq{<span class="hunk"><del>it </del><ins>It </ins></span>}
52+
. qq{<span class="hunk">is only a\ntest. Had </span>}
53+
. qq{<span class="hunk"><del>it </del><ins>this </ins></span>}
54+
. qq{<span class="hunk">been an\n}
5355
. qq{actual diff, the results would\n}
54-
. qq{have been output to </span><span class="hunk"><del>HTML.\n}
55-
. qq{</del><ins>the terminal.\n</ins></span></div>}
56-
;
56+
. qq{have been output to </span><span class="hunk"><del>HTML</del>}
57+
. qq{<ins>the terminal</ins></span>}
58+
. qq{<span class="hunk">.\n\nSome string with funny </span>}
59+
. qq{<span class="hunk"><del>\$</del><ins>\@</ins></span>}
60+
. qq{<span class="hunk">\nchars in the end</span>}
61+
. qq{<span class="hunk"><del>*</del><ins>?</ins></span>}
62+
. qq{<span class="hunk">\n</span></div>};
5763

5864
is word_diff($filename1, $filename2, \%opts), $file_diff,
5965
'Diff by file name should include a header';

t/htmltwolines.t

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,27 @@ my $header1 = qq{<span class="fileheader">--- $filename1 $time1</span>};
5050
my $header2 = qq{<span class="fileheader">+++ $filename2 $time2</span>};
5151

5252
my $file_diff = qq{<div class="file">$header1}
53-
. qq{<span class="hunk">This is a </span><span class="hunk"><del>tst;\n}
54-
. qq{it </del></span><span class="hunk">is only a\n}
53+
. qq{<span class="hunk">This is a </span><span class="hunk"><del>tst;</del></span>}
54+
. qq{<span class="hunk">\n</span>}
55+
. qq{<span class="hunk"><del>it </del></span><span class="hunk">is only a\n}
5556
. qq{test. Had </span><span class="hunk"><del>it </del></span><span class="hunk">been an\n}
5657
. qq{actual diff, the results would\n}
57-
. qq{have been output to </span><span class="hunk"><del>HTML.\n</del></span></div>\n}
58+
. qq{have been output to </span><span class="hunk"><del>HTML</del></span>}
59+
. qq{<span class="hunk">.\n\nSome string with funny </span>}
60+
. qq{<span class="hunk"><del>\$</del></span>}
61+
. qq{<span class="hunk">\nchars in the end</span>}
62+
. qq{<span class="hunk"><del>*</del></span><span class="hunk">\n</span></div>\n}
5863
. qq{<div class="file">$header2}
59-
. qq{<span class="hunk">This is a </span><span class="hunk"><ins>test.\n}
60-
. qq{It </ins></span><span class="hunk">is only a\n}
64+
. qq{<span class="hunk">This is a </span><span class="hunk"><ins>test.</ins></span>}
65+
. qq{<span class="hunk">\n</span>}
66+
. qq{<span class="hunk"><ins>It </ins></span><span class="hunk">is only a\n}
6167
. qq{test. Had </span><span class="hunk"><ins>this </ins></span><span class="hunk">been an\n}
6268
. qq{actual diff, the results would\n}
63-
. qq{have been output to </span><span class="hunk"><ins>the terminal.\n</ins></span></div>\n}
64-
;
69+
. qq{have been output to </span><span class="hunk"><ins>the terminal</ins></span>}
70+
. qq{<span class="hunk">.\n\nSome string with funny </span>}
71+
. qq{<span class="hunk"><ins>\@</ins></span>}
72+
. qq{<span class="hunk">\nchars in the end</span>}
73+
. qq{<span class="hunk"><ins>?</ins></span><span class="hunk">\n</span></div>\n};
6574

6675
is word_diff($filename1, $filename2, \%opts), $file_diff,
6776
'Diff by file name should include a header';

0 commit comments

Comments
 (0)