pocketlang/tests/lang/import.pk
Thakee Nathees 168f365cde import statements are refactored.
- all import statement (native or script file) have the same syntax
- allow relative (including parent directory) imports
- cyclic imports are handled by caching the scripts
- `import foo` can potentially import `<searchpath>/foo/_init.pk`
- * import are not supported anymore
2022-05-06 11:16:48 +05:30

38 lines
844 B
Plaintext

## Testing import statement
import lang
import lang, path
import lang as o, path as p
from lang import write
from lang import clock as c
import basics
import controlflow as if_test
from functions import f1, f2 as fn2, f3
import imports.fns
assert(fns.f1() == 'f1')
assert(fns.f2() == 'f2')
assert(fns.f3() == 'f3')
## Import the script and bound it with a given name.
import imports.fns as fns2
assert(fns2 == fns)
assert(fns2.f1 == fns.f1)
## Test if the imported globals were initialized
import imports.globals as gbl
assert(gbl.g_1 == 3)
assert(gbl.g_2 == gbl.get_a_value())
## import "imports/foo/_init.pk::bar"
from imports.foo import bar
assert(bar() == "foo.bar")
## Test cyclic import
import imports.cyclic_a as a
assert(a.get_b_fn()() == "cyclic b")
# If we got here, that means all test were passed.
print('All TESTS PASSED')