mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 22:28:45 +01:00
Get logical imports in "wren_modules" working.
There's a lot of changes here and surely some rough edges to iron out. Also, I need to update the docs. But I want to get closer to landing this so I can build on it.
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
void callRunTests(WrenVM* vm)
|
||||
{
|
||||
wrenEnsureSlots(vm, 1);
|
||||
wrenGetVariable(vm, "test/api/call", "Call", 0);
|
||||
wrenGetVariable(vm, "./test/api/call", "Call", 0);
|
||||
WrenHandle* callClass = wrenGetSlotHandle(vm, 0);
|
||||
|
||||
WrenHandle* noParams = wrenMakeCallHandle(vm, "noParams");
|
||||
|
||||
@ -4,23 +4,23 @@
|
||||
|
||||
static void beforeDefined(WrenVM* vm)
|
||||
{
|
||||
wrenGetVariable(vm, "test/api/get_variable", "A", 0);
|
||||
wrenGetVariable(vm, "./test/api/get_variable", "A", 0);
|
||||
}
|
||||
|
||||
static void afterDefined(WrenVM* vm)
|
||||
{
|
||||
wrenGetVariable(vm, "test/api/get_variable", "A", 0);
|
||||
wrenGetVariable(vm, "./test/api/get_variable", "A", 0);
|
||||
}
|
||||
|
||||
static void afterAssigned(WrenVM* vm)
|
||||
{
|
||||
wrenGetVariable(vm, "test/api/get_variable", "A", 0);
|
||||
wrenGetVariable(vm, "./test/api/get_variable", "A", 0);
|
||||
}
|
||||
|
||||
static void otherSlot(WrenVM* vm)
|
||||
{
|
||||
wrenEnsureSlots(vm, 3);
|
||||
wrenGetVariable(vm, "test/api/get_variable", "B", 2);
|
||||
wrenGetVariable(vm, "./test/api/get_variable", "B", 2);
|
||||
|
||||
// Move it into return position.
|
||||
const char* string = wrenGetSlotString(vm, 2);
|
||||
@ -29,7 +29,7 @@ static void otherSlot(WrenVM* vm)
|
||||
|
||||
static void otherModule(WrenVM* vm)
|
||||
{
|
||||
wrenGetVariable(vm, "test/api/get_variable_module", "Variable", 0);
|
||||
wrenGetVariable(vm, "./test/api/get_variable_module", "Variable", 0);
|
||||
}
|
||||
|
||||
WrenForeignMethodFn getVariableBindMethod(const char* signature)
|
||||
|
||||
@ -25,7 +25,7 @@ static WrenForeignMethodFn bindForeignMethod(
|
||||
WrenVM* vm, const char* module, const char* className,
|
||||
bool isStatic, const char* signature)
|
||||
{
|
||||
if (strncmp(module, "test/", 5) != 0) return NULL;
|
||||
if (strncmp(module, "./test/", 7) != 0) return NULL;
|
||||
|
||||
// For convenience, concatenate all of the method qualifiers into a single
|
||||
// signature string.
|
||||
@ -78,7 +78,7 @@ static WrenForeignClassMethods bindForeignClass(
|
||||
WrenVM* vm, const char* module, const char* className)
|
||||
{
|
||||
WrenForeignClassMethods methods = { NULL, NULL };
|
||||
if (strncmp(module, "test/", 5) != 0) return methods;
|
||||
if (strncmp(module, "./test/", 7) != 0) return methods;
|
||||
|
||||
foreignClassBindClass(className, &methods);
|
||||
if (methods.allocate != NULL) return methods;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
void resetStackAfterCallAbortRunTests(WrenVM* vm)
|
||||
{
|
||||
wrenEnsureSlots(vm, 1);
|
||||
wrenGetVariable(vm, "test/api/reset_stack_after_call_abort", "Test", 0);
|
||||
wrenGetVariable(vm, "./test/api/reset_stack_after_call_abort", "Test", 0);
|
||||
WrenHandle* testClass = wrenGetSlotHandle(vm, 0);
|
||||
|
||||
WrenHandle* abortFiber = wrenMakeCallHandle(vm, "abortFiber()");
|
||||
|
||||
@ -22,7 +22,8 @@ void resetStackAfterForeignConstructBindClass(
|
||||
void resetStackAfterForeignConstructRunTests(WrenVM* vm)
|
||||
{
|
||||
wrenEnsureSlots(vm, 1);
|
||||
wrenGetVariable(vm, "test/api/reset_stack_after_foreign_construct", "Test", 0);
|
||||
wrenGetVariable(vm,
|
||||
"./test/api/reset_stack_after_foreign_construct", "Test", 0);
|
||||
WrenHandle* testClass = wrenGetSlotHandle(vm, 0);
|
||||
|
||||
WrenHandle* callConstruct = wrenMakeCallHandle(vm, "callConstruct()");
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
class Foo {
|
||||
foreign someUnknownMethod // expect runtime error: Could not find foreign method 'someUnknownMethod' for class Foo in module 'test/language/foreign/unknown_method'.
|
||||
foreign someUnknownMethod // expect runtime error: Could not find foreign method 'someUnknownMethod' for class Foo in module './test/language/foreign/unknown_method'.
|
||||
}
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
System.print("before") // expect: before
|
||||
import "./module" for Module // expect runtime error: Could not compile module 'test/language/module/compile_error/module'.
|
||||
import "./module" for Module // expect runtime error: Could not compile module './test/language/module/compile_error/module'.
|
||||
|
||||
6
test/language/module/logical_dir/logical_dir.wren
Normal file
6
test/language/module/logical_dir/logical_dir.wren
Normal file
@ -0,0 +1,6 @@
|
||||
// Import a module from within a named package.
|
||||
import "foo/within_foo" for Foo
|
||||
// expect: ran foo module
|
||||
// expect: ran bar module
|
||||
|
||||
System.print(Foo) // expect: from foo
|
||||
@ -0,0 +1,5 @@
|
||||
// nontest
|
||||
var Bar = "from bar"
|
||||
System.print("ran bar module")
|
||||
|
||||
import "foo/within_foo"
|
||||
@ -0,0 +1,5 @@
|
||||
// nontest
|
||||
var Foo = "from foo"
|
||||
System.print("ran foo module")
|
||||
|
||||
import "bar/within_bar"
|
||||
5
test/language/module/logical_short/logical_short.wren
Normal file
5
test/language/module/logical_short/logical_short.wren
Normal file
@ -0,0 +1,5 @@
|
||||
// Import a module whose name is the same as the package.
|
||||
import "foo" for Module
|
||||
// expect: ran module
|
||||
|
||||
System.print(Module) // expect: from module
|
||||
@ -0,0 +1,3 @@
|
||||
// nontest
|
||||
var Module = "from module"
|
||||
System.print("ran module")
|
||||
@ -1 +1 @@
|
||||
import "./does_not_exist" for DoesNotExist // expect runtime error: Could not load module 'test/language/module/does_not_exist'.
|
||||
import "./does_not_exist" for DoesNotExist // expect runtime error: Could not load module './test/language/module/does_not_exist'.
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
// Should execute the module:
|
||||
// expect: ran module
|
||||
import "./module" for DoesNotExist // expect runtime error: Could not find a variable named 'DoesNotExist' in module 'test/language/module/unknown_variable/module'.
|
||||
import "./module" for DoesNotExist // expect runtime error: Could not find a variable named 'DoesNotExist' in module './test/language/module/unknown_variable/module'.
|
||||
|
||||
@ -0,0 +1,3 @@
|
||||
// Stops as soon as it finds a wren_modules directory, regardless of whether or
|
||||
// not it contains the desired module.
|
||||
import "foo" // expect runtime error: Could not load module 'foo'.
|
||||
@ -0,0 +1,2 @@
|
||||
// nontest
|
||||
System.print("ran foo module")
|
||||
@ -0,0 +1,3 @@
|
||||
// Walk up parent directories from the root script to find "wren_modules".
|
||||
import "foo"
|
||||
// expect: ran foo module
|
||||
@ -0,0 +1,2 @@
|
||||
// nontest
|
||||
System.print("ran foo module")
|
||||
@ -1,6 +1,6 @@
|
||||
import "meta" for Meta
|
||||
|
||||
var variables = Meta.getModuleVariables("test/meta/get_module_variables")
|
||||
var variables = Meta.getModuleVariables("./test/meta/get_module_variables")
|
||||
|
||||
// Includes implicitly imported core stuff.
|
||||
System.print(variables.contains("Object")) // expect: true
|
||||
|
||||
@ -9,40 +9,39 @@
|
||||
static void expectNormalize(const char* input, const char* expected)
|
||||
{
|
||||
Path* path = pathNew(input);
|
||||
Path* result = pathNormalize(path);
|
||||
pathNormalize(path);
|
||||
|
||||
if (strcmp(result->chars, expected) != 0)
|
||||
if (strcmp(path->chars, expected) != 0)
|
||||
{
|
||||
printf("FAIL %-30s Want %s\n", input, expected);
|
||||
printf(" Got %s\n\n", result->chars);
|
||||
printf(" Got %s\n\n", path->chars);
|
||||
fail();
|
||||
}
|
||||
else
|
||||
{
|
||||
#if SHOW_PASSES
|
||||
printf("PASS %-30s -> %s\n", input, result->chars);
|
||||
printf("PASS %-30s -> %s\n", input, path->chars);
|
||||
#endif
|
||||
pass();
|
||||
}
|
||||
|
||||
pathFree(path);
|
||||
pathFree(result);
|
||||
}
|
||||
|
||||
static void testNormalize()
|
||||
{
|
||||
// simple cases
|
||||
// Simple cases.
|
||||
expectNormalize("", ".");
|
||||
expectNormalize(".", ".");
|
||||
expectNormalize("..", "..");
|
||||
expectNormalize("a", "a");
|
||||
expectNormalize("/", "/");
|
||||
|
||||
// collapses redundant separators
|
||||
// Collapses redundant separators.
|
||||
expectNormalize("a/b/c", "a/b/c");
|
||||
expectNormalize("a//b///c////d", "a/b/c/d");
|
||||
|
||||
// eliminates "." parts
|
||||
// Eliminates "." parts, except one at the beginning.
|
||||
expectNormalize("./", ".");
|
||||
expectNormalize("/.", "/");
|
||||
expectNormalize("/./", "/");
|
||||
@ -50,10 +49,10 @@ static void testNormalize()
|
||||
expectNormalize("a/./b", "a/b");
|
||||
expectNormalize("a/.b/c", "a/.b/c");
|
||||
expectNormalize("a/././b/./c", "a/b/c");
|
||||
expectNormalize("././a", "a");
|
||||
expectNormalize("././a", "./a");
|
||||
expectNormalize("a/./.", "a");
|
||||
|
||||
// eliminates ".." parts
|
||||
// Eliminates ".." parts.
|
||||
expectNormalize("..", "..");
|
||||
expectNormalize("../", "..");
|
||||
expectNormalize("../../..", "../../..");
|
||||
@ -68,7 +67,7 @@ static void testNormalize()
|
||||
expectNormalize("a/b/c/../../d/e/..", "a/d");
|
||||
expectNormalize("a/b/../../../../c", "../../c");
|
||||
|
||||
// does not walk before root on absolute paths
|
||||
// Does not walk before root on absolute paths.
|
||||
expectNormalize("..", "..");
|
||||
expectNormalize("../", "..");
|
||||
expectNormalize("/..", "/");
|
||||
@ -84,7 +83,7 @@ static void testNormalize()
|
||||
expectNormalize("a/b/../../../../c", "../../c");
|
||||
expectNormalize("a/b/c/../../..d/./.e/f././", "a/..d/.e/f.");
|
||||
|
||||
// removes trailing separators
|
||||
// Removes trailing separators.
|
||||
expectNormalize("./", ".");
|
||||
expectNormalize(".//", ".");
|
||||
expectNormalize("a/", "a");
|
||||
@ -94,7 +93,7 @@ static void testNormalize()
|
||||
expectNormalize("foo/bar/baz", "foo/bar/baz");
|
||||
expectNormalize("foo", "foo");
|
||||
expectNormalize("foo/bar/", "foo/bar");
|
||||
expectNormalize("./foo/././bar/././", "foo/bar");
|
||||
expectNormalize("./foo/././bar/././", "./foo/bar");
|
||||
}
|
||||
|
||||
void testPath()
|
||||
|
||||
Reference in New Issue
Block a user