pocketlang/tests/lang/import.pk

46 lines
1.2 KiB
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
from lang import *
from path import *
import "basics.pk" ## will import all
2021-06-02 17:33:29 +08:00
import "controlflow.pk" as if_test
from "functions.pk" import f1, f2 as fn2, f3
2021-05-19 02:59:09 +08:00
## If it has a module name it'll bind to that name.
import 'import/module.pk'
assert(module_name.get_module_name() == 'module_name')
## Import everything from the module.
from 'import/module.pk' import *
assert(module_name.get_module_name == get_module_name)
## script without module name will import all by default.
import 'import/all_import.pk'
assert(all_f1() == 'f1')
assert(all_f2() == 'f2')
assert(all_f3() == 'f3')
## Import the script and bound it with a given name.
import 'import/all_import.pk' as all_import
assert(all_import.all_f1 == all_f1)
## Test if the imported globals were initialized
import 'import/globals.pk'
assert(g_import != null)
assert(g_import.g_var_1 == 3)
assert(g_import.g_var_2 == g_import.get_a_value())
import 'import/globals2.pk'
assert(g_val_1 == 100)
assert(g_val_2 == get_a_value())
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')