File Coverage

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

linestmtbrancondsubtimecode
1#!/usr/bin/env perl
2
3
2
2
2
1907
2
47
use Cwd 'realpath';
4
2
2
2
4
1
17
use File::Spec;
5
2
2
2
237
2
32
use CheckSpelling::Util;
6
2
2
2
351
2
1130
use CheckSpelling::CheckDictionary;
7
8
2
2
2
2
39774
480
13
5
open WARNINGS, ">>:encoding(UTF-8)", CheckSpelling::Util::get_file_from_env('early_warnings', '/dev/stderr');
9
2
774
$ARGV[0] =~ /^(.*)/;
10
2
3
my $file = $1;
11
2
22
open FILE, "<:encoding(UTF-8)", $file;
12
2
35
$/ = undef;
13
2
28
my $content = <FILE>;
14
2
23
close FILE;
15
2
67
open FILE, ">:encoding(UTF-8)", $file;
16
17
2
129
$file = File::Spec->abs2rel(realpath($file));
18
19
2
4
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
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
1
4
    $remainder = $1 if $content =~ /([^\r\n\x0b\f\x85\x{2028}\x{2029}]+)$/;
30}
31
2
6
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
10
    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
7
        print WARNINGS $warning;
42    } elsif ($line ne '') {
43
6
10
        print FILE "$line\n";
44    }
45}
46
2
2
if ($remainder ne '') {
47
1
1
    $remainder = CheckSpelling::CheckDictionary::process_line($name, $remainder);
48
1
1
    print FILE $remainder;
49}
50
2
0
close WARNINGS;