From b2a38518f3be458181d7ad75900d8305cdb9a297 Mon Sep 17 00:00:00 2001 From: AlDanial Date: Fri, 16 Feb 2024 17:15:51 -0800 Subject: [PATCH] XML start block comment on line w/code #811 --- Unix/cloc | 20 ++++++++++++++---- Unix/t/01_opts.t | 7 +++++++ cloc | 21 +++++++++++++++---- tests/inputs/issues/811/inline_comment.xml | 6 ++++++ .../issues/811/inline_comment.xml.yaml | 21 +++++++++++++++++++ 5 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 tests/inputs/issues/811/inline_comment.xml create mode 100644 tests/outputs/issues/811/inline_comment.xml.yaml diff --git a/Unix/cloc b/Unix/cloc index 78ef6c1c..b20ff37a 100755 --- a/Unix/cloc +++ b/Unix/cloc @@ -7160,6 +7160,7 @@ sub remove_matches { # {{{1 $pattern , # in Perl regular expression (case insensitive) ) = @_; print "-> remove_matches(pattern=$pattern)\n" if $opt_v > 2; + print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4; my @save_lines = (); foreach (@{$ra_lines}) { @@ -7171,6 +7172,7 @@ sub remove_matches { # {{{1 push @save_lines, $_; } + print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4; print "<- remove_matches\n" if $opt_v > 2; #print "remove_matches returning\n ", join("\n ", @save_lines), "\n"; return @save_lines; @@ -7181,6 +7183,7 @@ sub remove_matches_2re { # {{{1 $pattern2, # in Perl regex 2 (case insensitive) to not match prev line ) = @_; print "-> remove_matches_2re(pattern=$pattern1,$pattern2)\n" if $opt_v > 2; + print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4; my @save_lines = (); for (my $i = 0; $i < scalar @{$ra_lines}; $i++) { @@ -7197,6 +7200,7 @@ sub remove_matches_2re { # {{{1 push @save_lines, $ra_lines->[$i]; } + print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4; print "<- remove_matches_2re\n" if $opt_v > 2; #print "remove_matches_2re returning\n ", join("\n ", @save_lines), "\n"; return @save_lines; @@ -7308,6 +7312,7 @@ sub remove_between { # {{{1 # '{}' '()' '[]' or '<>' print "-> remove_between(marker=$marker)\n" if $opt_v > 2; + print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4; my %acceptable = ('{}'=>1, '()'=>1, '[]'=>1, '<>'=>1, ); die "remove_between: invalid delimiter '$marker'\n", "the delimiter must be one of these four pairs:\n", @@ -7326,6 +7331,7 @@ sub remove_between { # {{{1 $all_lines =~ s/$1//g; } + print "[", join("]\n[", split(/\n/, $all_lines)), "]\n" if $opt_v > 4; print "<- remove_between\n" if $opt_v > 2; return split("\n", $all_lines); } # 1}}} @@ -7337,6 +7343,7 @@ sub rm_comments_in_strings { # {{{1 print "-> rm_comments_in_strings(string_marker=$string_marker, " . "start_comment=$start_comment, end_comment=$end_comment)\n" if $opt_v > 2; + print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4; my @save_lines = (); my $in_ml_string = 0; @@ -7407,6 +7414,7 @@ sub rm_comments_in_strings { # {{{1 push @save_lines, $new_line; } + print "[", join("]\n[", @save_lines), "]\n" if $opt_v > 4; print "<- rm_comments_in_strings\n" if $opt_v > 2; return @save_lines; } # 1}}} @@ -7539,7 +7547,7 @@ sub replace_between_regex { # {{{1 push @save_lines, $_; } - print "[", join("][", @{$ra_lines}), "]\n" if $opt_v > 4; + print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4; print "<- replace_between_regex\n" if $opt_v > 2; return @save_lines; } # 1}}} @@ -7656,7 +7664,11 @@ sub remove_html_comments { # {{{1 } next if /^\s*$/; $in_comment = 1 if /^(.*?) 4; + print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4; print "<- docstring_rm_comments\n" if $opt_v > 2; return @{$ra_lines}; } # 1}}} @@ -11514,7 +11526,7 @@ sub call_regexp_common { # {{{1 # a bogus use of %RE to avoid: # Name "main::RE" used only once: possible typo at cloc line xx. print scalar keys %RE if $opt_v < -20; - print "[", join("][", @{$ra_lines}), "]\n" if $opt_v > 4; + print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4; print "<- call_regexp_common\n" if $opt_v > 2; return split("\n", $all_lines); } # 1}}} diff --git a/Unix/t/01_opts.t b/Unix/t/01_opts.t index c1063d91..c361c4bc 100755 --- a/Unix/t/01_opts.t +++ b/Unix/t/01_opts.t @@ -781,6 +781,13 @@ my @Tests = ( 'ref' => '../tests/outputs/issues/806/results.yaml', }, + { + 'name' => 'XML start block comment on line w/code #811', + 'cd' => '../tests/inputs/issues/811', + 'args' => 'inline_comment.xml', + 'ref' => '../tests/outputs/issues/811/inline_comment.xml.yaml', + }, + ); # Special cases: diff --git a/cloc b/cloc index e57162c1..1855e52a 100755 --- a/cloc +++ b/cloc @@ -7175,6 +7175,7 @@ sub remove_matches { # {{{1 $pattern , # in Perl regular expression (case insensitive) ) = @_; print "-> remove_matches(pattern=$pattern)\n" if $opt_v > 2; + print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4; my @save_lines = (); foreach (@{$ra_lines}) { @@ -7186,6 +7187,7 @@ sub remove_matches { # {{{1 push @save_lines, $_; } + print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4; print "<- remove_matches\n" if $opt_v > 2; #print "remove_matches returning\n ", join("\n ", @save_lines), "\n"; return @save_lines; @@ -7196,6 +7198,7 @@ sub remove_matches_2re { # {{{1 $pattern2, # in Perl regex 2 (case insensitive) to not match prev line ) = @_; print "-> remove_matches_2re(pattern=$pattern1,$pattern2)\n" if $opt_v > 2; + print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4; my @save_lines = (); for (my $i = 0; $i < scalar @{$ra_lines}; $i++) { @@ -7212,6 +7215,7 @@ sub remove_matches_2re { # {{{1 push @save_lines, $ra_lines->[$i]; } + print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4; print "<- remove_matches_2re\n" if $opt_v > 2; #print "remove_matches_2re returning\n ", join("\n ", @save_lines), "\n"; return @save_lines; @@ -7323,6 +7327,7 @@ sub remove_between { # {{{1 # '{}' '()' '[]' or '<>' print "-> remove_between(marker=$marker)\n" if $opt_v > 2; + print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4; my %acceptable = ('{}'=>1, '()'=>1, '[]'=>1, '<>'=>1, ); die "remove_between: invalid delimiter '$marker'\n", "the delimiter must be one of these four pairs:\n", @@ -7341,6 +7346,7 @@ sub remove_between { # {{{1 $all_lines =~ s/$1//g; } + print "[", join("]\n[", split(/\n/, $all_lines)), "]\n" if $opt_v > 4; print "<- remove_between\n" if $opt_v > 2; return split("\n", $all_lines); } # 1}}} @@ -7352,6 +7358,7 @@ sub rm_comments_in_strings { # {{{1 print "-> rm_comments_in_strings(string_marker=$string_marker, " . "start_comment=$start_comment, end_comment=$end_comment)\n" if $opt_v > 2; + print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4; my @save_lines = (); my $in_ml_string = 0; @@ -7422,6 +7429,7 @@ sub rm_comments_in_strings { # {{{1 push @save_lines, $new_line; } + print "[", join("]\n[", @save_lines), "]\n" if $opt_v > 4; print "<- rm_comments_in_strings\n" if $opt_v > 2; return @save_lines; } # 1}}} @@ -7554,7 +7562,7 @@ sub replace_between_regex { # {{{1 push @save_lines, $_; } - print "[", join("][", @{$ra_lines}), "]\n" if $opt_v > 4; + print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4; print "<- replace_between_regex\n" if $opt_v > 2; return @save_lines; } # 1}}} @@ -7671,7 +7679,11 @@ sub remove_html_comments { # {{{1 } next if /^\s*$/; $in_comment = 1 if /^(.*?) 4; + print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4; print "<- docstring_rm_comments\n" if $opt_v > 2; return @{$ra_lines}; } # 1}}} @@ -8543,6 +8555,7 @@ sub set_constants { # {{{1 'jsf' => 'JavaServer Faces' , 'jsx' => 'JSX' , 'xhtml' => 'XHTML' , + 'j2' => 'Jinja Template' , 'jinja' => 'Jinja Template' , 'jinja2' => 'Jinja Template' , 'yyp' => 'JSON' , @@ -11528,7 +11541,7 @@ sub call_regexp_common { # {{{1 # a bogus use of %RE to avoid: # Name "main::RE" used only once: possible typo at cloc line xx. print scalar keys %RE if $opt_v < -20; - print "[", join("][", @{$ra_lines}), "]\n" if $opt_v > 4; + print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4; print "<- call_regexp_common\n" if $opt_v > 2; return split("\n", $all_lines); } # 1}}} diff --git a/tests/inputs/issues/811/inline_comment.xml b/tests/inputs/issues/811/inline_comment.xml new file mode 100644 index 00000000..6b28a52f --- /dev/null +++ b/tests/inputs/issues/811/inline_comment.xml @@ -0,0 +1,6 @@ + + + + diff --git a/tests/outputs/issues/811/inline_comment.xml.yaml b/tests/outputs/issues/811/inline_comment.xml.yaml new file mode 100644 index 00000000..304035c7 --- /dev/null +++ b/tests/outputs/issues/811/inline_comment.xml.yaml @@ -0,0 +1,21 @@ +--- +# github.com/AlDanial/cloc +header : + cloc_url : github.com/AlDanial/cloc + cloc_version : 1.99 + elapsed_seconds : 0.00256609916687012 + n_files : 1 + n_lines : 6 + files_per_second : 389.696553005668 + lines_per_second : 2338.17931803401 + report_file : ../../../outputs/issues/811/inline_comment.xml.yaml +'XML' : + nFiles: 1 + blank: 0 + comment: 2 + code: 4 +SUM: + blank: 0 + comment: 2 + code: 4 + nFiles: 1