@@ -130,15 +130,41 @@ class PluginCoverageTest extends FunSuite with MacroSupport {
130130 assert(! compiler.reporter.hasErrors)
131131 // should instrument:
132132 // 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",
137137 // case block "yes" literal
138138 // skip case block "yes" literal
139139 compiler.assertNMeasuredStatements(7 )
140140 }
141141
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+
142168 // https://github.com/scoverage/sbt-scoverage/issues/16
143169 test(
144170 " scoverage should instrument for-loops but not the generated scaffolding"
@@ -246,9 +272,9 @@ class PluginCoverageTest extends FunSuite with MacroSupport {
246272
247273 assert(! compiler.reporter.hasErrors)
248274 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
250276 // we are testing that we don't instrument the tuple2 call used here
251- compiler.assertNMeasuredStatements(4 )
277+ compiler.assertNMeasuredStatements(7 )
252278 }
253279
254280 test(" scoverage should instrument all case statements in an explicit match" ) {
0 commit comments