@@ -130,15 +130,41 @@ class PluginCoverageTest extends FunSuite with MacroSupport {
130
130
assert(! compiler.reporter.hasErrors)
131
131
// should instrument:
132
132
// the if clause,
133
- // thenp block,
134
- // thenp literal "1",
135
- // elsep block,
136
- // elsep literal "2",
133
+ // then block,
134
+ // then literal "1",
135
+ // else block,
136
+ // else literal "2",
137
137
// case block "yes" literal
138
138
// skip case block "yes" literal
139
139
compiler.assertNMeasuredStatements(7 )
140
140
}
141
141
142
+ test(
143
+ " scoverage should instrument anonymous function with pattern matching body"
144
+ ) {
145
+ val compiler = ScoverageCompiler .default
146
+ compiler.compileCodeSnippet(
147
+ """ object A {
148
+ | def foo(a: List[Option[Int]]) = a.map {
149
+ | case Some(value) => value + 1
150
+ | case None => 0
151
+ | }
152
+ |} """ .stripMargin
153
+ )
154
+ assert(! compiler.reporter.hasErrors)
155
+ // should instrument:
156
+ // the def method entry,
157
+ // case Some,
158
+ // case block expression
159
+ // case none,
160
+ // case block literal "0"
161
+
162
+ // account for canbuildfrom statement
163
+ val expectedStatementsCount =
164
+ if (ScoverageCompiler .ShortScalaVersion < " 2.13" ) 6 else 5
165
+ compiler.assertNMeasuredStatements(expectedStatementsCount)
166
+ }
167
+
142
168
// https://github.com/scoverage/sbt-scoverage/issues/16
143
169
test(
144
170
" scoverage should instrument for-loops but not the generated scaffolding"
@@ -246,9 +272,9 @@ class PluginCoverageTest extends FunSuite with MacroSupport {
246
272
247
273
assert(! compiler.reporter.hasErrors)
248
274
assert(! compiler.reporter.hasWarnings)
249
- // should have 4 profiled statements: the outer apply, the true, the a < b, the false
275
+ // should have 7 profiled statements: the outer apply, and three pairs of case patterns & blocks
250
276
// we are testing that we don't instrument the tuple2 call used here
251
- compiler.assertNMeasuredStatements(4 )
277
+ compiler.assertNMeasuredStatements(7 )
252
278
}
253
279
254
280
test(" scoverage should instrument all case statements in an explicit match" ) {
0 commit comments