File tree Expand file tree Collapse file tree 3 files changed +39
-3
lines changed
main/scala/scala/build/preprocessing
test/scala/scala/build/tests Expand file tree Collapse file tree 3 files changed +39
-3
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ package scala.build.preprocessing
3
3
import scala .util .matching .Regex
4
4
5
5
object SheBang {
6
- private val sheBangRegex : Regex = s """ (^(#!.*( \\ X)?)+( \\ X*!#.*)?) """ .r
6
+ private val sheBangRegex : Regex = s """ (^(#!.*( \\ X)?)+( \\ X*^ !#.*)?) """ .r
7
7
8
8
def isShebangScript (content : String ): Boolean = sheBangRegex.unanchored.matches(content)
9
9
Original file line number Diff line number Diff line change @@ -325,7 +325,14 @@ class SourcesTests extends TestUtil.ScalaCliBuildSuite {
325
325
|VAL=1
326
326
|!#
327
327
|
328
- |println("Hello World #!")""" .stripMargin
328
+ |println("Hello World #!")""" .stripMargin,
329
+ os.rel / " hasBangHashInComment.sc" ->
330
+ """ #!/usr/bin/scala-cli
331
+ |
332
+ |
333
+ |
334
+ |
335
+ |println("Hello World !#")""" .stripMargin
329
336
)
330
337
val expectedParsedCodes = Seq (
331
338
"""
@@ -349,7 +356,14 @@ class SourcesTests extends TestUtil.ScalaCliBuildSuite {
349
356
|
350
357
|
351
358
|
352
- |println("Hello World #!")""" .stripMargin
359
+ |println("Hello World #!")""" .stripMargin,
360
+ """
361
+ |
362
+ |
363
+ |
364
+ |
365
+ |
366
+ |println("Hello World !#")""" .stripMargin
353
367
)
354
368
355
369
testInputs.withInputs { (root, inputs) =>
Original file line number Diff line number Diff line change @@ -69,6 +69,28 @@ class MarkdownCodeBlockTests extends TestUtil.ScalaCliBuildSuite {
69
69
expect(actualResult == expectedResult)
70
70
}
71
71
72
+ test(" shebang closing line allowed in scala code" ) {
73
+ val code = """ println("Hello !#")""" .stripMargin
74
+ val markdown =
75
+ s """ # Some snippet
76
+ |
77
+ |```scala
78
+ |#!/usr/bin/env -S scala-cli shebang
79
+ | $code
80
+ |```
81
+ | """ .stripMargin
82
+ val expectedResult =
83
+ MarkdownCodeBlock (
84
+ info = PlainScalaInfo ,
85
+ body = " \n " + code,
86
+ startLine = 3 ,
87
+ endLine = 4
88
+ )
89
+ val Right (Seq (actualResult : MarkdownCodeBlock )) =
90
+ MarkdownCodeBlock .findCodeBlocks(os.sub / " Example.md" , markdown)
91
+ expect(actualResult == expectedResult)
92
+ }
93
+
72
94
test(" a raw Scala code block is extracted correctly from markdown" ) {
73
95
val code = """ object Main extends App {
74
96
| println("Hello")
You can’t perform that action at this time.
0 commit comments