File Coverage

File:/home/runner/work/check-spelling/check-spelling/check-dictionary.pl
Coverage:87.9%

linestmtbrancondsubtimecode
1#!/usr/bin/env perl
2
3
2
2
2
2208
2
58
use Cwd 'realpath';
4
2
2
2
3
2
18
use File::Spec;
5
2
2
2
248
2
32
use CheckSpelling::Util;
6
2
2
2
371
2
1395
use CheckSpelling::CheckDictionary;
7
8
2
2
2
2
42161
507
14
3
open WARNINGS, ">>:encoding(UTF-8)", CheckSpelling::Util::get_file_from_env('early_warnings', '/dev/stderr');
9
2
916
$ARGV[0] =~ /^(.*)/;
10
2
4
my $file = $1;
11
2
30
open FILE, "<:encoding(UTF-8)", $file;
12
2
39
$/ = undef;
13
2
40
my $content = <FILE>;
14
2
33
close FILE;
15
2
86
open FILE, ">:encoding(UTF-8)", $file;
16
17
2
160
$file = File::Spec->abs2rel(realpath($file));
18
19
2
3
my $name = CheckSpelling::Util::get_file_from_env('file', $file);
20
21
2
5
$ENV{comment_char} = '$^' unless $ENV{comment_char} =~ /\S/;
22
23
2
2
my $first_end = undef;
24
2
1
my $messy = 0;
25
2
4
$. = 0;
26
27
2
0
my $remainder;
28
2
8
if ($content !~ /(?:\r\n|\n|\r|\x0b|\f|\x85|\x{2028}|\x{2029})$/) {
29
0
0
    $remainder = $1 if $content =~ /([^\r\n\x0b\f\x85\x{2028}\x{2029}]+)$/;
30}
31
2
5
while ($content =~ s/([^\r\n\x0b\f\x85\x{2028}\x{2029}]*)(\r\n|\n|\r|\x0b|\f|\x85|\x{2028}|\x{2029})//m) {
32
10
6
    ++$.;
33
10
11
    my ($line, $end) = ($1, $2);
34
10
9
    unless (defined $first_end) {
35
2
2
        $first_end = $end;
36    } elsif ($end ne $first_end) {
37        print WARNINGS "$name:$.:$-[0] ... $+[0], Warning - Entry has inconsistent line endings. (unexpected-line-ending)\n";
38    }
39
10
10
    my ($line, $warning) = CheckSpelling::CheckDictionary::process_line($name, $line);
40
10
13
    if ($warning ne '') {
41
2
8
        print WARNINGS $warning;
42    } elsif ($line ne '') {
43
6
12
        print FILE "$line\n";
44    }
45}
46
2
2
if ($remainder ne '') {
47
0
0
    $remainder = CheckSpelling::CheckDictionary::process_line($name, $remainder);
48
0
0
    print FILE $remainder;
49}
50
2
0
close WARNINGS;