-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
140 additions
and
82 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
internal/compiler-bridge/src/main/java/xsbti/ConsoleFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
internal/compiler-bridge/src/main/java/xsbti/ConsoleInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
internal/compiler-bridge/src/main/java/xsbti/ConsoleResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
internal/compiler-bridge/src/main/java/xsbti/ConsoleResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
9 changes: 8 additions & 1 deletion
9
internal/compiler-bridge/src/main/scala/xsbt/ConsoleFactory.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 8 additions & 1 deletion
9
internal/compiler-bridge/src/main/scala/xsbt/ConsoleHelper.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 8 additions & 1 deletion
9
internal/compiler-bridge/src/main/scala/xsbt/ConsoleResponse.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
internal/compiler-bridge/src/test/scala/xsbt/ConsoleInterfaceSpecification.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package xsbt | ||
|
||
import sbt.internal.util.UnitSpec | ||
import sbt.util.Logger | ||
import xsbti.ConsoleResult | ||
|
||
// This is a specification to check the REPL block parsing. | ||
class ConsoleInterfaceSpecification extends UnitSpec { | ||
|
||
private val consoleFactory = new ConsoleFactory | ||
|
||
def consoleWithArgs(args: String*) = consoleFactory.createConsole( | ||
args = args.toArray, | ||
bootClasspathString = "", | ||
classpathString = "", | ||
initialCommands = "", | ||
cleanupCommands = "", | ||
loader = this.getClass.getClassLoader, | ||
bindNames = Array.empty, | ||
bindValues = Array.empty, | ||
log = Logger.Null | ||
) | ||
|
||
private val consoleWithoutArgs = consoleWithArgs() | ||
|
||
"Scala interpreter" should "evaluate arithmetic expression" in { | ||
val response = consoleWithoutArgs.interpret("1+1", false) | ||
response.output.trim shouldBe "res0: Int = 2" | ||
response.result shouldBe ConsoleResult.Success | ||
} | ||
|
||
it should "evaluate list constructor" in { | ||
val response = consoleWithoutArgs.interpret("List(1,2)", false) | ||
response.output.trim shouldBe "res1: List[Int] = List(1, 2)" | ||
response.result shouldBe ConsoleResult.Success | ||
} | ||
|
||
it should "evaluate import" in { | ||
val response = consoleWithoutArgs.interpret("import xsbt._", false) | ||
response.output.trim shouldBe "import xsbt._" | ||
response.result shouldBe ConsoleResult.Success | ||
} | ||
|
||
it should "mark partial expression as incomplete" in { | ||
val response = consoleWithoutArgs.interpret("val a =", false) | ||
response.result shouldBe ConsoleResult.Incomplete | ||
} | ||
|
||
it should "not evaluate incorrect expression" in { | ||
val response = consoleWithoutArgs.interpret("1 ++ 1", false) | ||
response.result shouldBe ConsoleResult.Error | ||
} | ||
|
||
val postfixOpExpression = "import scala.concurrent.duration._\nval t = 1 second" | ||
|
||
it should "evaluate postfix op with a warning" in { | ||
val response = consoleWithoutArgs.interpret(postfixOpExpression, false) | ||
response.output.trim should startWith("warning") | ||
response.result shouldBe ConsoleResult.Success | ||
} | ||
|
||
private val consoleWithPostfixOps = consoleWithArgs("-language:postfixOps") | ||
|
||
it should "evaluate postfix op without warning when -language:postfixOps arg passed" in { | ||
val response = consoleWithPostfixOps.interpret(postfixOpExpression, false) | ||
response.output.trim should not startWith "warning" | ||
response.result shouldBe ConsoleResult.Success | ||
} | ||
|
||
} |