Skip to content

Commit

Permalink
Fix #877.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongl authored and tgodzik committed Jun 24, 2024
1 parent 06c9034 commit 4048e26
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 11 deletions.
2 changes: 1 addition & 1 deletion mdoc/src/main/scala/mdoc/internal/markdown/Renderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ object Renderer {
case FailSection(instrumented, startLine, startColumn, endLine, endColumn) =>
val input = Input.String(instrumented)
val edit =
TokenEditDistance.fromInputs(doc.sections.map(_.source.pos.input), input)
TokenEditDistance.fromTrees(Seq(section.source.source), input)
val compiled = compiler.fail(edit, input, section.source.pos)
val tpos = new RangePosition(startLine, startColumn, endLine, endColumn)
val pos = tpos.toMeta(section)
Expand Down
43 changes: 43 additions & 0 deletions tests/unit/src/test/scala-3/tests/markdown/FailPositionSuite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package tests.markdown

import tests.markdown.StringSyntax._
import tests.markdown.Compat

class FailPositionSuite extends BaseMarkdownSuite {

check(
"position",
"""|```scala mdoc
|extension (x: Int)
| def ===(y: Int) = x == y
|```
|
|```scala mdoc:fail
|1 === ""
|```
|
|```scala mdoc:silent
| 1 === 1
|```
""".stripMargin,
"""|```scala
|extension (x: Int)
| def ===(y: Int) = x == y
|```
|
|```scala
|1 === ""
|// error:
|// Found: ("" : String)
|// Required: Int
|// 1 === ""
|// ^^
|```
|
|```scala
| 1 === 1
|```
""".stripMargin
)

}
22 changes: 12 additions & 10 deletions tests/unit/src/test/scala/tests/markdown/FailSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -381,46 +381,48 @@ class FailSuite extends BaseMarkdownSuite {
"two-errors",
"""
|```scala mdoc:fail
|val nope = "foo" * "goo"
|val one = "foo" * "goo"
|```
|
|```scala mdoc:fail
|val bad = "moo" * "loo"
|val two = "moo" * "loo"
|```
""".stripMargin,
"""|```scala
|val nope = "foo" * "goo"
|val one = "foo" * "goo"
|// error: type mismatch;
|// found : String("goo")
|// required: Int
|// val one = "foo" * "goo"
|// ^^^^^
|```
|
|```scala
|val bad = "moo" * "loo"
|val two = "moo" * "loo"
|// error: type mismatch;
|// found : String("loo")
|// required: Int
|// val bad = "moo" * "loo"
|// val two = "moo" * "loo"
|// ^^^^^
|```
|""".stripMargin,
compat = Map(
Compat.Scala3 ->
"""|```scala
|val nope = "foo" * "goo"
|val one = "foo" * "goo"
|// error:
|// Found: ("goo" : String)
|// Required: Int
|// val nope = "foo" * "goo"
|// ^^^^^
|// val one = "foo" * "goo"
|// ^^^^^
|```
|
|```scala
|val bad = "moo" * "loo"
|val two = "moo" * "loo"
|// error:
|// Found: ("loo" : String)
|// Required: Int
|// val bad = "moo" * "loo"
|// val two = "moo" * "loo"
|// ^^^^^
|```
|""".stripMargin
Expand Down

0 comments on commit 4048e26

Please sign in to comment.