|
| 1 | +package scala.build.tests |
| 2 | + |
| 3 | +import com.eed3si9n.expecty.Expecty.expect |
| 4 | + |
| 5 | +import scala.build.input.SourceScalaFile |
| 6 | +import scala.build.preprocessing.{PreprocessedSource, ScalaPreprocessor} |
| 7 | + |
| 8 | +class ScalaPreprocessorTests extends munit.FunSuite { |
| 9 | + |
| 10 | + test("should respect using directives in a .scala file with the shebang line") { |
| 11 | + TestInputs(os.rel / "Main.scala" -> |
| 12 | + """#!/usr/bin/env -S scala-cli shebang |
| 13 | + |//> using lib "com.lihaoyi::os-lib::0.8.1" |
| 14 | + | |
| 15 | + |object Main { |
| 16 | + | def main(args: Array[String]): Unit = { |
| 17 | + | println(os.pwd) |
| 18 | + | } |
| 19 | + |}""".stripMargin).fromRoot { root => |
| 20 | + val scalaFile = SourceScalaFile(root, os.sub / "Main.scala") |
| 21 | + val Some(Right(result)) = ScalaPreprocessor.preprocess( |
| 22 | + scalaFile, |
| 23 | + logger = TestLogger(), |
| 24 | + allowRestrictedFeatures = false |
| 25 | + ) |
| 26 | + expect(result.nonEmpty) |
| 27 | + val Some(directivesPositions) = result.head.directivesPositions |
| 28 | + expect(directivesPositions.specialCommentDirectives.startPos == 0 -> 0) |
| 29 | + expect(directivesPositions.specialCommentDirectives.endPos == 3 -> 0) |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + test("should respect using directives in a .sc file with the shebang line") { |
| 34 | + TestInputs(os.rel / "sample.sc" -> |
| 35 | + """#!/usr/bin/env -S scala-cli shebang |
| 36 | + |//> using lib "com.lihaoyi::os-lib::0.8.1" |
| 37 | + |println(os.pwd) |
| 38 | + |""".stripMargin).fromRoot { root => |
| 39 | + val scalaFile = SourceScalaFile(root, os.sub / "sample.sc") |
| 40 | + val Some(Right(result)) = ScalaPreprocessor.preprocess( |
| 41 | + scalaFile, |
| 42 | + logger = TestLogger(), |
| 43 | + allowRestrictedFeatures = false |
| 44 | + ) |
| 45 | + expect(result.nonEmpty) |
| 46 | + val Some(directivesPositions) = result.head.directivesPositions |
| 47 | + expect(directivesPositions.specialCommentDirectives.startPos == 0 -> 0) |
| 48 | + expect(directivesPositions.specialCommentDirectives.endPos == 2 -> 0) |
| 49 | + } |
| 50 | + } |
| 51 | +} |
0 commit comments