Skip to content

Commit 9d0f033

Browse files
committed
Allow sclicheck to detect code blocks starting with >3 backticks & add dedicated handling for Markdown code blocks
1 parent 2aa52cf commit 9d0f033

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

modules/docs-tests/src/main/scala/sclicheck/sclicheck.scala

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ import scala.io.StdIn.readLine
99
import scala.util.Random
1010
import scala.util.matching.Regex
1111

12-
val SnippetBlock = """ *(```[`]*)[^ ]+ title=([\w\d\.\-\/_]+) *""".r
13-
val CompileBlock = """ *(```[`]*) *(\w+) +(compile|fail) *(?:title=([\w\d\.\-\/_]+))? *""".r
14-
def compileBlockEnds(backticks: String): Regex = {
15-
val regexString = s""" *$backticks *"""
16-
regexString.r
17-
}
18-
val BashCommand = """ *```bash *(fail)? *""".r
19-
val CheckBlock = """ *\<\!-- Expected(-regex)?: *""".r
20-
val CheckBlockEnd = """ *\--> *""".r
21-
val Clear = """ *<!--+ *clear *-+-> *""".r
12+
val SnippetBlock = """ *(`{2}`+)[^ ]+ title=([\w\d.\-/_]+) *""".r
13+
val CompileBlock = """ *(`{2}`+) *(\w+) +(compile|fail) *(?:title=([\w\d.\-/_]+))? *""".r
14+
def compileBlockEnds(backticks: String) = s""" *$backticks *""".r
15+
val BashCommand = """ *```bash *(fail)? *""".r
16+
val CheckBlock = """ *\<\!-- Expected(-regex)?: *""".r
17+
val CheckBlockEnd = """ *\--> *""".r
18+
val Clear = """ *<!--+ *clear *-+-> *""".r
2219

2320
case class Options(
2421
scalaCliCommand: Seq[String],

modules/docs-tests/src/test/scala/sclicheck/SclicheckTests.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package sclicheck
22

33
class SclicheckTests extends munit.FunSuite:
44
test("Run regex") {
5+
assert(None == clue(CompileBlock.unapplySeq("``scala compile")))
56
assert(
67
Some(Seq("```", "scala", "compile", null)) == clue(
78
CompileBlock.unapplySeq("```scala compile")
@@ -15,6 +16,16 @@ class SclicheckTests extends munit.FunSuite:
1516
CompileBlock.unapplySeq("````markdown compile")
1617
)
1718
)
19+
assert(
20+
Some(Seq("````", "markdown", "fail", "a.md")) == clue(
21+
CompileBlock.unapplySeq("````markdown fail title=a.md")
22+
)
23+
)
24+
assert(
25+
None == clue(
26+
CompileBlock.unapplySeq("``scala fail title=a.sc")
27+
)
28+
)
1829
assert(
1930
Some(Seq("```", "scala", "fail", "a.sc")) == clue(
2031
CompileBlock.unapplySeq("```scala fail title=a.sc")

0 commit comments

Comments
 (0)