File Coverage

blib/lib/Jenkins/i18n/Assertions.pm
Criterion Covered Total %
statement 14 20 70.0
branch 1 6 16.6
condition n/a
subroutine 5 8 62.5
pod 4 4 100.0
total 24 38 63.1


line stmt bran cond sub pod time code
1             package Jenkins::i18n::Assertions;
2 8     8   59 use warnings;
  8         29  
  8         260  
3 8     8   44 use strict;
  8         17  
  8         179  
4 8     8   38 use Set::Tiny 0.04;
  8         278  
  8         376  
5 8     8   51 use Exporter 'import';
  8         14  
  8         2305  
6              
7             our @EXPORT_OK = qw(has_empty is_jelly_file has_hudson can_ignore);
8              
9             =pod
10              
11             =head1 NAME
12              
13             Jenkins::i18n::Assertions: execute assertions on files, Properties keys and
14             keys values.
15              
16             =head1 SYNOPSIS
17              
18             use Jenkins::i18n::Assertions qw(is_jelly_file);
19              
20             if (is_jelly_file($filename)) {
21             # do something
22             }
23              
24             =head1 DESCRIPTION
25              
26             This module provides several assertions required to process the Jenkins
27             internationalization related files.
28              
29             =head1 FUNCTIONS
30              
31             =head2 has_empty
32              
33             Some Properties have keys with empty values (for any reason).
34              
35             When the value of the Property key is empty, but that is expected, that's fine.
36             The convention in those cases is that the Property key has a C string as
37             part of it's name.
38              
39             This function just tests that. The test is B.
40              
41             Expects as parameter a key Property.
42              
43             Returns 1, if there is a match, 0 otherwise.
44              
45             =cut
46              
47             my $empty_regex = qr/empty/i;
48              
49             sub has_empty {
50 0     0 1 0 my $property_value = shift;
51 0 0       0 return ( $property_value =~ $empty_regex ) ? 1 : 0;
52             }
53              
54             =head2 is_jelly_file
55              
56             Tests if a file name contains C<.jelly> as an file extension. The match B
57             case sensitive.
58              
59             Expects as parameter a file name (maybe be a full path).
60              
61             Returns 1, if there is a match, 0 otherwise.
62              
63             =cut
64              
65             my $jelly_regex = qr/.jelly$/;
66              
67             sub is_jelly_file {
68 0     0 1 0 my $filename = shift;
69 0 0       0 return ( $filename =~ $jelly_regex ) ? 1 : 0;
70             }
71              
72             =head2 has_hudson
73              
74             Tests if a Property key value has the C string on it. The match B
75             case sensitive.
76              
77             Expects as parameter a Property key value.
78              
79             Returns 1, if there is a match, 0 otherwise.
80              
81             =cut
82              
83             my $hudson_regex = qr/Hudson/;
84              
85             sub has_hudson {
86 6     6 1 75 my $property_value = shift;
87 6 50       35 return ( $property_value =~ $hudson_regex ) ? 1 : 0;
88             }
89              
90             =head2 can_ignore
91              
92             Some Properties keys have values that don't have to be translated, like URL's
93             and proper nouns. This functions tests for those known cases.
94              
95             Expects as parameter a Properties key value.
96              
97             Returns 1, if there is a match, 0 otherwise.
98              
99             =cut
100              
101             my $ignore_same = Set::Tiny->new(
102             (
103             'https://www.jenkins.io/redirect/log-levels',
104             'Maven',
105             'Jenkins',
106             'JDK',
107             'Javadoc',
108             'https://www.jenkins.io/redirect/fingerprint',
109             'https://www.jenkins.io/redirect/search-box'
110             )
111             );
112              
113             sub can_ignore {
114 0     0 1   my $property_value = shift;
115 0           return $ignore_same->has($property_value);
116             }
117              
118             1;
119             __END__