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
2334
4
56
use Cwd 'realpath';
4
2
2
2
4
1
21
use File::Spec;
5
2
2
2
250
2
33
use CheckSpelling::Util;
6
2
2
2
363
2
1434
use CheckSpelling::CheckDictionary;
7
8
2
2
2
2
43141
499
13
6
open WARNINGS, ">>:encoding(UTF-8)", CheckSpelling::Util::get_file_from_env('early_warnings', '/dev/stderr');
9
2
941
$ARGV[0] =~ /^(.*)/;
10
2
2
my $file = $1;
11
2
28
open FILE, "<:encoding(UTF-8)", $file;
12
2
38
$/ = undef;
13
2
47
my $content = <FILE>;
14
2
30
close FILE;
15
2
114
open FILE, ">:encoding(UTF-8)", $file;
16
17
2
209
$file = File::Spec->abs2rel(realpath($file));
18
19
2
5
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
2
my $messy = 0;
25
2
3
$. = 0;
26
27
2
1
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
7
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
10
    ++$.;
33
10
9
    my ($line, $end) = ($1, $2);
34
10
10
    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
12
    my ($line, $warning) = CheckSpelling::CheckDictionary::process_line($name, $line);
40
10
12
    if ($warning ne '') {
41
2
8
        print WARNINGS $warning;
42    } elsif ($line ne '') {
43
6
9
        print FILE "$line\n";
44    }
45}
46
2
3
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;