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
1985
2
48
use Cwd 'realpath';
4
2
2
2
3
1
17
use File::Spec;
5
2
2
2
238
1
35
use CheckSpelling::Util;
6
2
2
2
350
2
1251
use CheckSpelling::CheckDictionary;
7
8
2
2
2
2
39932
475
12
6
open WARNINGS, ">>:encoding(UTF-8)", CheckSpelling::Util::get_file_from_env('early_warnings', '/dev/stderr');
9
2
813
$ARGV[0] =~ /^(.*)/;
10
2
2
my $file = $1;
11
2
28
open FILE, "<:encoding(UTF-8)", $file;
12
2
35
$/ = undef;
13
2
33
my $content = <FILE>;
14
2
25
close FILE;
15
2
80
open FILE, ">:encoding(UTF-8)", $file;
16
17
2
153
$file = File::Spec->abs2rel(realpath($file));
18
19
2
3
my $name = CheckSpelling::Util::get_file_from_env('file', $file);
20
21
2
4
$ENV{comment_char} = '$^' unless $ENV{comment_char} =~ /\S/;
22
23
2
1
my $first_end = undef;
24
2
2
my $messy = 0;
25
2
2
$. = 0;
26
27
2
1
my $remainder;
28
2
6
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
8
    ++$.;
33
10
9
    my ($line, $end) = ($1, $2);
34
10
10
    unless (defined $first_end) {
35
2
1
        $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
11
    my ($line, $warning) = CheckSpelling::CheckDictionary::process_line($name, $line);
40
10
11
    if ($warning ne '') {
41
2
7
        print WARNINGS $warning;
42    } elsif ($line ne '') {
43
6
10
        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;