pocketlang/tests/lang/import.pk

38 lines
844 B
Plaintext
Raw Normal View History

## Testing import statement
2021-05-16 15:05:54 +08:00
import lang
import lang, path
import lang as o, path as p
2021-05-19 02:59:09 +08:00
from lang import write
2021-05-16 15:05:54 +08:00
from lang import clock as c
2021-05-19 02:59:09 +08:00
import basics
import controlflow as if_test
from functions import f1, f2 as fn2, f3
2021-05-19 02:59:09 +08:00
import imports.fns
assert(fns.f1() == 'f1')
assert(fns.f2() == 'f2')
assert(fns.f3() == 'f3')
2021-05-19 02:59:09 +08:00
## Import the script and bound it with a given name.
import imports.fns as fns2
assert(fns2 == fns)
assert(fns2.f1 == fns.f1)
2021-05-19 02:59:09 +08:00
## 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")
2021-05-19 02:59:09 +08:00
2021-06-16 02:54:30 +08:00
# If we got here, that means all test were passed.
print('All TESTS PASSED')