File tree 2 files changed +35
-8
lines changed
2 files changed +35
-8
lines changed Original file line number Diff line number Diff line change @@ -12,17 +12,28 @@ class LinesClassifier
12
12
COMMENT_LINE = /^\s *#/ . freeze
13
13
WHITESPACE_OR_COMMENT_LINE = Regexp . union ( WHITESPACE_LINE , COMMENT_LINE )
14
14
15
- def self . no_cov_line
15
+ def self . no_cov_block
16
16
/^(\s *)#(\s *)(:#{ SimpleCov . nocov_token } :)/o
17
17
end
18
18
19
+ def self . no_cov_line
20
+ /#(\s *)(:#{ SimpleCov . nocov_token } :)(\s *)$/o
21
+ end
22
+
19
23
def self . no_cov_line? ( line )
20
24
no_cov_line . match? ( line )
21
25
rescue ArgumentError
22
26
# E.g., line contains an invalid byte sequence in UTF-8
23
27
false
24
28
end
25
29
30
+ def self . no_cov_block? ( line )
31
+ no_cov_block . match? ( line )
32
+ rescue ArgumentError
33
+ # E.g., line contains an invalid byte sequence in UTF-8
34
+ false
35
+ end
36
+
26
37
def self . whitespace_line? ( line )
27
38
WHITESPACE_OR_COMMENT_LINE . match? ( line )
28
39
rescue ArgumentError
@@ -34,10 +45,10 @@ def classify(lines)
34
45
skipping = false
35
46
36
47
lines . map do |line |
37
- if self . class . no_cov_line ?( line )
48
+ if self . class . no_cov_block ?( line )
38
49
skipping = !skipping
39
50
NOT_RELEVANT
40
- elsif skipping || self . class . whitespace_line? ( line )
51
+ elsif skipping || self . class . no_cov_line? ( line ) || self . class . whitespace_line? ( line )
41
52
NOT_RELEVANT
42
53
else
43
54
RELEVANT
Original file line number Diff line number Diff line change 65
65
end
66
66
end
67
67
68
+ describe ":nocov: one liner" do
69
+ it "determines :nocov: lines are not-relevant" do
70
+ classified_lines = subject . classify [
71
+ "def hi" ,
72
+ "raise NotImplementedError # :nocov:" ,
73
+ "end" ,
74
+ ""
75
+ ]
76
+
77
+ expect ( classified_lines . length ) . to eq 4
78
+ expect ( classified_lines [ 1 ] ) . to be_irrelevant
79
+ end
80
+ end
81
+
68
82
describe ":nocov: blocks" do
69
83
it "determines :nocov: blocks are not-relevant" do
70
84
classified_lines = subject . classify [
80
94
81
95
it "determines all lines after a non-closing :nocov: as not-relevant" do
82
96
classified_lines = subject . classify [
97
+ "puts 'Not relevant' # :nocov:" ,
83
98
"# :nocov:" ,
84
99
"puts 'Not relevant'" ,
85
100
"# :nocov:" ,
86
101
"puts 'Relevant again'" ,
87
102
"puts 'Still relevant'" ,
88
103
"# :nocov:" ,
89
- "puts 'Not relevant till the end'" ,
104
+ "puts 'Not relevant till the end' # :nocov: " ,
90
105
"puts 'Ditto'"
91
106
]
92
107
93
- expect ( classified_lines . length ) . to eq 8
108
+ expect ( classified_lines . length ) . to eq 9
94
109
95
- expect ( classified_lines [ 0 ..2 ] ) . to all be_irrelevant
96
- expect ( classified_lines [ 3 ..4 ] ) . to all be_relevant
97
- expect ( classified_lines [ 5 ..7 ] ) . to all be_irrelevant
110
+ expect ( classified_lines [ 0 ] ) . to be_irrelevant
111
+ expect ( classified_lines [ 1 ..3 ] ) . to all be_irrelevant
112
+ expect ( classified_lines [ 4 ..5 ] ) . to all be_relevant
113
+ expect ( classified_lines [ 6 ..8 ] ) . to all be_irrelevant
98
114
end
99
115
end
100
116
end
You can’t perform that action at this time.
0 commit comments