mirror of
https://github.com/enso-org/enso.git
synced 2024-10-26 21:19:02 +03:00
No Implicit Builtins (#1114)
This commit is contained in:
parent
eea08a9fca
commit
4e337840cf
@ -1,4 +1,4 @@
|
||||
import Builtins
|
||||
from Builtins import all
|
||||
|
||||
from Builtins export Nil, Cons
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
import Base.List
|
||||
import Builtins
|
||||
|
||||
from Builtins export all
|
||||
|
||||
from Base.List export Nil, Cons
|
||||
|
@ -1,4 +1,5 @@
|
||||
import Base.Process.Exit_Code
|
||||
from Builtins import System, True, False
|
||||
|
||||
## The builder object that is used to create operating system processes.
|
||||
type Process_Builder command arguments stdin
|
||||
|
@ -1,3 +1,5 @@
|
||||
from Builtins import System
|
||||
|
||||
type Os
|
||||
type Linux
|
||||
type MacOS
|
||||
@ -16,4 +18,4 @@ from_text os =
|
||||
Return the OS type:
|
||||
Platform.os
|
||||
os : Os
|
||||
os = Platform.from_text System.os
|
||||
os = here.from_text System.os
|
||||
|
@ -1,4 +1,5 @@
|
||||
import Base.List
|
||||
from Builtins import all
|
||||
|
||||
## The top-level entry point for a test suite.
|
||||
type Suite specs
|
||||
|
@ -307,7 +307,13 @@ object Main {
|
||||
*/
|
||||
private def runRepl(projectPath: Option[String]): Unit = {
|
||||
val mainMethodName = "internal_repl_entry_point___"
|
||||
val dummySourceToTriggerRepl = s"$mainMethodName = Debug.breakpoint"
|
||||
// TODO[MK, RW]: when CI-testing can use a fully-built distribution,
|
||||
// switch to `from Base import all` here.
|
||||
val dummySourceToTriggerRepl =
|
||||
s"""from Builtins import all
|
||||
|
|
||||
|$mainMethodName = Debug.breakpoint
|
||||
|""".stripMargin
|
||||
val replModuleName = "Internal_Repl_Module___"
|
||||
val packagePath = projectPath.getOrElse("")
|
||||
val context =
|
||||
|
@ -20,7 +20,8 @@ class AtomFixtures extends DefaultInterpreterRunner {
|
||||
val millionElementList = buildInputList(million)
|
||||
|
||||
val generateListCode =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main = length ->
|
||||
| generator = acc -> i -> if i == 0 then acc else generator (Cons i acc) (i - 1)
|
||||
|
|
||||
@ -30,7 +31,8 @@ class AtomFixtures extends DefaultInterpreterRunner {
|
||||
val generateList = getMain(generateListCode)
|
||||
|
||||
val generateListQualifiedCode =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main = length ->
|
||||
| generator = acc -> i -> if i == 0 then acc else generator (Builtins.cons i acc) (i - 1)
|
||||
|
|
||||
@ -40,7 +42,8 @@ class AtomFixtures extends DefaultInterpreterRunner {
|
||||
val generateListQualified = getMain(generateListQualifiedCode)
|
||||
|
||||
val reverseListCode =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main = list ->
|
||||
| reverser = acc -> list -> case list of
|
||||
| Cons h t -> reverser (Cons h acc) t
|
||||
@ -52,7 +55,8 @@ class AtomFixtures extends DefaultInterpreterRunner {
|
||||
val reverseList = getMain(reverseListCode)
|
||||
|
||||
val reverseListMethodsCode =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Cons.reverse = acc -> case this of
|
||||
| Cons h t -> reverse t (Cons h acc)
|
||||
|
|
||||
@ -65,7 +69,8 @@ class AtomFixtures extends DefaultInterpreterRunner {
|
||||
val reverseListMethods = getMain(reverseListMethodsCode)
|
||||
|
||||
val sumListCode =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main = list ->
|
||||
| summator = acc -> list -> case list of
|
||||
| Cons h t -> summator acc+h t
|
||||
@ -77,7 +82,8 @@ class AtomFixtures extends DefaultInterpreterRunner {
|
||||
val sumList = getMain(sumListCode)
|
||||
|
||||
val sumListLeftFoldCode =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main = list ->
|
||||
| fold = f -> acc -> list -> case list of
|
||||
| Cons h t -> fold f (f acc h) t
|
||||
@ -89,7 +95,8 @@ class AtomFixtures extends DefaultInterpreterRunner {
|
||||
val sumListLeftFold = getMain(sumListLeftFoldCode)
|
||||
|
||||
val sumListFallbackCode =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main = list ->
|
||||
| summator = acc -> list -> case list of
|
||||
| Cons h t -> summator acc+h t
|
||||
@ -101,7 +108,8 @@ class AtomFixtures extends DefaultInterpreterRunner {
|
||||
val sumListFallback = getMain(sumListFallbackCode)
|
||||
|
||||
val sumListMethodsCode =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Nil.sum = acc -> acc
|
||||
|Cons.sum = acc -> case this of
|
||||
| Cons h t -> sum t h+acc
|
||||
@ -113,7 +121,8 @@ class AtomFixtures extends DefaultInterpreterRunner {
|
||||
val sumListMethods = getMain(sumListMethodsCode)
|
||||
|
||||
val mapReverseListCode =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Nil.mapReverse = f -> acc -> acc
|
||||
|Cons.mapReverse = f -> acc -> case this of
|
||||
| Cons h t -> mapReverse t f (Cons (f h) acc)
|
||||
@ -125,7 +134,8 @@ class AtomFixtures extends DefaultInterpreterRunner {
|
||||
val mapReverseList = getMain(mapReverseListCode)
|
||||
|
||||
val mapReverseListCurryCode =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Nil.mapReverse = f -> acc -> acc
|
||||
|Cons.mapReverse = f -> acc -> case this of
|
||||
| Cons h t -> mapReverse t f (Cons (f h) acc)
|
||||
|
@ -49,7 +49,8 @@ class RecursionFixtures extends DefaultInterpreterRunner {
|
||||
val oversaturatedRecursiveCall = getMain(oversaturatedRecursiveCallTCOCode)
|
||||
|
||||
val sumStateTCOCode =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|stateSum = n ->
|
||||
| acc = State.get Number
|
||||
| State.put Number (acc + n)
|
||||
@ -62,7 +63,8 @@ class RecursionFixtures extends DefaultInterpreterRunner {
|
||||
val sumStateTCO = getMain(sumStateTCOCode)
|
||||
|
||||
val sumTCOWithEvalCode =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main = sumTo ->
|
||||
| summator = acc -> current ->
|
||||
| if current == 0 then acc else Debug.eval "summator (acc + current) (current - 1)"
|
||||
@ -73,7 +75,8 @@ class RecursionFixtures extends DefaultInterpreterRunner {
|
||||
val sumTCOWithEval = getMain(sumTCOWithEvalCode)
|
||||
|
||||
val nestedThunkSumCode =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|doNTimes = n -> ~block ->
|
||||
| block
|
||||
| if n == 1 then Unit else here.doNTimes n-1 block
|
||||
|
@ -167,40 +167,6 @@ public class Context {
|
||||
return inReader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new module scope that automatically imports all the builtin types and methods.
|
||||
*
|
||||
* @param module the module related to the newly created scope.
|
||||
* @return a new module scope with automatic builtins dependency.
|
||||
*/
|
||||
public ModuleScope createScope(Module module) {
|
||||
ModuleScope moduleScope = new ModuleScope(module);
|
||||
initializeScope(moduleScope);
|
||||
return moduleScope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new module with scope that automatically imports all the builtin types and methods.
|
||||
*
|
||||
* @param name the qualified name of the newly created module.
|
||||
* @return a new module containing scope with automatic builtins dependency.
|
||||
*/
|
||||
public Module createModule(QualifiedName name) {
|
||||
Module module = Module.empty(name);
|
||||
initializeScope(module.compileScope(this));
|
||||
return module;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all contents from a given scope.
|
||||
*
|
||||
* @param scope the scope to reset.
|
||||
*/
|
||||
public void resetScope(ModuleScope scope) {
|
||||
scope.reset();
|
||||
initializeScope(scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the module name associated with a given file, using the environment packages
|
||||
* information.
|
||||
@ -272,10 +238,6 @@ public class Context {
|
||||
.map(name -> getTopScope().createModule(name, getTruffleFile(path)));
|
||||
}
|
||||
|
||||
private void initializeScope(ModuleScope scope) {
|
||||
scope.addImport(getBuiltins().getScope());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the builtin functions from the compiler.
|
||||
*
|
||||
|
@ -185,7 +185,7 @@ public class Module implements TruffleObject {
|
||||
* @return the scope defined by this module
|
||||
*/
|
||||
public ModuleScope compileScope(Context context) {
|
||||
ensureScopeExists(context);
|
||||
ensureScopeExists();
|
||||
if (!compilationStage.isAtLeast(CompilationStage.AFTER_CODEGEN)) {
|
||||
try {
|
||||
compile(context);
|
||||
@ -198,11 +198,10 @@ public class Module implements TruffleObject {
|
||||
/**
|
||||
* Create scope if it does not exist.
|
||||
*
|
||||
* @param context the language context.
|
||||
*/
|
||||
public void ensureScopeExists(Context context) {
|
||||
public void ensureScopeExists() {
|
||||
if (scope == null) {
|
||||
scope = context.createScope(this);
|
||||
scope = new ModuleScope(this);
|
||||
compilationStage = CompilationStage.INITIAL;
|
||||
}
|
||||
}
|
||||
@ -225,10 +224,10 @@ public class Module implements TruffleObject {
|
||||
}
|
||||
|
||||
private void compile(Context context) throws IOException {
|
||||
ensureScopeExists(context);
|
||||
ensureScopeExists();
|
||||
Source source = getSource();
|
||||
if (source == null) return;
|
||||
context.resetScope(scope);
|
||||
scope.reset();
|
||||
compilationStage = CompilationStage.INITIAL;
|
||||
context.getCompiler().run(source, this);
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ public class TopLevelScope implements TruffleObject {
|
||||
private static Module createModule(TopLevelScope scope, Object[] arguments, Context context)
|
||||
throws ArityException, UnsupportedTypeException {
|
||||
String moduleName = Types.extractArguments(arguments, String.class);
|
||||
return context.createModule(QualifiedName.simpleName(moduleName));
|
||||
return Module.empty(QualifiedName.simpleName(moduleName));
|
||||
}
|
||||
|
||||
private static Module registerModule(TopLevelScope scope, Object[] arguments, Context context)
|
||||
|
@ -101,8 +101,8 @@ class Compiler(val context: Context) {
|
||||
}
|
||||
|
||||
private def parseModule(module: Module): Unit = {
|
||||
module.ensureScopeExists(context)
|
||||
context.resetScope(module.getScope)
|
||||
module.ensureScopeExists()
|
||||
module.getScope.reset()
|
||||
val moduleContext = ModuleContext(
|
||||
module = module,
|
||||
freshNameSupply = Some(freshNameSupply)
|
||||
|
@ -59,29 +59,7 @@ class ImportResolver(compiler: Compiler) {
|
||||
case _ => None
|
||||
}
|
||||
|
||||
// TODO[MK] Remove when No Implicit Prelude
|
||||
val builtinResolution = BindingsMap.ResolvedImport(
|
||||
IR.Module.Scope.Import
|
||||
.Module(
|
||||
IR.Name.Qualified(
|
||||
List(
|
||||
IR.Name.Literal("Builtins", isReferent = true, None),
|
||||
IR.Name.Literal("Main", isReferent = true, None)
|
||||
),
|
||||
None
|
||||
),
|
||||
Some(IR.Name.Literal("Builtins", isReferent = true, None)),
|
||||
isAll = true,
|
||||
None,
|
||||
None,
|
||||
None
|
||||
),
|
||||
None,
|
||||
compiler.context.getBuiltins.getModule
|
||||
)
|
||||
|
||||
currentLocal.resolvedImports =
|
||||
builtinResolution :: importedModules
|
||||
currentLocal.resolvedImports = importedModules
|
||||
current.unsafeSetCompilationStage(
|
||||
Module.CompilationStage.AFTER_IMPORT_RESOLUTION
|
||||
)
|
||||
|
@ -1,3 +1,4 @@
|
||||
from Builtins import all
|
||||
from TestNonImportedOverloads.Util import all
|
||||
|
||||
X.method = 10
|
||||
|
@ -1,3 +1,5 @@
|
||||
from Builtins import all
|
||||
|
||||
type X a
|
||||
|
||||
Unit.util = x -> x.method
|
||||
|
@ -1,3 +1,4 @@
|
||||
from Builtins import all
|
||||
import TestNonImportedOwnMethods.Util
|
||||
|
||||
type X a
|
||||
|
@ -1 +1,3 @@
|
||||
from Builtins import all
|
||||
|
||||
Unit.util = x -> x.method
|
||||
|
@ -19,6 +19,8 @@ class ReplTest extends InterpreterTest with BeforeAndAfter with EitherValues {
|
||||
"initialize properly" in {
|
||||
val code =
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|main = Debug.breakpoint
|
||||
|""".stripMargin
|
||||
setSessionManager(executor => executor.exit())
|
||||
@ -28,6 +30,8 @@ class ReplTest extends InterpreterTest with BeforeAndAfter with EitherValues {
|
||||
"be able to execute arbitrary code in the caller scope" in {
|
||||
val code =
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| x = 1
|
||||
| y = 2
|
||||
@ -46,6 +50,8 @@ class ReplTest extends InterpreterTest with BeforeAndAfter with EitherValues {
|
||||
"return the last evaluated value back to normal execution flow" in {
|
||||
val code =
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| a = 5
|
||||
| b = 6
|
||||
@ -62,6 +68,8 @@ class ReplTest extends InterpreterTest with BeforeAndAfter with EitherValues {
|
||||
"be able to define its local variables" in {
|
||||
val code =
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| x = 10
|
||||
| Debug.breakpoint
|
||||
@ -78,6 +86,8 @@ class ReplTest extends InterpreterTest with BeforeAndAfter with EitherValues {
|
||||
"not overwrite bindings" in {
|
||||
val code =
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| x = 10
|
||||
| Debug.breakpoint
|
||||
@ -93,6 +103,8 @@ class ReplTest extends InterpreterTest with BeforeAndAfter with EitherValues {
|
||||
"access and modify monadic state" in {
|
||||
val code =
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|run =
|
||||
| State.put Number 10
|
||||
| Debug.breakpoint
|
||||
@ -111,6 +123,8 @@ class ReplTest extends InterpreterTest with BeforeAndAfter with EitherValues {
|
||||
"be able to list local variables in its scope" in {
|
||||
val code =
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| x = 10
|
||||
| y = 20
|
||||
@ -135,6 +149,8 @@ class ReplTest extends InterpreterTest with BeforeAndAfter with EitherValues {
|
||||
"be able to list bindings it has created" in {
|
||||
val code =
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| x = 10
|
||||
| y = 20
|
||||
@ -160,6 +176,8 @@ class ReplTest extends InterpreterTest with BeforeAndAfter with EitherValues {
|
||||
"allow to be nested" in {
|
||||
val code =
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| 10 * Debug.breakpoint + 1
|
||||
|""".stripMargin
|
||||
@ -181,6 +199,8 @@ class ReplTest extends InterpreterTest with BeforeAndAfter with EitherValues {
|
||||
"behave well when nested" in {
|
||||
val code =
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| x = 1
|
||||
| 10 * Debug.breakpoint + x
|
||||
@ -206,6 +226,8 @@ class ReplTest extends InterpreterTest with BeforeAndAfter with EitherValues {
|
||||
"handle errors gracefully" in {
|
||||
val code =
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| Debug.breakpoint
|
||||
|""".stripMargin
|
||||
@ -224,6 +246,8 @@ class ReplTest extends InterpreterTest with BeforeAndAfter with EitherValues {
|
||||
"attach language stack traces to the exception" in {
|
||||
val code =
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| Debug.breakpoint
|
||||
|""".stripMargin
|
||||
@ -248,6 +272,8 @@ class ReplTest extends InterpreterTest with BeforeAndAfter with EitherValues {
|
||||
"not pollute bindings upon nested error" in {
|
||||
val code =
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| Debug.breakpoint
|
||||
|""".stripMargin
|
||||
|
@ -106,15 +106,17 @@ class RuntimeServerTest
|
||||
|
||||
val metadata = new Metadata
|
||||
|
||||
val idMainX = metadata.addItem(16, 1)
|
||||
val idMainY = metadata.addItem(26, 7)
|
||||
val idMainZ = metadata.addItem(42, 5)
|
||||
val idFooY = metadata.addItem(81, 8)
|
||||
val idFooZ = metadata.addItem(98, 5)
|
||||
val idMainX = metadata.addItem(42, 1)
|
||||
val idMainY = metadata.addItem(52, 7)
|
||||
val idMainZ = metadata.addItem(68, 5)
|
||||
val idFooY = metadata.addItem(107, 8)
|
||||
val idFooZ = metadata.addItem(124, 5)
|
||||
|
||||
def code =
|
||||
metadata.appendToCode(
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| x = 6
|
||||
| y = x.foo 5
|
||||
@ -205,11 +207,13 @@ class RuntimeServerTest
|
||||
object Main2 {
|
||||
|
||||
val metadata = new Metadata
|
||||
val idMainY = metadata.addItem(148, 10)
|
||||
val idMainZ = metadata.addItem(167, 10)
|
||||
val idMainY = metadata.addItem(174, 10)
|
||||
val idMainZ = metadata.addItem(193, 10)
|
||||
|
||||
val code = metadata.appendToCode(
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|foo = arg ->
|
||||
| IO.println "I'm expensive!"
|
||||
| arg + 5
|
||||
@ -382,11 +386,13 @@ class RuntimeServerTest
|
||||
val moduleName = "Test.Main"
|
||||
|
||||
val metadata = new Metadata
|
||||
val idMain = metadata.addItem(23, 17)
|
||||
val idMainFoo = metadata.addItem(28, 12)
|
||||
val idMain = metadata.addItem(49, 17)
|
||||
val idMainFoo = metadata.addItem(54, 12)
|
||||
|
||||
val code =
|
||||
"""foo a b = a + b
|
||||
"""from Builtins import all
|
||||
|
|
||||
|foo a b = a + b
|
||||
|
|
||||
|main =
|
||||
| this.foo 1 2
|
||||
@ -483,11 +489,13 @@ class RuntimeServerTest
|
||||
val moduleName = "Test.Main"
|
||||
|
||||
val metadata = new Metadata
|
||||
val idMain = metadata.addItem(23, 30)
|
||||
val idMainFoo = metadata.addItem(40, 12)
|
||||
val idMain = metadata.addItem(49, 30)
|
||||
val idMainFoo = metadata.addItem(66, 12)
|
||||
|
||||
val code =
|
||||
"""foo a b = a + b
|
||||
"""from Builtins import all
|
||||
|
|
||||
|foo a b = a + b
|
||||
|
|
||||
|main =
|
||||
| IO.println (this.foo 1 2)
|
||||
@ -585,11 +593,13 @@ class RuntimeServerTest
|
||||
val moduleName = "Test.Main"
|
||||
|
||||
val metadata = new Metadata
|
||||
val idMain = metadata.addItem(7, 41)
|
||||
val idMainBar = metadata.addItem(39, 8)
|
||||
val idMain = metadata.addItem(33, 41)
|
||||
val idMainBar = metadata.addItem(65, 8)
|
||||
|
||||
val code =
|
||||
"""main = IO.println (State.run Number 42 this.bar)
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main = IO.println (State.run Number 42 this.bar)
|
||||
|
|
||||
|bar = State.get Number
|
||||
|""".stripMargin
|
||||
@ -682,11 +692,13 @@ class RuntimeServerTest
|
||||
val moduleName = "Test.Main"
|
||||
|
||||
val metadata = new Metadata
|
||||
val idMain = metadata.addItem(7, 40)
|
||||
val idMainBar = metadata.addItem(38, 8)
|
||||
val idMain = metadata.addItem(33, 40)
|
||||
val idMainBar = metadata.addItem(64, 8)
|
||||
|
||||
val code =
|
||||
"""main = IO.println (State.run Number 0 this.bar)
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main = IO.println (State.run Number 0 this.bar)
|
||||
|
|
||||
|bar =
|
||||
| State.put Number 10
|
||||
@ -781,11 +793,13 @@ class RuntimeServerTest
|
||||
val moduleName = "Test.Main"
|
||||
|
||||
val metadata = new Metadata
|
||||
val idMain = metadata.addItem(23, 23)
|
||||
val idMainFoo = metadata.addItem(28, 12)
|
||||
val idMain = metadata.addItem(49, 23)
|
||||
val idMainFoo = metadata.addItem(54, 12)
|
||||
|
||||
val code =
|
||||
"""foo a b = a + b
|
||||
"""from Builtins import all
|
||||
|
|
||||
|foo a b = a + b
|
||||
|
|
||||
|main =
|
||||
| this.foo 1 2
|
||||
@ -881,7 +895,7 @@ class RuntimeServerTest
|
||||
val contextId = UUID.randomUUID()
|
||||
val requestId = UUID.randomUUID()
|
||||
val moduleName = "Test.Main"
|
||||
val idMain = context.Main.metadata.addItem(7, 47)
|
||||
val idMain = context.Main.metadata.addItem(33, 47)
|
||||
val idMainUpdate =
|
||||
Api.Response(
|
||||
Api.ExpressionValuesComputed(
|
||||
@ -960,7 +974,7 @@ class RuntimeServerTest
|
||||
"x",
|
||||
"Any",
|
||||
Suggestion
|
||||
.Scope(Suggestion.Position(1, 6), Suggestion.Position(6, 0))
|
||||
.Scope(Suggestion.Position(3, 6), Suggestion.Position(8, 0))
|
||||
)
|
||||
),
|
||||
Api.SuggestionsDatabaseUpdate.Add(
|
||||
@ -970,7 +984,7 @@ class RuntimeServerTest
|
||||
"y",
|
||||
"Any",
|
||||
Suggestion
|
||||
.Scope(Suggestion.Position(1, 6), Suggestion.Position(6, 0))
|
||||
.Scope(Suggestion.Position(3, 6), Suggestion.Position(8, 0))
|
||||
)
|
||||
),
|
||||
Api.SuggestionsDatabaseUpdate.Add(
|
||||
@ -980,7 +994,7 @@ class RuntimeServerTest
|
||||
"z",
|
||||
"Any",
|
||||
Suggestion
|
||||
.Scope(Suggestion.Position(1, 6), Suggestion.Position(6, 0))
|
||||
.Scope(Suggestion.Position(3, 6), Suggestion.Position(8, 0))
|
||||
)
|
||||
),
|
||||
Api.SuggestionsDatabaseUpdate.Add(
|
||||
@ -990,7 +1004,7 @@ class RuntimeServerTest
|
||||
"y",
|
||||
"Any",
|
||||
Suggestion
|
||||
.Scope(Suggestion.Position(7, 17), Suggestion.Position(10, 5))
|
||||
.Scope(Suggestion.Position(9, 17), Suggestion.Position(12, 5))
|
||||
)
|
||||
),
|
||||
Api.SuggestionsDatabaseUpdate.Add(
|
||||
@ -1000,8 +1014,8 @@ class RuntimeServerTest
|
||||
"z",
|
||||
"Any",
|
||||
Suggestion.Scope(
|
||||
Suggestion.Position(7, 17),
|
||||
Suggestion.Position(10, 5)
|
||||
Suggestion.Position(9, 17),
|
||||
Suggestion.Position(12, 5)
|
||||
)
|
||||
)
|
||||
)
|
||||
@ -1055,11 +1069,13 @@ class RuntimeServerTest
|
||||
val moduleName = "Test.Main"
|
||||
|
||||
val metadata = new Metadata
|
||||
val idResult = metadata.addItem(20, 4)
|
||||
val idPrintln = metadata.addItem(29, 17)
|
||||
val idMain = metadata.addItem(6, 40)
|
||||
val idResult = metadata.addItem(46, 4)
|
||||
val idPrintln = metadata.addItem(55, 17)
|
||||
val idMain = metadata.addItem(32, 40)
|
||||
val code =
|
||||
"""main =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| result = 1337
|
||||
| IO.println result
|
||||
|""".stripMargin.linesIterator.mkString("\n")
|
||||
@ -1134,8 +1150,8 @@ class RuntimeServerTest
|
||||
"result",
|
||||
"Any",
|
||||
Suggestion.Scope(
|
||||
Suggestion.Position(0, 6),
|
||||
Suggestion.Position(2, 21)
|
||||
Suggestion.Position(2, 6),
|
||||
Suggestion.Position(4, 21)
|
||||
)
|
||||
)
|
||||
)
|
||||
@ -1153,7 +1169,7 @@ class RuntimeServerTest
|
||||
mainFile,
|
||||
Seq(
|
||||
TextEdit(
|
||||
model.Range(model.Position(1, 13), model.Position(1, 17)),
|
||||
model.Range(model.Position(3, 13), model.Position(3, 17)),
|
||||
"\"Hi\""
|
||||
)
|
||||
)
|
||||
@ -1178,15 +1194,17 @@ class RuntimeServerTest
|
||||
val moduleName = "Test.Main"
|
||||
|
||||
val metadata = new Metadata
|
||||
val idMain = metadata.addItem(6, 35)
|
||||
val idMainA = metadata.addItem(15, 8)
|
||||
val idMainP = metadata.addItem(28, 12)
|
||||
val idPie = metadata.addItem(45 + 8, 1)
|
||||
val idUwu = metadata.addItem(58 + 8, 1)
|
||||
val idHie = metadata.addItem(71 + 8, 6)
|
||||
val idXxx = metadata.addItem(91 + 8, 1)
|
||||
val idMain = metadata.addItem(32, 35)
|
||||
val idMainA = metadata.addItem(41, 8)
|
||||
val idMainP = metadata.addItem(54, 12)
|
||||
val idPie = metadata.addItem(71 + 8, 1)
|
||||
val idUwu = metadata.addItem(84 + 8, 1)
|
||||
val idHie = metadata.addItem(97 + 8, 6)
|
||||
val idXxx = metadata.addItem(117 + 8, 1)
|
||||
val code =
|
||||
"""main =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| a = 123 + 21
|
||||
| IO.println a
|
||||
|
|
||||
@ -1313,8 +1331,8 @@ class RuntimeServerTest
|
||||
"a",
|
||||
"Any",
|
||||
Suggestion.Scope(
|
||||
Suggestion.Position(0, 6),
|
||||
Suggestion.Position(3, 0)
|
||||
Suggestion.Position(2, 6),
|
||||
Suggestion.Position(5, 0)
|
||||
)
|
||||
)
|
||||
)
|
||||
@ -1332,7 +1350,7 @@ class RuntimeServerTest
|
||||
mainFile,
|
||||
Seq(
|
||||
TextEdit(
|
||||
model.Range(model.Position(1, 8), model.Position(1, 16)),
|
||||
model.Range(model.Position(3, 8), model.Position(3, 16)),
|
||||
"1234.x 4"
|
||||
)
|
||||
)
|
||||
@ -1363,7 +1381,7 @@ class RuntimeServerTest
|
||||
mainFile,
|
||||
Seq(
|
||||
TextEdit(
|
||||
model.Range(model.Position(1, 8), model.Position(1, 16)),
|
||||
model.Range(model.Position(3, 8), model.Position(3, 16)),
|
||||
"1000.x 5"
|
||||
)
|
||||
)
|
||||
@ -1380,7 +1398,7 @@ class RuntimeServerTest
|
||||
mainFile,
|
||||
Seq(
|
||||
TextEdit(
|
||||
model.Range(model.Position(1, 8), model.Position(1, 16)),
|
||||
model.Range(model.Position(3, 8), model.Position(3, 16)),
|
||||
"Main.pie"
|
||||
)
|
||||
)
|
||||
@ -1411,7 +1429,7 @@ class RuntimeServerTest
|
||||
mainFile,
|
||||
Seq(
|
||||
TextEdit(
|
||||
model.Range(model.Position(1, 8), model.Position(1, 16)),
|
||||
model.Range(model.Position(3, 8), model.Position(3, 16)),
|
||||
"Main.uwu"
|
||||
)
|
||||
)
|
||||
@ -1442,7 +1460,7 @@ class RuntimeServerTest
|
||||
mainFile,
|
||||
Seq(
|
||||
TextEdit(
|
||||
model.Range(model.Position(1, 8), model.Position(1, 16)),
|
||||
model.Range(model.Position(3, 8), model.Position(3, 16)),
|
||||
"Main.hie"
|
||||
)
|
||||
)
|
||||
@ -1473,7 +1491,7 @@ class RuntimeServerTest
|
||||
mainFile,
|
||||
Seq(
|
||||
TextEdit(
|
||||
model.Range(model.Position(1, 8), model.Position(1, 16)),
|
||||
model.Range(model.Position(3, 8), model.Position(3, 16)),
|
||||
"\"Hello!\""
|
||||
)
|
||||
)
|
||||
@ -1498,13 +1516,15 @@ class RuntimeServerTest
|
||||
val moduleName = "Test.Main"
|
||||
|
||||
val metadata = new Metadata
|
||||
val idMain = metadata.addItem(6, 89)
|
||||
val id1 = metadata.addItem(15, 15)
|
||||
val id2 = metadata.addItem(35, 18)
|
||||
val id3 = metadata.addItem(58, 16)
|
||||
val idy = metadata.addItem(83, 2)
|
||||
val idMain = metadata.addItem(32, 89)
|
||||
val id1 = metadata.addItem(41, 15)
|
||||
val id2 = metadata.addItem(61, 18)
|
||||
val id3 = metadata.addItem(84, 16)
|
||||
val idy = metadata.addItem(109, 2)
|
||||
val code =
|
||||
"""main =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| x = 15.overloaded 1
|
||||
| "foo".overloaded 2
|
||||
| overloaded 10 30
|
||||
@ -1643,8 +1663,8 @@ class RuntimeServerTest
|
||||
"x",
|
||||
"Any",
|
||||
Suggestion.Scope(
|
||||
Suggestion.Position(0, 6),
|
||||
Suggestion.Position(6, 0)
|
||||
Suggestion.Position(2, 6),
|
||||
Suggestion.Position(8, 0)
|
||||
)
|
||||
)
|
||||
),
|
||||
@ -1655,8 +1675,8 @@ class RuntimeServerTest
|
||||
"y",
|
||||
"Any",
|
||||
Suggestion.Scope(
|
||||
Suggestion.Position(0, 6),
|
||||
Suggestion.Position(6, 0)
|
||||
Suggestion.Position(2, 6),
|
||||
Suggestion.Position(8, 0)
|
||||
)
|
||||
)
|
||||
)
|
||||
@ -1851,15 +1871,21 @@ class RuntimeServerTest
|
||||
Api.Response(requestId, Api.CreateContextResponse(contextId))
|
||||
)
|
||||
|
||||
val code =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main = IO.println "I'm a file!"
|
||||
|""".stripMargin
|
||||
|
||||
// Create a new file
|
||||
context.writeFile(fooFile, "main = IO.println \"I'm a file!\"")
|
||||
context.writeFile(fooFile, code)
|
||||
|
||||
// Open the new file
|
||||
context.send(
|
||||
Api.Request(
|
||||
Api.OpenFileNotification(
|
||||
fooFile,
|
||||
"main = IO.println \"I'm a file!\"",
|
||||
code,
|
||||
false
|
||||
)
|
||||
)
|
||||
@ -1913,7 +1939,7 @@ class RuntimeServerTest
|
||||
fooFile,
|
||||
Seq(
|
||||
TextEdit(
|
||||
model.Range(model.Position(0, 25), model.Position(0, 29)),
|
||||
model.Range(model.Position(2, 25), model.Position(2, 29)),
|
||||
"modified"
|
||||
)
|
||||
)
|
||||
@ -2022,7 +2048,7 @@ class RuntimeServerTest
|
||||
it should "send suggestion notifications when file is executed" in {
|
||||
val contextId = UUID.randomUUID()
|
||||
val requestId = UUID.randomUUID()
|
||||
val idMain = context.Main.metadata.addItem(7, 47)
|
||||
val idMain = context.Main.metadata.addItem(33, 47)
|
||||
val idMainUpdate =
|
||||
Api.Response(
|
||||
Api.ExpressionValuesComputed(
|
||||
@ -2102,7 +2128,7 @@ class RuntimeServerTest
|
||||
"x",
|
||||
"Any",
|
||||
Suggestion
|
||||
.Scope(Suggestion.Position(1, 6), Suggestion.Position(6, 0))
|
||||
.Scope(Suggestion.Position(3, 6), Suggestion.Position(8, 0))
|
||||
)
|
||||
),
|
||||
Api.SuggestionsDatabaseUpdate.Add(
|
||||
@ -2112,7 +2138,7 @@ class RuntimeServerTest
|
||||
"y",
|
||||
"Any",
|
||||
Suggestion
|
||||
.Scope(Suggestion.Position(1, 6), Suggestion.Position(6, 0))
|
||||
.Scope(Suggestion.Position(3, 6), Suggestion.Position(8, 0))
|
||||
)
|
||||
),
|
||||
Api.SuggestionsDatabaseUpdate.Add(
|
||||
@ -2122,7 +2148,7 @@ class RuntimeServerTest
|
||||
"z",
|
||||
"Any",
|
||||
Suggestion
|
||||
.Scope(Suggestion.Position(1, 6), Suggestion.Position(6, 0))
|
||||
.Scope(Suggestion.Position(3, 6), Suggestion.Position(8, 0))
|
||||
)
|
||||
),
|
||||
Api.SuggestionsDatabaseUpdate.Add(
|
||||
@ -2132,7 +2158,7 @@ class RuntimeServerTest
|
||||
"y",
|
||||
"Any",
|
||||
Suggestion
|
||||
.Scope(Suggestion.Position(7, 17), Suggestion.Position(10, 5))
|
||||
.Scope(Suggestion.Position(9, 17), Suggestion.Position(12, 5))
|
||||
)
|
||||
),
|
||||
Api.SuggestionsDatabaseUpdate.Add(
|
||||
@ -2142,7 +2168,7 @@ class RuntimeServerTest
|
||||
"z",
|
||||
"Any",
|
||||
Suggestion
|
||||
.Scope(Suggestion.Position(7, 17), Suggestion.Position(10, 5))
|
||||
.Scope(Suggestion.Position(9, 17), Suggestion.Position(12, 5))
|
||||
)
|
||||
)
|
||||
)
|
||||
@ -2205,15 +2231,21 @@ class RuntimeServerTest
|
||||
Api.Response(requestId, Api.CreateContextResponse(contextId))
|
||||
)
|
||||
|
||||
val code =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main = IO.println "I'm a file!"
|
||||
|""".stripMargin
|
||||
|
||||
// Create a new file
|
||||
context.writeFile(fooFile, "main = IO.println \"I'm a file!\"")
|
||||
context.writeFile(fooFile, code)
|
||||
|
||||
// Open the new file
|
||||
context.send(
|
||||
Api.Request(
|
||||
Api.OpenFileNotification(
|
||||
fooFile,
|
||||
"main = IO.println \"I'm a file!\"",
|
||||
code,
|
||||
false
|
||||
)
|
||||
)
|
||||
@ -2267,11 +2299,11 @@ class RuntimeServerTest
|
||||
fooFile,
|
||||
Seq(
|
||||
TextEdit(
|
||||
model.Range(model.Position(0, 25), model.Position(0, 29)),
|
||||
model.Range(model.Position(2, 25), model.Position(2, 29)),
|
||||
"modified"
|
||||
),
|
||||
TextEdit(
|
||||
model.Range(model.Position(0, 0), model.Position(0, 0)),
|
||||
model.Range(model.Position(2, 0), model.Position(2, 0)),
|
||||
"Number.lucky = 42\n\n"
|
||||
)
|
||||
)
|
||||
@ -2669,7 +2701,11 @@ class RuntimeServerTest
|
||||
val moduleName = "Test.Main"
|
||||
val metadata = new Metadata
|
||||
|
||||
val code = "main = Number.pi"
|
||||
val code =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main = Number.pi
|
||||
|""".stripMargin
|
||||
val contents = metadata.appendToCode(code)
|
||||
context.writeMain(contents)
|
||||
|
||||
@ -2948,7 +2984,7 @@ class RuntimeServerTest
|
||||
"x",
|
||||
"Any",
|
||||
Suggestion
|
||||
.Scope(Suggestion.Position(1, 6), Suggestion.Position(6, 0))
|
||||
.Scope(Suggestion.Position(3, 6), Suggestion.Position(8, 0))
|
||||
)
|
||||
),
|
||||
Api.SuggestionsDatabaseUpdate.Add(
|
||||
@ -2958,7 +2994,7 @@ class RuntimeServerTest
|
||||
"y",
|
||||
"Any",
|
||||
Suggestion
|
||||
.Scope(Suggestion.Position(1, 6), Suggestion.Position(6, 0))
|
||||
.Scope(Suggestion.Position(3, 6), Suggestion.Position(8, 0))
|
||||
)
|
||||
),
|
||||
Api.SuggestionsDatabaseUpdate.Add(
|
||||
@ -2968,7 +3004,7 @@ class RuntimeServerTest
|
||||
"z",
|
||||
"Any",
|
||||
Suggestion
|
||||
.Scope(Suggestion.Position(1, 6), Suggestion.Position(6, 0))
|
||||
.Scope(Suggestion.Position(3, 6), Suggestion.Position(8, 0))
|
||||
)
|
||||
),
|
||||
Api.SuggestionsDatabaseUpdate.Add(
|
||||
@ -2978,7 +3014,7 @@ class RuntimeServerTest
|
||||
"y",
|
||||
"Any",
|
||||
Suggestion
|
||||
.Scope(Suggestion.Position(7, 17), Suggestion.Position(10, 5))
|
||||
.Scope(Suggestion.Position(9, 17), Suggestion.Position(12, 5))
|
||||
)
|
||||
),
|
||||
Api.SuggestionsDatabaseUpdate.Add(
|
||||
@ -2988,7 +3024,7 @@ class RuntimeServerTest
|
||||
"z",
|
||||
"Any",
|
||||
Suggestion
|
||||
.Scope(Suggestion.Position(7, 17), Suggestion.Position(10, 5))
|
||||
.Scope(Suggestion.Position(9, 17), Suggestion.Position(12, 5))
|
||||
)
|
||||
)
|
||||
)
|
||||
@ -3041,7 +3077,7 @@ class RuntimeServerTest
|
||||
mainFile,
|
||||
Seq(
|
||||
TextEdit(
|
||||
model.Range(model.Position(2, 8), model.Position(2, 9)),
|
||||
model.Range(model.Position(4, 8), model.Position(4, 9)),
|
||||
"5"
|
||||
)
|
||||
)
|
||||
|
@ -15,6 +15,8 @@ class CaseTest extends InterpreterTest {
|
||||
"result in an error if the matched constructor isn't visible" in {
|
||||
val code =
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| x = Cons a Nil
|
||||
| case x of
|
||||
@ -30,6 +32,8 @@ class CaseTest extends InterpreterTest {
|
||||
"result in an error if the wrong number of fields are provided" in {
|
||||
val code =
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| x = Cons a Nil
|
||||
| case x of
|
||||
|
@ -5,7 +5,7 @@ import org.enso.interpreter.node.callable.{ApplicationNode, SequenceLiteralNode}
|
||||
import org.enso.interpreter.node.controlflow.CaseNode
|
||||
import org.enso.interpreter.node.expression.literal.IntegerLiteralNode
|
||||
import org.enso.interpreter.node.scope.{AssignmentNode, ReadLocalVariableNode}
|
||||
import org.enso.interpreter.test.{InterpreterTest, InterpreterContext}
|
||||
import org.enso.interpreter.test.{InterpreterContext, InterpreterTest}
|
||||
import org.enso.polyglot.MethodNames
|
||||
|
||||
class CodeLocationsTest extends InterpreterTest {
|
||||
@ -28,8 +28,8 @@ class CodeLocationsTest extends InterpreterTest {
|
||||
}
|
||||
}
|
||||
|
||||
override def specify(
|
||||
implicit interpreterContext: InterpreterContext
|
||||
override def specify(implicit
|
||||
interpreterContext: InterpreterContext
|
||||
): Unit = {
|
||||
|
||||
"be correct in simple arithmetic expressions" in
|
||||
@ -53,9 +53,13 @@ class CodeLocationsTest extends InterpreterTest {
|
||||
|
||||
"be correct in applications and method calls" in
|
||||
withLocationsInstrumenter { instrumenter =>
|
||||
val code = "main = (2-2 == 0).if_then_else (Cons 5 6) 0"
|
||||
instrumenter.assertNodeExists(7, 36, classOf[ApplicationNode])
|
||||
instrumenter.assertNodeExists(32, 8, classOf[ApplicationNode])
|
||||
val code =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main = (2-2 == 0).if_then_else (Cons 5 6) 0
|
||||
|""".stripMargin
|
||||
instrumenter.assertNodeExists(33, 36, classOf[ApplicationNode])
|
||||
instrumenter.assertNodeExists(58, 8, classOf[ApplicationNode])
|
||||
eval(code)
|
||||
()
|
||||
}
|
||||
@ -64,16 +68,18 @@ class CodeLocationsTest extends InterpreterTest {
|
||||
withLocationsInstrumenter { instrumenter =>
|
||||
val code =
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| x = 2 + 2 * 2
|
||||
| y = x * x
|
||||
| IO.println y
|
||||
|""".stripMargin
|
||||
instrumenter.assertNodeExists(12, 13, classOf[AssignmentNode])
|
||||
instrumenter.assertNodeExists(30, 9, classOf[AssignmentNode])
|
||||
instrumenter.assertNodeExists(34, 1, classOf[ReadLocalVariableNode])
|
||||
instrumenter.assertNodeExists(38, 1, classOf[ReadLocalVariableNode])
|
||||
instrumenter.assertNodeExists(55, 1, classOf[ReadLocalVariableNode])
|
||||
instrumenter.assertNodeExists(38, 13, classOf[AssignmentNode])
|
||||
instrumenter.assertNodeExists(56, 9, classOf[AssignmentNode])
|
||||
instrumenter.assertNodeExists(60, 1, classOf[ReadLocalVariableNode])
|
||||
instrumenter.assertNodeExists(64, 1, classOf[ReadLocalVariableNode])
|
||||
instrumenter.assertNodeExists(81, 1, classOf[ReadLocalVariableNode])
|
||||
eval(code)
|
||||
()
|
||||
}
|
||||
@ -82,6 +88,8 @@ class CodeLocationsTest extends InterpreterTest {
|
||||
withLocationsInstrumenter { instrumenter =>
|
||||
val code =
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|Unit.method =
|
||||
| foo = a -> b ->
|
||||
| IO.println a
|
||||
@ -92,10 +100,10 @@ class CodeLocationsTest extends InterpreterTest {
|
||||
|main = Unit.method
|
||||
|""".stripMargin
|
||||
|
||||
instrumenter.assertNodeExists(80, 5, classOf[ApplicationNode])
|
||||
instrumenter.assertNodeExists(98, 1, classOf[ReadLocalVariableNode])
|
||||
instrumenter.assertNodeExists(94, 7, classOf[ApplicationNode])
|
||||
instrumenter.assertNodeExists(106, 9, classOf[ApplicationNode])
|
||||
instrumenter.assertNodeExists(106, 5, classOf[ApplicationNode])
|
||||
instrumenter.assertNodeExists(124, 1, classOf[ReadLocalVariableNode])
|
||||
instrumenter.assertNodeExists(120, 7, classOf[ApplicationNode])
|
||||
instrumenter.assertNodeExists(132, 9, classOf[ApplicationNode])
|
||||
eval(code)
|
||||
()
|
||||
}
|
||||
@ -104,6 +112,8 @@ class CodeLocationsTest extends InterpreterTest {
|
||||
withLocationsInstrumenter { instrumenter =>
|
||||
val code =
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| x = Cons 1 2
|
||||
| y = Nil
|
||||
@ -119,10 +129,10 @@ class CodeLocationsTest extends InterpreterTest {
|
||||
|
|
||||
| foo x + foo y
|
||||
|""".stripMargin
|
||||
instrumenter.assertNodeExists(80, 109, classOf[CaseNode])
|
||||
instrumenter.assertNodeExists(126, 7, classOf[ApplicationNode])
|
||||
instrumenter.assertNodeExists(146, 9, classOf[AssignmentNode])
|
||||
instrumenter.assertNodeExists(183, 5, classOf[ApplicationNode])
|
||||
instrumenter.assertNodeExists(106, 109, classOf[CaseNode])
|
||||
instrumenter.assertNodeExists(152, 7, classOf[ApplicationNode])
|
||||
instrumenter.assertNodeExists(172, 9, classOf[AssignmentNode])
|
||||
instrumenter.assertNodeExists(209, 5, classOf[ApplicationNode])
|
||||
eval(code)
|
||||
()
|
||||
}
|
||||
@ -224,8 +234,12 @@ class CodeLocationsTest extends InterpreterTest {
|
||||
val mod = interpreterContext.executionContext.evalModule(code, "Test")
|
||||
val tpe = mod.getAssociatedConstructor
|
||||
val method = mod.getMethod(tpe, "foo")
|
||||
method.value.invokeMember(MethodNames.Function.GET_SOURCE_START) shouldEqual 1
|
||||
method.value.invokeMember(MethodNames.Function.GET_SOURCE_LENGTH) shouldEqual 24
|
||||
method.value.invokeMember(
|
||||
MethodNames.Function.GET_SOURCE_START
|
||||
) shouldEqual 1
|
||||
method.value.invokeMember(
|
||||
MethodNames.Function.GET_SOURCE_LENGTH
|
||||
) shouldEqual 24
|
||||
|
||||
instrumenter.assertNodeExists(16, 9, classOf[ApplicationNode])
|
||||
|
||||
@ -268,6 +282,8 @@ class CodeLocationsTest extends InterpreterTest {
|
||||
instrumenter =>
|
||||
val code =
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|type MyAtom
|
||||
|
|
||||
|main =
|
||||
@ -277,10 +293,10 @@ class CodeLocationsTest extends InterpreterTest {
|
||||
| f (Cons (Cons MyAtom Nil) Nil)
|
||||
|""".stripMargin
|
||||
|
||||
instrumenter.assertNodeExists(29, 67, classOf[CaseNode])
|
||||
instrumenter.assertNodeExists(34, 1, classOf[ReadLocalVariableNode])
|
||||
instrumenter.assertNodeExists(77, 3, classOf[IntegerLiteralNode])
|
||||
instrumenter.assertNodeExists(47, 33, classOf[CreateFunctionNode])
|
||||
instrumenter.assertNodeExists(55, 67, classOf[CaseNode])
|
||||
instrumenter.assertNodeExists(60, 1, classOf[ReadLocalVariableNode])
|
||||
instrumenter.assertNodeExists(103, 3, classOf[IntegerLiteralNode])
|
||||
instrumenter.assertNodeExists(73, 33, classOf[CreateFunctionNode])
|
||||
|
||||
eval(code) shouldEqual 100
|
||||
}
|
||||
|
@ -10,7 +10,8 @@ class CompileDiagnosticsTest extends InterpreterTest {
|
||||
): Unit = {
|
||||
"surface ast-processing errors in the language" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| x = Panic.recover ()
|
||||
| x.catch err->
|
||||
@ -22,7 +23,8 @@ class CompileDiagnosticsTest extends InterpreterTest {
|
||||
|
||||
"surface parsing errors in the language" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| x = Panic.recover @
|
||||
| x.catch to_text
|
||||
@ -32,7 +34,8 @@ class CompileDiagnosticsTest extends InterpreterTest {
|
||||
|
||||
"surface redefinition errors in the language" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|foo =
|
||||
| x = 1
|
||||
| x = 2
|
||||
|
@ -68,7 +68,8 @@ class ComplexTypeDefinitionSugarTest extends InterpreterTest {
|
||||
|
||||
"work with methods appearing to be suspended blocks" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|type Foo
|
||||
| type Bar
|
||||
| x =
|
||||
|
@ -15,9 +15,10 @@ class ConstructorsTest extends InterpreterTest {
|
||||
): Unit = {
|
||||
"dispatch to the proper match branch" in {
|
||||
val patternMatchingCode =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| x = Builtins.Cons 1 Nil
|
||||
| x = Cons 1 Nil
|
||||
| case x of
|
||||
| Cons h t -> h
|
||||
| Nil -> 0
|
||||
@ -27,7 +28,8 @@ class ConstructorsTest extends InterpreterTest {
|
||||
|
||||
"work with recursion" in {
|
||||
val testCode =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| genList = i -> if i == 0 then Nil else Cons i (genList (i - 1))
|
||||
| sumList = list -> case list of
|
||||
@ -41,7 +43,8 @@ class ConstructorsTest extends InterpreterTest {
|
||||
|
||||
"behave correctly in non-tail positions" in {
|
||||
val testCode =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| add = x -> y -> x + y
|
||||
| testCons = Cons 1 2
|
||||
@ -56,7 +59,8 @@ class ConstructorsTest extends InterpreterTest {
|
||||
|
||||
"accept a catch-all fallback clause" in {
|
||||
val testCode =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| nil = Nil
|
||||
| case nil of
|
||||
@ -68,7 +72,8 @@ class ConstructorsTest extends InterpreterTest {
|
||||
|
||||
"throw an exception when match fails" in {
|
||||
val testCode =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| nil = Nil
|
||||
| case nil of
|
||||
@ -80,7 +85,8 @@ class ConstructorsTest extends InterpreterTest {
|
||||
|
||||
"be usable in code, with arbitrary definition order" in {
|
||||
val testCode =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|type Cons2 a b
|
||||
|
|
||||
|Unit.genList = i -> if i == 0 then Nil2 else Cons2 i (genList Unit (i - 1))
|
||||
|
@ -66,7 +66,8 @@ class CurryingTest extends InterpreterTest {
|
||||
|
||||
"allow default arguments to be suspended in method call syntax" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.fn = w -> x -> (y = 10) -> (z = 20) -> w + x + y + z
|
||||
|
|
||||
|main =
|
||||
|
@ -15,7 +15,8 @@ class ErrorsTest extends InterpreterTest {
|
||||
|
||||
"be thrown and stop evaluation" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|type Foo
|
||||
|type Bar
|
||||
|type Baz
|
||||
@ -34,7 +35,8 @@ class ErrorsTest extends InterpreterTest {
|
||||
|
||||
"be recoverable and transformed into errors" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|type MyError
|
||||
|
|
||||
|main =
|
||||
@ -49,7 +51,8 @@ class ErrorsTest extends InterpreterTest {
|
||||
|
||||
"propagate through pattern matches" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|type MyError
|
||||
|
|
||||
|main =
|
||||
@ -66,7 +69,8 @@ class ErrorsTest extends InterpreterTest {
|
||||
|
||||
"propagate through specialized pattern matches" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|type MyError
|
||||
|
|
||||
|main =
|
||||
@ -84,7 +88,8 @@ class ErrorsTest extends InterpreterTest {
|
||||
|
||||
"be catchable by a user-provided special handling function" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| intError = Error.throw 1
|
||||
| intError.catch (x -> x + 3)
|
||||
@ -94,7 +99,8 @@ class ErrorsTest extends InterpreterTest {
|
||||
|
||||
"accept a constructor handler in catch function" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|type MyCons err
|
||||
|
|
||||
|main =
|
||||
@ -107,7 +113,8 @@ class ErrorsTest extends InterpreterTest {
|
||||
|
||||
"accept a method handle in catch function" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|type MyRecovered x
|
||||
|type MyError x
|
||||
|
|
||||
|
@ -11,7 +11,8 @@ class EvalTest extends InterpreterTest {
|
||||
|
||||
"evaluate a string expression" in {
|
||||
val code =
|
||||
s"""
|
||||
s"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| Debug.eval $rawTQ
|
||||
| IO.println "foo"
|
||||
@ -22,7 +23,8 @@ class EvalTest extends InterpreterTest {
|
||||
|
||||
"have access to the caller scope" in {
|
||||
val code =
|
||||
s"""
|
||||
s"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| x = "Hello World!"
|
||||
| Debug.eval $rawTQ
|
||||
@ -34,7 +36,8 @@ class EvalTest extends InterpreterTest {
|
||||
|
||||
"have access to the caller module scope" in {
|
||||
val code =
|
||||
s"""
|
||||
s"""from Builtins import all
|
||||
|
|
||||
|type MyType x
|
||||
|
|
||||
|main =
|
||||
@ -48,7 +51,8 @@ class EvalTest extends InterpreterTest {
|
||||
|
||||
"return a value usable in the caller scope" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| x = 1
|
||||
| y = 2
|
||||
@ -61,7 +65,8 @@ class EvalTest extends InterpreterTest {
|
||||
|
||||
"work in a recursive setting" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| fn = sumTo ->
|
||||
| summator = acc -> current ->
|
||||
@ -74,7 +79,8 @@ class EvalTest extends InterpreterTest {
|
||||
|
||||
"work inside a thunk passed to another function" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| fn = sumTo ->
|
||||
| summator = acc -> current ->
|
||||
|
@ -41,10 +41,14 @@ class ExpressionIdTest extends InterpreterTest {
|
||||
|
||||
"be correct in applications and method calls" in
|
||||
withIdsInstrumenter { instrumenter =>
|
||||
val code = "main = (2-2 == 0).if_then_else (Cons 5 6) 0"
|
||||
val code =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main = (2-2 == 0).if_then_else (Cons 5 6) 0
|
||||
|""".stripMargin
|
||||
val meta = new Metadata
|
||||
val id1 = meta.addItem(7, 36)
|
||||
val id2 = meta.addItem(32, 8)
|
||||
val id1 = meta.addItem(33, 36)
|
||||
val id2 = meta.addItem(58, 8)
|
||||
|
||||
instrumenter.assertNodeExists(id1, "Cons 5 6")
|
||||
instrumenter.assertNodeExists(id2, "Cons 5 6")
|
||||
@ -55,6 +59,8 @@ class ExpressionIdTest extends InterpreterTest {
|
||||
withIdsInstrumenter { instrumenter =>
|
||||
val code =
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|Unit.method =
|
||||
| foo = a -> b ->
|
||||
| IO.println a
|
||||
@ -65,10 +71,10 @@ class ExpressionIdTest extends InterpreterTest {
|
||||
|main = Unit.method
|
||||
|""".stripMargin
|
||||
val meta = new Metadata
|
||||
val id1 = meta.addItem(80, 5)
|
||||
val id2 = meta.addItem(98, 1)
|
||||
val id3 = meta.addItem(94, 7)
|
||||
val id4 = meta.addItem(107, 9)
|
||||
val id1 = meta.addItem(106, 5)
|
||||
val id2 = meta.addItem(124, 1)
|
||||
val id3 = meta.addItem(120, 7)
|
||||
val id4 = meta.addItem(133, 9)
|
||||
|
||||
instrumenter.assertNodeExists(id1, "30")
|
||||
instrumenter.assertNodeExists(id2, "10")
|
||||
@ -81,6 +87,8 @@ class ExpressionIdTest extends InterpreterTest {
|
||||
withIdsInstrumenter { instrumenter =>
|
||||
val code =
|
||||
"""
|
||||
|from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| x = Cons 1 2
|
||||
| y = Nil
|
||||
@ -97,10 +105,10 @@ class ExpressionIdTest extends InterpreterTest {
|
||||
| foo x + foo y
|
||||
|""".stripMargin
|
||||
val meta = new Metadata
|
||||
val id1 = meta.addItem(80, 109)
|
||||
val id2 = meta.addItem(126, 7)
|
||||
val id3 = meta.addItem(146, 9)
|
||||
val id4 = meta.addItem(183, 5)
|
||||
val id1 = meta.addItem(106, 109)
|
||||
val id2 = meta.addItem(152, 7)
|
||||
val id3 = meta.addItem(172, 9)
|
||||
val id4 = meta.addItem(209, 5)
|
||||
|
||||
instrumenter.assertNodeExists(id1, "9")
|
||||
instrumenter.assertNodeExists(id2, "3")
|
||||
|
@ -22,7 +22,8 @@ class FunctionSugarTest extends InterpreterTest {
|
||||
|
||||
"work for methods" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.foo a b = a * b - a
|
||||
|
|
||||
|main = Unit.foo 2 3
|
||||
|
@ -12,7 +12,8 @@ class GlobalScopeTest extends InterpreterTest {
|
||||
|
||||
"use values from the global scope in their bodies" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.a = 10
|
||||
|Unit.addTen = b -> a Unit + b
|
||||
|
|
||||
@ -24,7 +25,8 @@ class GlobalScopeTest extends InterpreterTest {
|
||||
|
||||
"be able to call other functions in scope" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.adder = a -> b -> a + b
|
||||
|
|
||||
|main =
|
||||
@ -40,7 +42,8 @@ class GlobalScopeTest extends InterpreterTest {
|
||||
|
||||
"be able to be passed as values when in scope" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.adder = a -> b -> a + b
|
||||
|
|
||||
|Unit.binaryFn = a -> b -> function ->
|
||||
@ -55,7 +58,8 @@ class GlobalScopeTest extends InterpreterTest {
|
||||
|
||||
"be able to mutually recurse in the global scope" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.decrementCall = number ->
|
||||
| res = number - 1
|
||||
| Unit.fn1 res
|
||||
@ -71,7 +75,8 @@ class GlobalScopeTest extends InterpreterTest {
|
||||
|
||||
"be suspended within blocks" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.a = 10/0
|
||||
|
|
||||
|Unit.b = Unit.a
|
||||
|
@ -52,7 +52,8 @@ class GroupingTest extends InterpreterTest {
|
||||
|
||||
"work with pattern matches" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| fn = x -> case x of
|
||||
| (Cons h t) -> h + fn t
|
||||
|
@ -44,7 +44,8 @@ class InteropTest extends InterpreterTest {
|
||||
|
||||
"work with oversaturated calls on unresolved methods returned from functions" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Any.method = this
|
||||
|
|
||||
|main = x -> method
|
||||
@ -56,7 +57,8 @@ class InteropTest extends InterpreterTest {
|
||||
|
||||
"work with unresolved symbols" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Number.add x = x + this
|
||||
|Text.add x = this + x
|
||||
|
|
||||
|
@ -56,7 +56,8 @@ class LambdaChainingTest extends InterpreterTest {
|
||||
|
||||
"work properly with lazy parameters" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| fn = a -> ~b -> ~c ->
|
||||
| b
|
||||
|
@ -50,7 +50,8 @@ class LambdaShorthandArgsTest extends InterpreterTest {
|
||||
|
||||
"work with mixfix functions" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Number.if_then_else = ~t -> ~f -> if this == 0 then t else f
|
||||
|
|
||||
|main =
|
||||
@ -65,7 +66,8 @@ class LambdaShorthandArgsTest extends InterpreterTest {
|
||||
|
||||
"work with case expressions" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| f = case _ of
|
||||
| Cons a b -> 10
|
||||
@ -139,7 +141,8 @@ class LambdaShorthandArgsTest extends InterpreterTest {
|
||||
|
||||
"work properly with vector literals" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| fun = [1, _, (1 + 2), _]
|
||||
| vec = fun 2 4
|
||||
|
@ -75,7 +75,8 @@ class LambdaTest extends InterpreterTest {
|
||||
|
||||
"be able to return atoms that are evaluated with oversaturated args" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| f = x -> Cons
|
||||
| myCons = f 1 2 3
|
||||
@ -88,7 +89,8 @@ class LambdaTest extends InterpreterTest {
|
||||
|
||||
"support the use of oversaturated args in methods" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.myMethod = 1
|
||||
|
|
||||
|main =
|
||||
@ -115,7 +117,8 @@ class LambdaTest extends InterpreterTest {
|
||||
|
||||
"call fully saturated returned lambdas" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| fn = a -> b ->
|
||||
| IO.println (a + b)
|
||||
@ -131,7 +134,8 @@ class LambdaTest extends InterpreterTest {
|
||||
|
||||
"call fully saturated lambdas returned with TCO" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Number.if_then_else = ~t -> ~f -> if this == 0 then t else f
|
||||
|
|
||||
|main =
|
||||
|
@ -23,7 +23,8 @@ class MethodsTest extends InterpreterTest {
|
||||
}
|
||||
"execute `this` argument once" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.foo = 0
|
||||
|
|
||||
|main = (IO.println "foo").foo
|
||||
@ -85,7 +86,8 @@ class MethodsTest extends InterpreterTest {
|
||||
|
||||
"be definable as blocks without arguments" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Any.method =
|
||||
| x = this * this
|
||||
| y = x * 2
|
||||
@ -98,7 +100,8 @@ class MethodsTest extends InterpreterTest {
|
||||
|
||||
"be dispatched to the proper constructor" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Nil.sum = acc -> acc
|
||||
|Cons.sum = acc -> case this of
|
||||
| Cons h t -> sum t (h + acc)
|
||||
@ -111,7 +114,8 @@ class MethodsTest extends InterpreterTest {
|
||||
|
||||
"allow passing the call target by-name" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.testMethod = x -> y -> z -> x + y + z
|
||||
|main = testMethod x=1 y=2 this=Unit z=3
|
||||
|""".stripMargin
|
||||
@ -128,7 +132,8 @@ class MethodsTest extends InterpreterTest {
|
||||
|
||||
"be callable for any type when defined on Any" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|type Foo
|
||||
|type Bar
|
||||
|type Baz
|
||||
@ -153,7 +158,8 @@ class MethodsTest extends InterpreterTest {
|
||||
|
||||
"work as expected when defined across different constructors" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Nil.sum = 0
|
||||
|Cons.sum = case this of
|
||||
| Cons h t -> h + sum t
|
||||
|
@ -15,7 +15,8 @@ class NamedArgumentsTest extends InterpreterTest {
|
||||
|
||||
"be used in function bodies" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.a = 10
|
||||
|Unit.addTen = b -> a Unit + b
|
||||
|
|
||||
@ -27,7 +28,8 @@ class NamedArgumentsTest extends InterpreterTest {
|
||||
|
||||
"be passed when given out of order" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.subtract = a -> b -> a - b
|
||||
|
|
||||
|main = subtract Unit (b = 10) (a = 5)
|
||||
@ -51,7 +53,8 @@ class NamedArgumentsTest extends InterpreterTest {
|
||||
|
||||
"be definable" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.addNum = a -> (num = 10) -> a + num
|
||||
|
|
||||
|main = addNum Unit 5
|
||||
@ -62,7 +65,8 @@ class NamedArgumentsTest extends InterpreterTest {
|
||||
|
||||
"be able to default to complex expressions" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.add = a -> b -> a + b
|
||||
|Unit.doThing = a -> (b = add Unit 1 2) -> a + b
|
||||
|
|
||||
@ -87,7 +91,8 @@ class NamedArgumentsTest extends InterpreterTest {
|
||||
|
||||
"be used in functions when no arguments are supplied" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.addTogether = (a = 5) -> (b = 6) -> a + b
|
||||
|
|
||||
|main = addTogether Unit
|
||||
@ -98,7 +103,8 @@ class NamedArgumentsTest extends InterpreterTest {
|
||||
|
||||
"be overridable by name" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.addNum = a -> (num = 10) -> a + num
|
||||
|
|
||||
|main = addNum Unit 1 (num = 1)
|
||||
@ -109,7 +115,8 @@ class NamedArgumentsTest extends InterpreterTest {
|
||||
|
||||
"overridable by position" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.addNum = a -> (num = 10) -> a + num
|
||||
|
|
||||
|main = addNum Unit 1 2
|
||||
@ -120,7 +127,8 @@ class NamedArgumentsTest extends InterpreterTest {
|
||||
|
||||
"work in a recursive context" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.summer = sumTo ->
|
||||
| summator = (acc = 0) -> current ->
|
||||
| if current == 0 then acc else summator (current = current - 1) (acc = acc + current)
|
||||
@ -150,7 +158,8 @@ class NamedArgumentsTest extends InterpreterTest {
|
||||
|
||||
"be applied in a sequence compatible with Eta-expansions" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.foo = a -> b -> c -> a -> a
|
||||
|main = foo Unit 20 (a = 10) 0 0
|
||||
|""".stripMargin
|
||||
@ -160,7 +169,8 @@ class NamedArgumentsTest extends InterpreterTest {
|
||||
|
||||
"be able to depend on prior arguments" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.doubleOrAdd = a -> (b = a) -> a + b
|
||||
|
|
||||
|main = doubleOrAdd Unit 5
|
||||
@ -171,7 +181,8 @@ class NamedArgumentsTest extends InterpreterTest {
|
||||
|
||||
"not be able to depend on later arguments" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.badArgFn = a -> (b = c) -> (c = a) -> a + b + c
|
||||
|
|
||||
|main = badArgFn Unit 3
|
||||
@ -232,7 +243,8 @@ class NamedArgumentsTest extends InterpreterTest {
|
||||
|
||||
"work with constructors" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|type Cons2 head (rest = Nil2)
|
||||
|type Nil2
|
||||
|
|
||||
@ -248,7 +260,8 @@ class NamedArgumentsTest extends InterpreterTest {
|
||||
|
||||
"be assignable from Vectors" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| lam = (x=[1,3]) -> y -> y + Polyglot.get_array_element x 0 + Polyglot.get_array_element x 1
|
||||
| lam y=10
|
||||
|
@ -20,7 +20,8 @@ class OverloadsResolutionErrorTest extends InterpreterTest {
|
||||
|
||||
"result in an error at runtime for methods" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Unit.foo = 10
|
||||
|Unit.foo = 20
|
||||
|""".stripMargin.linesIterator.mkString("\n")
|
||||
@ -33,7 +34,7 @@ class OverloadsResolutionErrorTest extends InterpreterTest {
|
||||
.filterNot(_.contains("Compiler encountered"))
|
||||
.filterNot(_.contains("In module"))
|
||||
.toSet shouldEqual Set(
|
||||
"Test[3:1-3:13]: Method overloads are not supported: Unit.foo is defined multiple times in this module."
|
||||
"Test[4:1-4:13]: Method overloads are not supported: Unit.foo is defined multiple times in this module."
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,8 @@ class PatternMatchTest extends InterpreterTest {
|
||||
|
||||
"work for simple patterns" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| f = case _ of
|
||||
| Builtins.Cons a _ -> a
|
||||
@ -30,7 +31,8 @@ class PatternMatchTest extends InterpreterTest {
|
||||
|
||||
"work for anonymous catch-all patterns" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|type MyAtom a
|
||||
|
|
||||
|main =
|
||||
@ -75,7 +77,8 @@ class PatternMatchTest extends InterpreterTest {
|
||||
|
||||
"work for level one nested patterns" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|type MyAtom
|
||||
|
|
||||
|main =
|
||||
@ -91,7 +94,8 @@ class PatternMatchTest extends InterpreterTest {
|
||||
|
||||
"work for deeply nested patterns" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|type MyAtom
|
||||
|
|
||||
|main =
|
||||
@ -114,7 +118,8 @@ class PatternMatchTest extends InterpreterTest {
|
||||
|
||||
"correctly result in errors for incomplete matches" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|type MyAtom
|
||||
|
|
||||
|main =
|
||||
@ -130,7 +135,8 @@ class PatternMatchTest extends InterpreterTest {
|
||||
|
||||
"work for pattern matches in pattern matches" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|type MyAtom a
|
||||
|type One a
|
||||
|type Two a
|
||||
|
@ -11,7 +11,8 @@ class PolyglotTest extends InterpreterTest {
|
||||
|
||||
"allow calling methods on static objects" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| class = Java.lookup_class "org.enso.example.TestClass"
|
||||
| method = Polyglot.get_member class "add"
|
||||
@ -23,7 +24,8 @@ class PolyglotTest extends InterpreterTest {
|
||||
|
||||
"allow instantiating objects and calling methods on them" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| class = Java.lookup_class "org.enso.example.TestClass"
|
||||
| instance = Polyglot.new class [x -> x * 2]
|
||||
@ -34,7 +36,8 @@ class PolyglotTest extends InterpreterTest {
|
||||
|
||||
"allow listing available members of an object" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| class = Java.lookup_class "org.enso.example.TestClass"
|
||||
| instance = Polyglot.new class []
|
||||
|
@ -10,7 +10,8 @@ class SequenceLiteralsTest extends InterpreterTest {
|
||||
): Unit = {
|
||||
"create collections, with fields accessible through the Polyglot API" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|type My x y
|
||||
|
|
||||
|main =
|
||||
|
@ -11,7 +11,8 @@ class StateTest extends InterpreterTest {
|
||||
|
||||
"be accessible from functions" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|stateful =
|
||||
| State.put Number 10
|
||||
| x = State.get Number
|
||||
@ -26,7 +27,8 @@ class StateTest extends InterpreterTest {
|
||||
|
||||
"be implicitly threaded through function executions" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|inc_state =
|
||||
| x = State.get Number
|
||||
| State.put Number x+1
|
||||
@ -47,7 +49,8 @@ class StateTest extends InterpreterTest {
|
||||
|
||||
"work well with recursive code" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| stateSum = n ->
|
||||
| acc = State.get Number
|
||||
@ -61,7 +64,8 @@ class StateTest extends InterpreterTest {
|
||||
|
||||
"work with pattern matches" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|run =
|
||||
| matcher = x -> case x of
|
||||
| Unit ->
|
||||
@ -86,7 +90,8 @@ class StateTest extends InterpreterTest {
|
||||
|
||||
"undo changes on Panics" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|panicker =
|
||||
| State.put Number 400
|
||||
| Panic.throw Unit
|
||||
@ -103,7 +108,8 @@ class StateTest extends InterpreterTest {
|
||||
|
||||
"localize properly with State.run when 1 key used" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|inner = State.put Number 0
|
||||
|
|
||||
|outer =
|
||||
@ -118,7 +124,8 @@ class StateTest extends InterpreterTest {
|
||||
|
||||
"localize properly with State.run when 2 states used" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|type S1
|
||||
|type S2
|
||||
|
|
||||
@ -139,7 +146,8 @@ class StateTest extends InterpreterTest {
|
||||
|
||||
"localize properly with State.run when multiple states used" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|type S1
|
||||
|type S2
|
||||
|type S3
|
||||
|
@ -23,7 +23,8 @@ class SuspendedArgumentsTest extends InterpreterTest {
|
||||
|
||||
"not get executed upfront" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| foo = i -> ~x -> ~y -> if i == 0 then x else y
|
||||
| foo 1 (IO.println 1) (IO.println 2)
|
||||
@ -57,7 +58,8 @@ class SuspendedArgumentsTest extends InterpreterTest {
|
||||
|
||||
"work properly with method dispatch" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|type Foo
|
||||
|type Bar
|
||||
|
|
||||
@ -75,7 +77,8 @@ class SuspendedArgumentsTest extends InterpreterTest {
|
||||
|
||||
"work properly with oversaturated arguments" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| ifTest = c -> ~ifT -> ~ifF -> if c == 0 then ifT else ifF
|
||||
| foo = c -> ifTest c
|
||||
@ -89,7 +92,8 @@ class SuspendedArgumentsTest extends InterpreterTest {
|
||||
|
||||
"work properly with defaulted arguments" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main = a -> (~b = Panic.throw 1) -> a
|
||||
|""".stripMargin
|
||||
eval(code).call(1) shouldEqual 1
|
||||
@ -107,7 +111,8 @@ class SuspendedArgumentsTest extends InterpreterTest {
|
||||
|
||||
"work with vector literals" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| foo = ~x -> [x]
|
||||
| block =
|
||||
|
@ -18,7 +18,9 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
|
||||
|
||||
"return success exit code" in {
|
||||
val code =
|
||||
"""main =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| result = System.create_process "echo" [] "" False False False
|
||||
| result.exit_code
|
||||
|""".stripMargin
|
||||
@ -29,7 +31,9 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
|
||||
|
||||
"return error when creating nonexistent command" in {
|
||||
val code =
|
||||
"""main = System.create_process "nonexistentcommandxyz" [] "" False False False"""
|
||||
"""from Builtins import all
|
||||
|main = System.create_process "nonexistentcommandxyz" [] "" False False False
|
||||
|""".stripMargin
|
||||
|
||||
val error = the[InterpreterException] thrownBy eval(code)
|
||||
error.getMessage should include("nonexistentcommandxyz")
|
||||
@ -39,7 +43,9 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
|
||||
|
||||
"return error exit code" in {
|
||||
val code =
|
||||
"""main =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| result = System.create_process "ls" ["--gibberish"] "" False False False
|
||||
| result.exit_code
|
||||
|""".stripMargin
|
||||
@ -51,7 +57,9 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
|
||||
|
||||
"redirect stdin chars (Unix)" taggedAs OsUnix in {
|
||||
val code =
|
||||
"""main =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| result = System.create_process "bash" ["-c", "read line; echo $line"] "" True True True
|
||||
| result.exit_code
|
||||
|""".stripMargin
|
||||
@ -64,7 +72,9 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
|
||||
|
||||
"redirect stdin chars (Windows)" taggedAs OsWindows in {
|
||||
val code =
|
||||
"""main =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| result = System.create_process "PowerShell" ["-Command", "[System.Console]::ReadLine()"] "" True True True
|
||||
| result.exit_code
|
||||
|""".stripMargin
|
||||
@ -78,7 +88,9 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
|
||||
"redirect stdin bytes (Unix)" taggedAs OsUnix in {
|
||||
val input = Random.nextBytes(Byte.MaxValue)
|
||||
val code =
|
||||
"""main =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| result = System.create_process "bash" ["-c", "wc -c"] "" True True True
|
||||
| result.exit_code
|
||||
|""".stripMargin
|
||||
@ -91,7 +103,9 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
|
||||
|
||||
"redirect stdin unused" in {
|
||||
val code =
|
||||
"""main =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| result = System.create_process "echo" ["42"] "" True True True
|
||||
| result.exit_code
|
||||
|""".stripMargin
|
||||
@ -104,7 +118,9 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
|
||||
|
||||
"redirect stdin empty" in {
|
||||
val code =
|
||||
"""main =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| result = System.create_process "echo" ["9"] "" True True True
|
||||
| result.exit_code
|
||||
|""".stripMargin
|
||||
@ -116,7 +132,9 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
|
||||
|
||||
"provide stdin string (Unix)" taggedAs OsUnix in {
|
||||
val code =
|
||||
"""main =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| result = System.create_process "bash" ["-c", "read line; printf $line"] "hello" False False False
|
||||
| result.stdout
|
||||
|""".stripMargin
|
||||
@ -128,7 +146,9 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
|
||||
|
||||
"provide stdin string (Windows)" taggedAs OsWindows in {
|
||||
val code =
|
||||
"""main =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| result = System.create_process "PowerShell" ["-Command", "[System.Console]::ReadLine()"] "hello" False False False
|
||||
| result.stdout
|
||||
|""".stripMargin
|
||||
@ -140,7 +160,9 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
|
||||
|
||||
"redirect stdout chars" in {
|
||||
val code =
|
||||
"""main =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| result = System.create_process "echo" ["foobar"] "" False True True
|
||||
| result.exit_code
|
||||
|""".stripMargin
|
||||
@ -152,7 +174,9 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
|
||||
|
||||
"redirect stdout binary (Unix)" taggedAs OsUnix in {
|
||||
val code =
|
||||
"""main =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| result = System.create_process "bash" ["-c", "printf '%b' '\\x01\\x0F\\x10'"] "" False True True
|
||||
| result.exit_code
|
||||
|""".stripMargin
|
||||
@ -164,7 +188,9 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
|
||||
|
||||
"return stdout string" in {
|
||||
val code =
|
||||
"""main =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| result = System.create_process "echo" ["foobar"] "" False False False
|
||||
| result.stdout
|
||||
|""".stripMargin
|
||||
@ -176,7 +202,9 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
|
||||
|
||||
"redirect stderr chars (Unix)" taggedAs OsUnix in {
|
||||
val code =
|
||||
"""main =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| result = System.create_process "bash" ["-c", "printf err 1>&2"] "" False True True
|
||||
| result.exit_code
|
||||
|""".stripMargin
|
||||
@ -188,7 +216,9 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
|
||||
|
||||
"redirect stderr chars (Windows)" taggedAs OsWindows in {
|
||||
val code =
|
||||
"""main =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| result = System.create_process "PowerShell" ["-Command", "[System.Console]::Error.WriteLine('err')"] "" False True True
|
||||
| result.exit_code
|
||||
|""".stripMargin
|
||||
@ -200,7 +230,9 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
|
||||
|
||||
"redirect stderr binary (Unix)" taggedAs OsUnix in {
|
||||
val code =
|
||||
"""main =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| result = System.create_process "bash" ["-c", "printf '%b' '\\xCA\\xFE\\xBA\\xBE' 1>&2"] "" False True True
|
||||
| result.exit_code
|
||||
|""".stripMargin
|
||||
@ -212,7 +244,9 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
|
||||
|
||||
"return stderr string (Unix)" taggedAs OsUnix in {
|
||||
val code =
|
||||
"""main =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| result = System.create_process "bash" ["-c", "printf err 1>&2"] "" False False False
|
||||
| result.stderr
|
||||
|""".stripMargin
|
||||
@ -224,7 +258,9 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
|
||||
|
||||
"return stderr string (Windows)" taggedAs OsWindows in {
|
||||
val code =
|
||||
"""main =
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| result = System.create_process "PowerShell" ["-Command", "[System.Console]::Error.WriteLine('err')"] "" False False False
|
||||
| result.stderr
|
||||
|""".stripMargin
|
||||
|
@ -11,7 +11,8 @@ class TextTest extends InterpreterTest {
|
||||
|
||||
"support text creation with single-line literals" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main = IO.println "hello world!"
|
||||
|""".stripMargin
|
||||
|
||||
@ -21,7 +22,8 @@ class TextTest extends InterpreterTest {
|
||||
|
||||
"support text concatenation" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| h = "Hello, "
|
||||
| w = "World!"
|
||||
@ -33,7 +35,8 @@ class TextTest extends InterpreterTest {
|
||||
|
||||
"support converting arbitrary structures to text" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|type My_Type a
|
||||
|
|
||||
|main =
|
||||
@ -47,7 +50,8 @@ class TextTest extends InterpreterTest {
|
||||
|
||||
"support text creation with raw block literals" in {
|
||||
val code =
|
||||
s"""
|
||||
s"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| x = $rawTQ
|
||||
| Foo
|
||||
@ -63,7 +67,8 @@ class TextTest extends InterpreterTest {
|
||||
|
||||
"support escape sequences in literals" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main = IO.println "\"Grzegorz Brzeczyszczykiewicz\""
|
||||
|""".stripMargin
|
||||
|
||||
@ -76,7 +81,8 @@ class TextTest extends InterpreterTest {
|
||||
val resultStr = errString.drop(1).dropRight(1)
|
||||
|
||||
val code =
|
||||
s"""
|
||||
s"""from Builtins import all
|
||||
|
|
||||
|main = IO.print_err $errString
|
||||
|""".stripMargin
|
||||
|
||||
@ -88,7 +94,8 @@ class TextTest extends InterpreterTest {
|
||||
val inputString = "foobarbaz"
|
||||
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| IO.readln + " yay!"
|
||||
|""".stripMargin
|
||||
|
@ -20,7 +20,8 @@ class ThreadInterruptionTest extends InterpreterTest {
|
||||
.asHostObject[Context]()
|
||||
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|foo x =
|
||||
| if x == 0 then IO.println "Start." else Unit
|
||||
| here.foo x+1
|
||||
|
@ -11,7 +11,8 @@ class BooleanTest extends InterpreterTest {
|
||||
|
||||
"support if_then_else" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| if True then IO.println "true when true" else IO.println "false when true"
|
||||
| if False then IO.println "true when false" else IO.println "false when false"
|
||||
@ -22,7 +23,8 @@ class BooleanTest extends InterpreterTest {
|
||||
|
||||
"support overriding methods on boolean" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Boolean.isTrue = this
|
||||
|
|
||||
|main =
|
||||
@ -37,7 +39,8 @@ class BooleanTest extends InterpreterTest {
|
||||
|
||||
"support pattern matching" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|to_num b = case b of
|
||||
| True -> 1
|
||||
| False -> 2
|
||||
@ -51,7 +54,8 @@ class BooleanTest extends InterpreterTest {
|
||||
|
||||
"support per-constructor method overloads" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|True.to_num = 1
|
||||
|False.to_num = 2
|
||||
|
|
||||
@ -62,7 +66,8 @@ class BooleanTest extends InterpreterTest {
|
||||
|
||||
"support per-single-constructor method overloads" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|Boolean.to_num = 2
|
||||
|True.to_num = 1
|
||||
|
|
||||
@ -73,7 +78,8 @@ class BooleanTest extends InterpreterTest {
|
||||
|
||||
"support logical AND and OR operators" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| IO.println True&&False
|
||||
| IO.println True&&True
|
||||
@ -87,7 +93,8 @@ class BooleanTest extends InterpreterTest {
|
||||
|
||||
"support negation" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| IO.println True.not
|
||||
| IO.println False.not
|
||||
|
@ -28,7 +28,8 @@ class JsonSerializationTest extends InterpreterTest {
|
||||
|
||||
"support atoms" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|type X a b c
|
||||
|
|
||||
|main = X 123 "foo" Unit . json_serialize
|
||||
@ -46,7 +47,8 @@ class JsonSerializationTest extends InterpreterTest {
|
||||
|
||||
"support nested types" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| test_val = Cons 1 (Cons "\"foo\"" (Cons Unit (Cons (x -> x) Nil)))
|
||||
| test_val.json_serialize
|
||||
|
@ -10,7 +10,8 @@ class NumberTest extends InterpreterTest {
|
||||
): Unit = {
|
||||
"support equality comparisons" in {
|
||||
val code =
|
||||
"""
|
||||
"""from Builtins import all
|
||||
|
|
||||
|main =
|
||||
| IO.println 7==5
|
||||
| IO.println 30==30
|
||||
|
@ -1 +1,3 @@
|
||||
from Base import all
|
||||
|
||||
main = IO.println "Hello, World!"
|
@ -1,3 +1,5 @@
|
||||
from Base import all
|
||||
|
||||
foo = 123
|
||||
|
||||
bar = 345
|
||||
|
@ -1 +1,3 @@
|
||||
from Builtins import all
|
||||
|
||||
main = IO.println "Test successful."
|
Loading…
Reference in New Issue
Block a user