mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2025-12-06 16:57:04 +08:00
Added unit tests for namespaces.
These demonstrate the global scope of namespaces, defining functions and variables within namespaces, and namespace nesting by copy or reference.
This commit is contained in:
parent
d2c2962eb7
commit
d61e322c1d
7
unittests/namespaces.chai
Normal file
7
unittests/namespaces.chai
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace("math")
|
||||||
|
|
||||||
|
math.square = fun(x) { x * x }
|
||||||
|
math.sum_squares = fun(x, y) { math.square(x) + math.square(y) }
|
||||||
|
|
||||||
|
assert_equal(16, math.square(4))
|
||||||
|
assert_equal(29, math.sum_squares(2, 5))
|
||||||
9
unittests/namespaces_nested_copy.chai
Normal file
9
unittests/namespaces_nested_copy.chai
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace("parent")
|
||||||
|
namespace("child")
|
||||||
|
|
||||||
|
child.x = 3.0
|
||||||
|
parent.child = child
|
||||||
|
parent.child.x = 5.0
|
||||||
|
|
||||||
|
assert_equal(3.0, child.x)
|
||||||
|
assert_equal(5.0, parent.child.x)
|
||||||
9
unittests/namespaces_nested_ref.chai
Normal file
9
unittests/namespaces_nested_ref.chai
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace("parent")
|
||||||
|
namespace("child")
|
||||||
|
|
||||||
|
child.x = 3.0
|
||||||
|
parent.child := child
|
||||||
|
parent.child.x = 5.0
|
||||||
|
|
||||||
|
assert_equal(5.0, child.x)
|
||||||
|
assert_equal(5.0, parent.child.x)
|
||||||
Loading…
x
Reference in New Issue
Block a user