diff options
Diffstat (limited to 'libslang/src/test/nspace.sl')
-rw-r--r-- | libslang/src/test/nspace.sl | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/libslang/src/test/nspace.sl b/libslang/src/test/nspace.sl new file mode 100644 index 0000000..0b961c7 --- /dev/null +++ b/libslang/src/test/nspace.sl @@ -0,0 +1,93 @@ +_debug_info = 1; () = evalfile ("inc.sl"); + +print ("Testing NameSpace routines ..."); + +if (current_namespace () != "") + failed ("current_namespace - 1"); + +implements ("NSpace"); +% From this point on, define and variable defaults to static + +if (current_namespace () != "NSpace") + failed ("current_namespace - 2"); + +define static_function () +{ + "static_function"; +} +variable static_variable = "static_variable"; + +public define public_function () +{ + "public_function"; +} +public variable public_variable = "public_variable"; + +private define private_function () +{ + "private_function"; +} +private variable private_variable = "private_variable"; + +!if (is_defined ("Global->public_function")) failed ("public_function"); +!if (is_defined ("Global->public_variable")) failed ("public_variable"); +!if (is_defined ("public_function")) failed ("public_function"); +!if (is_defined ("public_variable")) failed ("public_variable"); +!if (is_defined ("NSpace->static_function")) failed ("static_function"); +!if (is_defined ("NSpace->static_variable")) failed ("static_variable"); +if (is_defined ("NSpace->private_function")) failed ("private_function"); +if (is_defined ("NSpace->private_variable")) failed ("private_variable"); + +if (static_variable != NSpace->static_variable) failed ("static_variable test"); +if (public_variable != Global->public_variable) failed ("public_variable test"); +if (private_variable != "private_variable") failed ("private_variable test"); + +public variable This_Namespace; + +This_Namespace = "NS1"; +() = evalfile ("ns1.inc"); +This_Namespace = "NS2"; +() = evalfile ("ns2.inc"); + +use_namespace ("NS1"); +if (func () != "NS1") + failed ("use_namespace 1"); +define func1 () +{ + return "1"; +} +use_namespace ("NS2"); +if (func () != "NS2") + failed ("use_namespace 2"); +define func1 () +{ + return "2"; +} +use_namespace ("Global"); +if (is_defined ("func")) + failed ("use_namespace Global"); +define func1 () +{ + return "3"; +} +!if (is_defined ("func1")) + failed ("use_namespace Global: func1"); + +if (NS1->func () != "NS1") + failed ("NS1->func"); +if (NS2->func () != "NS2") + failed ("NS2->func"); +if (NS1->func1 () != "1") + failed ("NS1->func1"); +if (NS2->func1 () != "2") + failed ("NS2->func1"); +if (Global->func1 () != "3") + failed ("Global->func1"); + +if (length (_get_namespaces ()) != 4) % Global, NS1, NS2, NSpace + failed ("_get_namespaces: %S", _get_namespaces()); + +print ("Ok\n"); + +exit (0); + |