From d61e322c1d14ebf8fa507bc397721b76c10f32e9 Mon Sep 17 00:00:00 2001 From: Stephen Berry Date: Tue, 18 Oct 2016 08:53:37 -0500 Subject: [PATCH] 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. --- unittests/namespaces.chai | 7 +++++++ unittests/namespaces_nested_copy.chai | 9 +++++++++ unittests/namespaces_nested_ref.chai | 9 +++++++++ 3 files changed, 25 insertions(+) create mode 100644 unittests/namespaces.chai create mode 100644 unittests/namespaces_nested_copy.chai create mode 100644 unittests/namespaces_nested_ref.chai diff --git a/unittests/namespaces.chai b/unittests/namespaces.chai new file mode 100644 index 00000000..51bea60f --- /dev/null +++ b/unittests/namespaces.chai @@ -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)) \ No newline at end of file diff --git a/unittests/namespaces_nested_copy.chai b/unittests/namespaces_nested_copy.chai new file mode 100644 index 00000000..7ec8ff53 --- /dev/null +++ b/unittests/namespaces_nested_copy.chai @@ -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) \ No newline at end of file diff --git a/unittests/namespaces_nested_ref.chai b/unittests/namespaces_nested_ref.chai new file mode 100644 index 00000000..5be991cb --- /dev/null +++ b/unittests/namespaces_nested_ref.chai @@ -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) \ No newline at end of file