From efae82199656aa466a5cfde7373fa20fac2d2d94 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 28 Aug 2010 22:55:43 +0000 Subject: [PATCH] Add some unit tests for reflection and recently discovered array lookup returned from a method problem --- src/main.cpp | 5 +++-- unittests/deep_array_lookup.chai | 11 +++++++++++ unittests/reflection_test.chai | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 unittests/deep_array_lookup.chai create mode 100644 unittests/reflection_test.chai diff --git a/src/main.cpp b/src/main.cpp index 964cb2e..94c4f27 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -149,10 +149,11 @@ int main(int argc, char *argv[]) { } } std::cout << std::endl; + return EXIT_FAILURE; } catch (std::exception &e) { - std::cout << e.what() << std::endl; - return EXIT_FAILURE; + std::cout << e.what() << std::endl; + return EXIT_FAILURE; } } } diff --git a/unittests/deep_array_lookup.chai b/unittests/deep_array_lookup.chai new file mode 100644 index 0000000..c405302 --- /dev/null +++ b/unittests/deep_array_lookup.chai @@ -0,0 +1,11 @@ +var a = [1,2,3, [4,5,6] ] + +assert_equal(a[3][0], 4) + + +def Test::Test() { this.a = [1,2,3]; } +attr Test::a; + +var t = Test(); + +assert_equal(t.a[0], 1) diff --git a/unittests/reflection_test.chai b/unittests/reflection_test.chai new file mode 100644 index 0000000..e12f31d --- /dev/null +++ b/unittests/reflection_test.chai @@ -0,0 +1,14 @@ +load_module("reflection") +var fname = "INPUT" +var parser := ChaiScript_Parser() +var parse_success = parser.parse("3 + 4", fname.c_str()) +var a := parser.ast() + +assert_equal(eval(a), 7) + +var childs := a.children.front().children +var node := childs[0] + +node.text = "9" + +assert_equal(eval(a), 13)