diff --git a/CMakeLists.txt b/CMakeLists.txt index d448095..279a53c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,7 +123,7 @@ if (BUILD_MODULES) set(MODULES stl_extra reflection) endif() -file(GLOB UNIT_TESTS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/unittests/ ${CMAKE_CURRENT_SOURCE_DIR}/unittests/*.chai) +file(GLOB UNIT_TESTS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/unittests/ ${CMAKE_CURRENT_SOURCE_DIR}/unittests/*.chai ${CMAKE_CURRENT_SOURCE_DIR}/unittests/3.x/*.chai) list(SORT UNIT_TESTS) diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 5e5bdbe..577a310 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -402,7 +402,7 @@ namespace chaiscript m->add(fun(&dispatch::Dynamic_Object::get_attrs), "get_attrs"); m->add(fun(&dispatch::Dynamic_Object::get_attr), "get_attr"); - m->eval("def Dynamic_Object::clone() { auto &new_o = Dynamic_Object(this.get_type_name()); for_each(this.get_attrs(), bind([](new_o, x) { new_o.get_attr(x.first) = x.second; }, new_o, _) ); return new_o; }"); + m->eval("def Dynamic_Object::clone() { auto &new_o = Dynamic_Object(this.get_type_name()); for_each(this.get_attrs(), bind(fun(new_o, x) { new_o.get_attr(x.first) = x.second; }, new_o, _) ); return new_o; }"); m->add(fun(&has_guard), "has_guard"); m->add(fun(&get_guard), "get_guard"); diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 1bb296d..040ec96 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -321,6 +321,13 @@ namespace chaiscript throw exception::eval_error("Missing clone or copy constructor for right hand side of equation", e.parameters, t_ss); } } + else if (this->children[1]->text == ":=") { + if (lhs.is_undef() || Boxed_Value::type_match(lhs, retval)) { + lhs.assign(retval); + } else { + throw exception::eval_error("Mismatched types in equation"); + } + } else { try { retval = t_ss.call_function(this->children[1]->text, lhs, retval); diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index f21c7b9..fa7644d 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -1119,11 +1119,7 @@ namespace chaiscript size_t prev_stack_top = m_match_stack.size(); - //if (Keyword("fun")) { - if (Char('[')) { - if (!Char(']')) { - throw exception::eval_error("Closure list not currently supported", File_Position(m_line, m_col), *m_filename); - } + if (Keyword("fun")) { retval = true; if (Char('(')) { @@ -1546,7 +1542,7 @@ namespace chaiscript size_t prev_stack_top = m_match_stack.size(); - if (Keyword("auto")) { + if (Keyword("auto") || Keyword("var")) { retval = true; if (!(Reference() || Id(true))) { @@ -1601,10 +1597,10 @@ namespace chaiscript size_t prev_stack_top = m_match_stack.size(); - if (Char('{')) { + if (Char('[')) { retval = true; Container_Arg_List(); - if (!Char('}')) { + if (!Char(']')) { throw exception::eval_error("Missing closing brace '}' in container initializer", File_Position(m_line, m_col), *m_filename); } if ((prev_stack_top != m_match_stack.size()) && (m_match_stack.back()->children.size() > 0)) { @@ -1893,7 +1889,7 @@ namespace chaiscript if (Operator()) { retval = true; - if (Symbol("=", true, true) || Symbol("+=", true, true) || + if (Symbol("=", true, true) || Symbol(":=", true, true) || Symbol("+=", true, true) || Symbol("-=", true, true) || Symbol("*=", true, true) || Symbol("/=", true, true) || Symbol("%=", true, true) || Symbol("<<=", true, true) || Symbol(">>=", true, true) || Symbol("&=", true, true) || Symbol("^=", true, true) || Symbol("|=", true, true)) { diff --git a/include/chaiscript/language/chaiscript_prelude.hpp b/include/chaiscript/language/chaiscript_prelude.hpp index 9cdecaf..b75c475 100644 --- a/include/chaiscript/language/chaiscript_prelude.hpp +++ b/include/chaiscript/language/chaiscript_prelude.hpp @@ -7,7 +7,7 @@ #ifndef CHAISCRIPT_PRELUDE_HPP_ #define CHAISCRIPT_PRELUDE_HPP_ -//Note, the expression "{x,y}" in "collate" is parsed as two separate expressions +//Note, the expression "[x,y]" in "collate" is parsed as two separate expressions //by C++, so CODE_STRING, takes two expressions and adds in the missing comma #define CODE_STRING(x, y) #x ", " #y @@ -23,7 +23,7 @@ def to_string(x) : call_exists(first, x) && call_exists(second, x) { \n\ }\n\ # to_string for containers\n\ def to_string(x) : call_exists(range, x) && !x.is_type("string"){ \n\ - "{" + x.join(", ") + "}"; \n\ + "[" + x.join(", ") + "]"; \n\ }\n\ # Basic to_string function\n\ def to_string(x) { \n\ @@ -259,7 +259,7 @@ def generate_range(x, y) { \n\ }\n\ # Returns a new Vector with the first value to the second value as its elements\n\ def collate(x, y) { \n\ - return {x, y}; \n\ + return [x, y]; \n\ } \n\ def zip_with(f, x, y, inserter) : call_exists(range, x) && call_exists(range, y) { \n\ auto r_x = range(x); \n\ @@ -305,10 +305,10 @@ def string::find_last_not_of(list) : is_type(list, "string") { \n\ int(find_last_not_of(this, list, -1)); \n\ } \n\ def string::ltrim() { \n\ - drop_while(this, [](x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'}); \n\ + drop_while(this, fun(x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'}); \n\ } \n\ def string::rtrim() { \n\ - reverse(drop_while(reverse(this), [](x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'})); \n\ + reverse(drop_while(reverse(this), fun(x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'})); \n\ } \n\ def string::trim() { \n\ ltrim(rtrim(this)); \n\ diff --git a/unittests/3.x/assign_const.chai b/unittests/3.x/assign_const.chai new file mode 100644 index 0000000..ff6a8c3 --- /dev/null +++ b/unittests/3.x/assign_const.chai @@ -0,0 +1,2 @@ +assert_throws("Mismatched types in equation, lhs is const.", fun() { 1 = 2 } ); +assert_throws("Mismatched types in equation, lhs is const.", fun() { 1 + 2 = 2 } ); diff --git a/unittests/3.x/bind.chai b/unittests/3.x/bind.chai new file mode 100644 index 0000000..3c72673 --- /dev/null +++ b/unittests/3.x/bind.chai @@ -0,0 +1,2 @@ +var prod = bind(foldl, _, `*`, 1.0) +assert_equal(60, prod([3, 4, 5])) diff --git a/unittests/3.x/bind2.chai b/unittests/3.x/bind2.chai new file mode 100644 index 0000000..0b8ddde --- /dev/null +++ b/unittests/3.x/bind2.chai @@ -0,0 +1,34 @@ + +def add(x, y) +{ + return x + y; +} + +assert_equal(2, add.get_arity()); + +var b = bind(add, 2, _); + +assert_equal(1, b.get_arity()); + +var c = bind(b, 3); + +assert_equal(0, c.get_arity()); + +assert_equal(6, b(4)); +assert_equal(5, c()); + +def concat2(a,b,c,d) +{ + return to_string(a) + to_string(b) + to_string(c) + to_string(d); +} + +var d = bind(concat2, _, " Hello ", _, " World"); +assert_equal(2, d.get_arity()); + +assert_equal("1 Hello 3 World", d(1,3)); + +var e = bind(`<`, _, 5); +var types = e.get_param_types(); +assert_equal(2, types.size()); +assert_equal(true, types[0].bare_equal(bool_type)); + diff --git a/unittests/3.x/block_start.chai b/unittests/3.x/block_start.chai new file mode 100644 index 0000000..4830af1 --- /dev/null +++ b/unittests/3.x/block_start.chai @@ -0,0 +1 @@ +{print("hello")} diff --git a/unittests/3.x/bool_not.chai b/unittests/3.x/bool_not.chai new file mode 100644 index 0000000..fe4d0f7 --- /dev/null +++ b/unittests/3.x/bool_not.chai @@ -0,0 +1 @@ +assert_equal(false, !true) diff --git a/unittests/3.x/boxed_cast_test.cpp b/unittests/3.x/boxed_cast_test.cpp new file mode 100644 index 0000000..2e6edd9 --- /dev/null +++ b/unittests/3.x/boxed_cast_test.cpp @@ -0,0 +1,319 @@ +#include + + +using namespace chaiscript; + + +template +void use(T){} + +template +bool run_test_type_conversion(const Boxed_Value &bv, bool expectedpass) +{ + try { + To ret = chaiscript::boxed_cast(bv); + use(ret); + } catch (const chaiscript::exception::bad_boxed_cast &/*e*/) { + if (expectedpass) { +// std::cerr << "Failure in run_test_type_conversion: " << e.what() << std::endl; + return false; + } else { + return true; + } + } catch (const std::exception &e) { + std::cerr << "Unexpected standard exception when attempting cast_conversion: " << e.what() << std::endl; + return false; + } catch (...) { + std::cerr << "Unexpected unknown exception when attempting cast_conversion." << std::endl; + return false; + } + + if (expectedpass) + { + return true; + } else { + return false; + } +} + +template +bool test_type_conversion(const Boxed_Value &bv, bool expectedpass) +{ + bool ret = run_test_type_conversion(bv, expectedpass); + + if (!ret) + { + std::cerr << "Error with type conversion test. From: " + << (bv.is_const()?(std::string("const ")):(std::string())) << bv.get_type_info().name() + << " To: " + << (boost::is_const::value?(std::string("const ")):(std::string())) << typeid(To).name() + << " test was expected to " << ((expectedpass)?(std::string("succeed")):(std::string("fail"))) << " but did not" << std::endl; + } + + return ret; +} + +template +bool do_test(const Boxed_Value &bv, bool T, bool ConstT, bool TRef, bool ConstTRef, bool TPtr, bool ConstTPtr, bool TPtrConst, + bool ConstTPtrConst, bool SharedPtrT, bool SharedConstPtrT, + bool ConstSharedPtrT, bool ConstSharedConstPtrT, bool ConstSharedPtrTRef, bool ConstSharedPtrTConstRef, + bool BoostRef, bool BoostConstRef, bool ConstBoostRef, bool ConstBoostConstRef, + bool ConstBoostRefRef, bool ConstBoostConstRefRef, bool Number, + bool ConstNumber, bool ConstNumberRef, bool TPtrConstRef, bool ConstTPtrConstRef) +{ + bool passed = true; + passed &= test_type_conversion(bv, T); + passed &= test_type_conversion(bv, ConstT); + passed &= test_type_conversion(bv, TRef); + passed &= test_type_conversion(bv, ConstTRef); + passed &= test_type_conversion(bv, TPtr); + passed &= test_type_conversion(bv, ConstTPtr); + passed &= test_type_conversion(bv, TPtrConst); + passed &= test_type_conversion(bv, ConstTPtrConst); + passed &= test_type_conversion >(bv, SharedPtrT); + passed &= test_type_conversion >(bv, SharedConstPtrT); + passed &= test_type_conversion &>(bv, false); + passed &= test_type_conversion &>(bv, false); + passed &= test_type_conversion >(bv, ConstSharedPtrT); + passed &= test_type_conversion >(bv, ConstSharedConstPtrT); + passed &= test_type_conversion &>(bv, ConstSharedPtrTRef); + passed &= test_type_conversion &>(bv, ConstSharedPtrTConstRef); + passed &= test_type_conversion >(bv, BoostRef); + passed &= test_type_conversion >(bv, BoostConstRef); + passed &= test_type_conversion &>(bv, false); + passed &= test_type_conversion &>(bv, false); + passed &= test_type_conversion >(bv, ConstBoostRef); + passed &= test_type_conversion >(bv, ConstBoostConstRef); + passed &= test_type_conversion &>(bv, ConstBoostRefRef); + passed &= test_type_conversion &>(bv, ConstBoostConstRefRef); + passed &= test_type_conversion(bv, Number); + passed &= test_type_conversion(bv, ConstNumber); + passed &= test_type_conversion(bv, false); + passed &= test_type_conversion(bv, ConstNumberRef); + passed &= test_type_conversion(bv, false); + passed &= test_type_conversion(bv, false); + passed &= test_type_conversion(bv, false); + passed &= test_type_conversion(bv, false); + passed &= test_type_conversion(bv, false); + passed &= test_type_conversion(bv, false); + passed &= test_type_conversion(bv, TPtrConstRef); + passed &= test_type_conversion(bv, ConstTPtrConstRef); + passed &= test_type_conversion(bv, true); + passed &= test_type_conversion(bv, true); + passed &= test_type_conversion(bv, true); + + return passed; +} + +/** Tests intended for built int types **/ +template +bool built_in_type_test(const T &initial, bool ispod) +{ + bool passed = true; + + /** value tests **/ + T i = T(initial); + passed &= do_test(var(i), true, true, true, true, true, + true, true, true, true, true, + true, true, true, true, true, + true, true, true, true, true, + ispod && true, ispod && true, ispod && true, true, true); + + passed &= do_test(const_var(i), true, true, false, true, false, + true, false, true, false, true, + false, true, false, true, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + passed &= do_test(var(&i), true, true, true, true, true, + true, true, true, false, false, + false, false, false, false, true, + true, true, true, true, true, + ispod && true, ispod && true, ispod && true, true, true); + + passed &= do_test(const_var(&i), true, true, false, true, false, + true, false, true, false, false, + false, false, false, false, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, ispod && false, true); + + passed &= do_test(var(boost::ref(i)), true, true, true, true, true, + true, true, true, false, false, + false, false, false, false, true, + true, true, true, true, true, + ispod && true, ispod && true, ispod && true, true, true); + + passed &= do_test(var(boost::cref(i)), true, true, false, true, false, + true, false, true, false, false, + false, false, false, false, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + /** Const Reference Variable tests */ + + // This reference will be copied on input, which is expected + const T &ir = i; + + passed &= do_test(var(i), true, true, true, true, true, + true, true, true, true, true, + true, true, true, true, true, + true, true, true, true, true, + ispod && true, ispod && true, ispod && true, true, true); + + // But a pointer or reference to it should be necessarily const + passed &= do_test(var(&ir), true, true, false, true, false, + true, false, true, false, false, + false, false, false, false, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + passed &= do_test(var(boost::ref(ir)), true, true, false, true, false, + true, false, true, false, false, + false, false, false, false, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + // Make sure const of const works too + passed &= do_test(const_var(&ir), true, true, false, true, false, + true, false, true, false, false, + false, false, false, false, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + passed &= do_test(const_var(boost::ref(ir)), true, true, false, true, false, + true, false, true, false, false, + false, false, false, false, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + /** Const Reference Variable tests */ + + // This will always be seen as a const + const T*cip = &i; + passed &= do_test(var(cip), true, true, false, true, false, + true, false, true, false, false, + false, false, false, false, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + // make sure const of const works + passed &= do_test(const_var(cip), true, true, false, true, false, + true, false, true, false, false, + false, false, false, false, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + /** shared_ptr tests **/ + + boost::shared_ptr ip(new T(initial)); + + passed &= do_test(var(ip), true, true, true, true, true, + true, true, true, true, true, + true, true, true, true, true, + true, true, true, true, true, + ispod && true, ispod && true, ispod && true, true, true); + + passed &= do_test(const_var(ip), true, true, false, true, false, + true, false, true, false, true, + false, true, false, true, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + /** const shared_ptr tests **/ + boost::shared_ptr ipc(new T(initial)); + + passed &= do_test(var(ipc), true, true, false, true, false, + true, false, true, false, true, + false, true, false, true, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + // const of this should be the same, making sure it compiles + passed &= do_test(const_var(ipc), true, true, false, true, false, + true, false, true, false, true, + false, true, false, true, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + + /** Double ptr tests **/ + + /* + T **doublep; + + passed &= do_test(var(doublep), true, true, false, true, false, + true, false, true, false, true, + false, true, false, true, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); +*/ + + return passed; +} + + +template +bool pointer_test(const T& default_value, const T& new_value) +{ + T *p = new T(default_value); + + // we store a pointer to a pointer, so we can get a pointer to a pointer + try { + T **result = boxed_cast(var(&p)); + *(*result) = new_value; + + + if (p != (*result) ) { + std::cerr << "Pointer passed in different than one returned" << std::endl; + return false; + } + + if (*p != *(*result) ) { + std::cerr << "Somehow dereferenced pointer values are not the same?" << std::endl; + return false; + } + + return true; + } catch (const exception::bad_boxed_cast &) { + std::cerr << "Bad boxed cast performing ** to ** test" << std::endl; + return false; + } catch (...) { + std::cerr << "Unknown exception performing ** to ** test" << std::endl; + return false; + } + + +} + + +int main() +{ + bool passed = true; + + /* + bool T, bool ConstT, bool TRef, bool ConstTRef, bool TPtr, + bool ConstTPtr, bool TPtrConst, bool ConstTPtrConst, bool SharedPtrT, bool SharedConstPtrT, + bool ConstSharedPtrT, bool ConstSharedConstPtrT, bool ConstSharedPtrTRef, bool ConstSharedPtrTConstRef, bool BoostRef, + bool BoostConstRef, bool ConstBoostRef, bool ConstBoostConstRef, bool ConstBoostRefRef, bool ConstBoostConstRefRef, + bool Number, bool ConstNumber, bool ConstNumberRef + */ + + passed &= built_in_type_test(5, true); + passed &= built_in_type_test(1.1, true); + passed &= built_in_type_test('a', true); + passed &= built_in_type_test('a', true); + passed &= built_in_type_test('a', true); + passed &= built_in_type_test(false, false); + passed &= built_in_type_test("Hello World", false); + + // storing a pointer + passed &= pointer_test(1, 0); + + if (passed) + { + return EXIT_SUCCESS; + } else { + return EXIT_FAILURE; + } + +} diff --git a/unittests/3.x/break_while.chai b/unittests/3.x/break_while.chai new file mode 100644 index 0000000..d54a3dd --- /dev/null +++ b/unittests/3.x/break_while.chai @@ -0,0 +1,7 @@ +var i = 0 +while (i < 10) { + if (++i == 5) { + break + } +} +assert_equal(5, i); diff --git a/unittests/3.x/char_init.chai b/unittests/3.x/char_init.chai new file mode 100644 index 0000000..ce76477 --- /dev/null +++ b/unittests/3.x/char_init.chai @@ -0,0 +1 @@ +assert_equal("b", to_string('b')) diff --git a/unittests/3.x/classification.chai b/unittests/3.x/classification.chai new file mode 100644 index 0000000..8c2cca9 --- /dev/null +++ b/unittests/3.x/classification.chai @@ -0,0 +1,7 @@ +assert_equal(true, 1.is_var_const()); +assert_equal(false, 1.is_var_reference()); +assert_equal(true, 1.is_var_pointer()); +assert_equal(false, 1.is_var_null()); +assert_equal(false, 1.is_var_undef()); +var i; +assert_equal(true, i.is_var_undef()); diff --git a/unittests/3.x/collate.chai b/unittests/3.x/collate.chai new file mode 100644 index 0000000..12632e5 --- /dev/null +++ b/unittests/3.x/collate.chai @@ -0,0 +1,3 @@ +var v = collate(1, 2) +assert_equal(1, v[0]) +assert_equal(2, v[1]) diff --git a/unittests/3.x/compare_gt.chai b/unittests/3.x/compare_gt.chai new file mode 100644 index 0000000..9a6ea45 --- /dev/null +++ b/unittests/3.x/compare_gt.chai @@ -0,0 +1 @@ +assert_equal(false, 1 > 2); diff --git a/unittests/3.x/compare_lt.chai b/unittests/3.x/compare_lt.chai new file mode 100644 index 0000000..6064110 --- /dev/null +++ b/unittests/3.x/compare_lt.chai @@ -0,0 +1 @@ +assert_equal(true, 1 < 2) diff --git a/unittests/3.x/concat.chai b/unittests/3.x/concat.chai new file mode 100644 index 0000000..3d285a5 --- /dev/null +++ b/unittests/3.x/concat.chai @@ -0,0 +1,5 @@ +var v = concat([1, 2], [3, 4]); + +assert_equal(4, v.size()); +assert_equal(1, v[0]); +assert_equal(4, v[3]); diff --git a/unittests/3.x/const_range_test.chai b/unittests/3.x/const_range_test.chai new file mode 100644 index 0000000..5ebb580 --- /dev/null +++ b/unittests/3.x/const_range_test.chai @@ -0,0 +1,4 @@ +//If the following succeeds, the test passes + + +"Hello World".for_each(fun(x) { print(x) } ) diff --git a/unittests/3.x/convert_double_string.chai b/unittests/3.x/convert_double_string.chai new file mode 100644 index 0000000..e12b90f --- /dev/null +++ b/unittests/3.x/convert_double_string.chai @@ -0,0 +1 @@ +assert_equal("3.5bob", 3.5.to_string() + "bob"); diff --git a/unittests/3.x/convert_int_string.chai b/unittests/3.x/convert_int_string.chai new file mode 100644 index 0000000..0fcda32 --- /dev/null +++ b/unittests/3.x/convert_int_string.chai @@ -0,0 +1 @@ +assert_equal("3bob", 3.to_string + "bob") diff --git a/unittests/3.x/convert_string_double.chai b/unittests/3.x/convert_string_double.chai new file mode 100644 index 0000000..b7b0b6e --- /dev/null +++ b/unittests/3.x/convert_string_double.chai @@ -0,0 +1 @@ +assert_equal(6.8, "3.5".to_double() + 3.3) diff --git a/unittests/3.x/convert_string_int.chai b/unittests/3.x/convert_string_int.chai new file mode 100644 index 0000000..e62eec9 --- /dev/null +++ b/unittests/3.x/convert_string_int.chai @@ -0,0 +1 @@ +assert_equal(8, "4".to_int() + 4) diff --git a/unittests/3.x/deep_array_lookup.chai b/unittests/3.x/deep_array_lookup.chai new file mode 100644 index 0000000..c405302 --- /dev/null +++ b/unittests/3.x/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/3.x/dispatch_functions.chai b/unittests/3.x/dispatch_functions.chai new file mode 100644 index 0000000..528d5b3 --- /dev/null +++ b/unittests/3.x/dispatch_functions.chai @@ -0,0 +1,11 @@ +assert_equal(`==`, `==`); +assert_not_equal(`==`, `<`); +assert_equal(`<`.get_arity(), 2); +assert_equal(`+`.get_annotation(), "Multiple method dispatch function wrapper."); +assert_equal(get_arity.get_contained_functions().size(), 0); +assert_equal(get_arity.get_arity(), 1); +assert_equal(get_arity.get_param_types().size(), 2); + +var paramtypes = get_arity.get_param_types(); + +assert_equal(true, paramtypes[1].bare_equal(Function_type)); diff --git a/unittests/3.x/drop.chai b/unittests/3.x/drop.chai new file mode 100644 index 0000000..c64b431 --- /dev/null +++ b/unittests/3.x/drop.chai @@ -0,0 +1 @@ +assert_equal([3,4], drop([1, 2, 3, 4], 2)) diff --git a/unittests/3.x/drop_while.chai b/unittests/3.x/drop_while.chai new file mode 100644 index 0000000..08e19f2 --- /dev/null +++ b/unittests/3.x/drop_while.chai @@ -0,0 +1 @@ +assert_equal([2, 3], drop_while([1, 2, 3], odd)) diff --git a/unittests/3.x/dynamic_object_test.cpp b/unittests/3.x/dynamic_object_test.cpp new file mode 100644 index 0000000..8383e03 --- /dev/null +++ b/unittests/3.x/dynamic_object_test.cpp @@ -0,0 +1,44 @@ +#include + +template +void assert_equal(const LHS &lhs, const RHS &rhs) +{ + if (lhs==rhs) + { + return; + } else { + std::cout << "Got: " << lhs << " expected " << rhs << std::endl; + exit(EXIT_FAILURE); + } +} + +int main() +{ + + chaiscript::ChaiScript chai; + + chai("attr bob::z; def bob::bob() { this.z = 10 }; var x = bob()"); + + chaiscript::dispatch::Dynamic_Object &mydo = chai.eval("x"); + + assert_equal(mydo.get_type_name(), "bob"); + + assert_equal(chaiscript::boxed_cast(mydo.get_attr("z")), 10); + + chai("x.z = 15"); + + assert_equal(chaiscript::boxed_cast(mydo.get_attr("z")), 15); + + int &z = chaiscript::boxed_cast(mydo.get_attr("z")); + + assert_equal(z, 15); + + z = 20; + + assert_equal(z, 20); + + assert_equal(chaiscript::boxed_cast(chai("x.z")), 20); + + return EXIT_SUCCESS; + +} diff --git a/unittests/3.x/empty.chai b/unittests/3.x/empty.chai new file mode 100644 index 0000000..e69de29 diff --git a/unittests/3.x/equ_shortform.chai b/unittests/3.x/equ_shortform.chai new file mode 100644 index 0000000..41c8e1d --- /dev/null +++ b/unittests/3.x/equ_shortform.chai @@ -0,0 +1,4 @@ +var x=.5 +assert_equal(.5, x) +var y=-.5 +assert_equal(-.5, y) diff --git a/unittests/3.x/eval.chai b/unittests/3.x/eval.chai new file mode 100644 index 0000000..2f18aa4 --- /dev/null +++ b/unittests/3.x/eval.chai @@ -0,0 +1 @@ +assert_equal(7, eval("3 + 4")) diff --git a/unittests/3.x/eval_catch_exception_test.cpp b/unittests/3.x/eval_catch_exception_test.cpp new file mode 100644 index 0000000..c599c09 --- /dev/null +++ b/unittests/3.x/eval_catch_exception_test.cpp @@ -0,0 +1,122 @@ +// Tests to make sure that the order in which function dispatches occur is correct + +#include + +int test_generic() +{ + chaiscript::ChaiScript chai; + + try { + chai.eval("throw(runtime_error(\"error\"));"); + } catch (const chaiscript::Boxed_Value &bv) { + const std::exception &e = chaiscript::boxed_cast(bv); + if (e.what() == std::string("error")) + { + return EXIT_SUCCESS; + } + } + + std::cout << "test_generic failed" << std::endl; + return EXIT_FAILURE; +} + +int test_1() +{ + chaiscript::ChaiScript chai; + + try { + chai.eval("throw(1)", chaiscript::exception_specification()); + } catch (int e) { + if (e == 1) + { + return EXIT_SUCCESS; + } + } + + std::cout << "test_1 failed" << std::endl; + return EXIT_FAILURE; +} + +int test_2() +{ + chaiscript::ChaiScript chai; + + try { + chai.eval("throw(1.0)", chaiscript::exception_specification()); + } catch (const double e) { + if (e == 1.0) + { + return EXIT_SUCCESS; + } + } + + std::cout << "test_2 failed" << std::endl; + return EXIT_FAILURE; +} + +int test_5() +{ + chaiscript::ChaiScript chai; + + try { + chai.eval("throw(runtime_error(\"error\"))", chaiscript::exception_specification()); + } catch (const double e) { + std::cout << "test_5 failed with double" << std::endl; + return EXIT_FAILURE; + } catch (int) { + std::cout << "test_5 failed with int" << std::endl; + return EXIT_FAILURE; + } catch (float) { + std::cout << "test_5 failed with float" << std::endl; + return EXIT_FAILURE; + } catch (const std::string &) { + std::cout << "test_5 failed with string" << std::endl; + return EXIT_FAILURE; + } catch (const std::exception &e) { + return EXIT_SUCCESS; + } + + std::cout << "test_5 failed" << std::endl; + return EXIT_FAILURE; +} + +int test_unhandled() +{ + chaiscript::ChaiScript chai; + + try { + chai.eval("throw(\"error\")", chaiscript::exception_specification()); + } catch (double) { + std::cout << "test_unhandled failed with double" << std::endl; + return EXIT_FAILURE; + } catch (int) { + std::cout << "test_unhandled failed with int" << std::endl; + return EXIT_FAILURE; + } catch (float) { + std::cout << "test_unhandled failed with float" << std::endl; + return EXIT_FAILURE; + } catch (const std::exception &e) { + std::cout << "test_unhandled failed with std::exception" << std::endl; + return EXIT_FAILURE; + } catch (const chaiscript::Boxed_Value &bv) { + return EXIT_SUCCESS; + } + + std::cout << "test_unhandled failed" << std::endl; + return EXIT_FAILURE; +} + + +int main() +{ + if (test_generic() == EXIT_SUCCESS + && test_1() == EXIT_SUCCESS + && test_2() == EXIT_SUCCESS + && test_5() == EXIT_SUCCESS + && test_unhandled() == EXIT_SUCCESS) + { + return EXIT_SUCCESS; + } else { + return EXIT_FAILURE; + } +} diff --git a/unittests/3.x/eval_error.chai b/unittests/3.x/eval_error.chai new file mode 100644 index 0000000..d63ad75 --- /dev/null +++ b/unittests/3.x/eval_error.chai @@ -0,0 +1,39 @@ +load_module("reflection") + +def deep() +{ + try { + } catch { + + } finally { + if (2) + { + } + + } +} + +def func() +{ + deep(); +} + +def doing() +{ + for (var i = 0; i < 10; ++i) + { + func(); + } +} + +def while_doing() +{ + while (true) + { + doing(); + } +} + +var f = fun() { while_doing(); } + +assert_equal(get_eval_error(f).call_stack.size(), 16) diff --git a/unittests/3.x/even.chai b/unittests/3.x/even.chai new file mode 100644 index 0000000..5a9a9ae --- /dev/null +++ b/unittests/3.x/even.chai @@ -0,0 +1 @@ +assert_equal(true, even(4)) diff --git a/unittests/3.x/exception.chai b/unittests/3.x/exception.chai new file mode 100644 index 0000000..50df6a8 --- /dev/null +++ b/unittests/3.x/exception.chai @@ -0,0 +1,9 @@ +var x = 1 +try { + throw(x) + x = 2 +} +catch(e) { + x = e + 3 +} +assert_equal(4, x); diff --git a/unittests/3.x/exception_finally.chai b/unittests/3.x/exception_finally.chai new file mode 100644 index 0000000..d6fd834 --- /dev/null +++ b/unittests/3.x/exception_finally.chai @@ -0,0 +1,32 @@ +var finallyone = false; + +try { + throw(3) +} +catch(x) { + assert_equal(3, x) +} +finally { + finallyone = true; +} + +assert_equal(true, finallyone); + +var try2 = false; +var catch2 = false; +var finally2 = false; + + +try { + try2 = true; +} +catch { + catch2 = true; +} +finally { + finally2 = true; +} + +assert_equal(true, try2); +assert_equal(false, catch2); +assert_equal(true, finally2); diff --git a/unittests/3.x/exception_guards.chai b/unittests/3.x/exception_guards.chai new file mode 100644 index 0000000..99cd901 --- /dev/null +++ b/unittests/3.x/exception_guards.chai @@ -0,0 +1,34 @@ +var results = []; + +for (var i = 2; i < 6; ++i) { + try { + throw(i) + } + catch(e) : e < 2 { + results.push_back("c1: " + e.to_string()); + } + catch(e) : e < 4 { + results.push_back("c2: " + e.to_string()); + } + catch(e) { + results.push_back("c3: " + e.to_string()); + } + catch { + // Should never get called + assert_equal(false, true) + } +} + +try { + throw(3) +} +catch(e) : e < 3 +{ + // Should never get called + assert_equal(false, true); +} +catch { + results.push_back("defaultcatch"); +} + +assert_equal(["c2: 2", "c2: 3", "c3: 4", "c3: 5", "defaultcatch"], results); diff --git a/unittests/3.x/filter.chai b/unittests/3.x/filter.chai new file mode 100644 index 0000000..6d805fe --- /dev/null +++ b/unittests/3.x/filter.chai @@ -0,0 +1 @@ +assert_equal([1,3], filter([1, 2, 3, 4], odd)) diff --git a/unittests/3.x/float.chai b/unittests/3.x/float.chai new file mode 100644 index 0000000..b1bdf29 --- /dev/null +++ b/unittests/3.x/float.chai @@ -0,0 +1,7 @@ +assert_equal(true, 1.2 < 2) +assert_equal(true, 1.2 > 1) +assert_equal(1.2, 1.2) + +assert_equal(true, .5 > 0) +assert_equal(true, .5 < 1) +assert_equal(0.5, .5) diff --git a/unittests/3.x/foldl.chai b/unittests/3.x/foldl.chai new file mode 100644 index 0000000..7e9db51 --- /dev/null +++ b/unittests/3.x/foldl.chai @@ -0,0 +1 @@ +assert_equal(10, foldl([1, 2, 3, 4], `+`, 0)) diff --git a/unittests/3.x/for.chai b/unittests/3.x/for.chai new file mode 100644 index 0000000..9799be2 --- /dev/null +++ b/unittests/3.x/for.chai @@ -0,0 +1,7 @@ +var ret = [] + +for (var i = 0; i < 5; ++i) { + ret.push_back(i); +} + +assert_equal([0,1,2,3,4], ret); diff --git a/unittests/3.x/for_each.chai b/unittests/3.x/for_each.chai new file mode 100644 index 0000000..242a1ba --- /dev/null +++ b/unittests/3.x/for_each.chai @@ -0,0 +1 @@ +for_each([1, 2, 3], print) diff --git a/unittests/3.x/for_each_range.chai b/unittests/3.x/for_each_range.chai new file mode 100644 index 0000000..43191bf --- /dev/null +++ b/unittests/3.x/for_each_range.chai @@ -0,0 +1,3 @@ +var v = [1,2,3]; +var r = range(v); +for_each(r, fun(x) { assert_equal(true, x>0); } ) diff --git a/unittests/3.x/for_each_retro.chai b/unittests/3.x/for_each_retro.chai new file mode 100644 index 0000000..cc27a58 --- /dev/null +++ b/unittests/3.x/for_each_retro.chai @@ -0,0 +1,4 @@ +// Don't bother checking the output from this one, just makes sure it executes +var v = [1,2,3]; +var r = retro(range(v)); +for_each(r, print) diff --git a/unittests/3.x/function_array_adjacent.chai b/unittests/3.x/function_array_adjacent.chai new file mode 100644 index 0000000..c34e2be --- /dev/null +++ b/unittests/3.x/function_array_adjacent.chai @@ -0,0 +1 @@ +assert_equal(2, `+`.get_contained_functions()[0].get_arity()) diff --git a/unittests/3.x/function_introspection.chai b/unittests/3.x/function_introspection.chai new file mode 100644 index 0000000..5ad76fc --- /dev/null +++ b/unittests/3.x/function_introspection.chai @@ -0,0 +1,76 @@ + +#Test Function Description +def test_function(a) +{ + return a; +} + + + + +// test_function tests +assert_equal(test_function.get_arity(), 1); +assert_equal(trim(test_function.get_annotation()), "#Test Function Description"); +assert_equal(test_function.get_contained_functions().size(), 0); +assert_equal(test_function.get_param_types().size(), 2); + +assert_equal(test_function, test_function); + +assert_not_equal(test_function, `+`); + +assert_equal(test_function.call([1]), 1); + +// dynamic object function tests + +def int::test_fun() +{ + return this; +} + +assert_equal(test_fun.get_arity(), 1); +assert_equal(test_fun.get_contained_functions.size(), 1); +assert_equal(test_fun.get_param_types().size(), 2); +assert_equal(test_fun, test_fun); +var test_fun_types = test_fun.get_param_types(); +assert_equal(true, test_fun_types[0].bare_equal(Object_type)); +assert_equal(true, test_fun_types[1].bare_equal(int_type)); + + +// built-ins tests + +assert_equal(2, `==`.get_arity()); + +// < should be the merging of two functions bool <(PODObject, PODObject) and bool <(string, string) +// we want to peel it apart and make sure that's true +var types = `<`.get_param_types(); +assert_equal(3, types.size()); +assert_equal(true, types[0].bare_equal(bool_type)); +assert_equal(true, types[1].bare_equal(Object_type)); +assert_equal(true, types[2].bare_equal(Object_type)); +assert_equal(2, `<`.get_contained_functions().size()); + + +// guard existence tests + +def with_guard(x) : x > 3 {} +def without_guard(x) {} + +def group_guard(x) {} +def group_guard(x) : x > 3 {} + +assert_equal(true, with_guard.has_guard()); +assert_equal(false, without_guard.has_guard()); + +assert_equal(2, group_guard.get_contained_functions().size()); +var group = group_guard.get_contained_functions(); + +assert_equal(true, group[0].has_guard()) +assert_equal(false, group[1].has_guard()) + +assert_throws("Function does not have a guard", fun() { group[0].get_guard(); } ); +assert_throws("Function does not have a guard", fun() { without_guard.get_guard(); } ); + +var guard = with_guard.get_guard(); + +assert_equal(false, guard.has_guard()); +assert_throws("Function does not have a guard", fun() { guard.get_guard(); } ); diff --git a/unittests/3.x/function_ordering_test.cpp b/unittests/3.x/function_ordering_test.cpp new file mode 100644 index 0000000..0a9652c --- /dev/null +++ b/unittests/3.x/function_ordering_test.cpp @@ -0,0 +1,38 @@ +// Tests to make sure that the order in which function dispatches occur is correct + +#include + +int test_one(const int &) +{ + return 1; +} + +int test_two(int &) +{ + return 2; +} + +int main() +{ + chaiscript::ChaiScript chai; + chai.eval("def test_fun(x) { return 3; }"); + chai.eval("def test_fun(x) : x == \"hi\" { return 4; }"); + chai.eval("def test_fun(x) { return 5; }"); + chai.add(chaiscript::fun(&test_one), "test_fun"); + chai.add(chaiscript::fun(&test_two), "test_fun"); + + int res1 = chai.eval("test_fun(1)"); + int res2 = chai.eval("var i = 1; test_fun(i)"); + int res3 = chai.eval("test_fun(\"bob\")"); + int res4 = chai.eval("test_fun(\"hi\")"); + + if (res1 == 1 + && res2 == 2 + && res3 == 3 + && res4 == 4 ) + { + return EXIT_SUCCESS; + } else { + return EXIT_FAILURE; + } +} diff --git a/unittests/3.x/function_reassignment.chai b/unittests/3.x/function_reassignment.chai new file mode 100644 index 0000000..2a885fd --- /dev/null +++ b/unittests/3.x/function_reassignment.chai @@ -0,0 +1,3 @@ +var x = `+` +x = `-` +assert_equal(1, x(5,4)) diff --git a/unittests/3.x/functor_cast_test.cpp b/unittests/3.x/functor_cast_test.cpp new file mode 100644 index 0000000..1f6f7ec --- /dev/null +++ b/unittests/3.x/functor_cast_test.cpp @@ -0,0 +1,25 @@ +#include + +double test_call(const boost::function &f, int val) +{ + return f(val); +} + +int main() +{ + + chaiscript::ChaiScript chai; + + chai.add(chaiscript::fun(&test_call), "test_call"); + + chai.eval("def func(i) { return i * 3.5; };"); + double d = chai.eval("test_call(func, 3)"); + + if (d == 3 * 3.5) + { + return EXIT_SUCCESS; + } else { + return EXIT_FAILURE; + } + +} diff --git a/unittests/3.x/functor_creation_test.cpp b/unittests/3.x/functor_creation_test.cpp new file mode 100644 index 0000000..6578a6d --- /dev/null +++ b/unittests/3.x/functor_creation_test.cpp @@ -0,0 +1,26 @@ +#include + +int main() +{ + + chaiscript::ChaiScript chai; + + chai.eval("def func() { print(\"Hello World\"); } "); + + boost::function f = chai.eval >("func"); + f(); + + if (chai.eval >("to_string")(6) != "6") + { + return EXIT_FAILURE; + } + + if (chai.eval >("to_string")(chaiscript::var(6)) == "6") + { + return EXIT_SUCCESS; + } else { + return EXIT_FAILURE; + } + + +} diff --git a/unittests/3.x/generate_range.chai b/unittests/3.x/generate_range.chai new file mode 100644 index 0000000..9e25970 --- /dev/null +++ b/unittests/3.x/generate_range.chai @@ -0,0 +1 @@ +assert_equal([1,2,3,4,5,6,7,8,9,10], generate_range(1, 10)) diff --git a/unittests/3.x/global_const_in_module.chai b/unittests/3.x/global_const_in_module.chai new file mode 100644 index 0000000..c9ca65a --- /dev/null +++ b/unittests/3.x/global_const_in_module.chai @@ -0,0 +1,7 @@ +load_module("test_module") + + +assert_equal(to_int(TestValue1), 1) + +assert_equal(TestValue1.type_name(), "TestEnum") + diff --git a/unittests/3.x/if.chai b/unittests/3.x/if.chai new file mode 100644 index 0000000..3ec7321 --- /dev/null +++ b/unittests/3.x/if.chai @@ -0,0 +1,7 @@ +var t = false; + +if (true) { + t = true; +} + +assert_equal(true, t); diff --git a/unittests/3.x/if_else.chai b/unittests/3.x/if_else.chai new file mode 100644 index 0000000..8cb42db --- /dev/null +++ b/unittests/3.x/if_else.chai @@ -0,0 +1,13 @@ +var i = 3 +var b1 = false; +var b2 = false; + +if (i == 2) { + b1 = true; +} +else { + b2 = true; +} + +assert_equal(false, b1); +assert_equal(true, b2); diff --git a/unittests/3.x/if_elseif.chai b/unittests/3.x/if_elseif.chai new file mode 100644 index 0000000..75b85b5 --- /dev/null +++ b/unittests/3.x/if_elseif.chai @@ -0,0 +1,18 @@ +var b1 = false; +var b2 = false; +var b3 = false; + +var i = 3 +if (i == 2) { + b1 = true; +} +else if (i == 4) { + b2 = true; +} +else if (i == 3) { + b3 = true; +} + +assert_equal(false, b1); +assert_equal(false, b2); +assert_equal(true, b3); diff --git a/unittests/3.x/if_elseif_else.chai b/unittests/3.x/if_elseif_else.chai new file mode 100644 index 0000000..26ed0d2 --- /dev/null +++ b/unittests/3.x/if_elseif_else.chai @@ -0,0 +1,14 @@ +var i = 3 +var b = false +if (i == 2) { + assert_equal(false, true) +} +else if (i == 4) { + assert_equal(false, true) +} +else { + assert_equal(true, true) + b = true +} + +assert_equal(true, b) diff --git a/unittests/3.x/index_operator.chai b/unittests/3.x/index_operator.chai new file mode 100644 index 0000000..e8af5cf --- /dev/null +++ b/unittests/3.x/index_operator.chai @@ -0,0 +1,10 @@ + +// tests more complex parses of the index operator + +def Bob::bob3() { return [1,2,3]; } +def Bob::Bob() {} +var b = Bob(); + + +assert_equal(b.bob3()[0], 1); +assert_equal((b.bob3())[1], 2); diff --git a/unittests/3.x/inheritance.chai b/unittests/3.x/inheritance.chai new file mode 100644 index 0000000..1fcd346 --- /dev/null +++ b/unittests/3.x/inheritance.chai @@ -0,0 +1,8 @@ +load_module("test_module") + +var t0 = TestBaseType() +var t = TestDerivedType(); + +assert_equal(t0.func(), 0); +assert_equal(t.func(), 1); + diff --git a/unittests/3.x/instring_eval.chai b/unittests/3.x/instring_eval.chai new file mode 100644 index 0000000..a72b2fc --- /dev/null +++ b/unittests/3.x/instring_eval.chai @@ -0,0 +1,3 @@ +var bob = 5.5 +assert_equal("5.5", "${bob}") +assert_equal("val: 8 and 8", "val: ${5.5 + 2.5} and ${bob + 2.5}") diff --git a/unittests/3.x/instring_eval_more.chai b/unittests/3.x/instring_eval_more.chai new file mode 100644 index 0000000..17768f8 --- /dev/null +++ b/unittests/3.x/instring_eval_more.chai @@ -0,0 +1,4 @@ +assert_equal("\$ {4 + 5}", "$ {4 + 5}") +assert_equal("\$9", "$${4+5}") +assert_equal("Value: \${4 + 5}", "Value: \${4 + 5}") +assert_equal("Value: \$9", "Value: \$${4 + 5}") diff --git a/unittests/3.x/invalid_function_assignment.chai b/unittests/3.x/invalid_function_assignment.chai new file mode 100644 index 0000000..99b098d --- /dev/null +++ b/unittests/3.x/invalid_function_assignment.chai @@ -0,0 +1 @@ +assert_throws("Illegal const function assignment", fun() { clone = `-` } ); diff --git a/unittests/3.x/invalid_function_reassignment.chai b/unittests/3.x/invalid_function_reassignment.chai new file mode 100644 index 0000000..cc7cb5a --- /dev/null +++ b/unittests/3.x/invalid_function_reassignment.chai @@ -0,0 +1 @@ +assert_throws("Invalid function reassignment", fun() { var x = 5; x = `-`; } ); diff --git a/unittests/3.x/is_undef.chai b/unittests/3.x/is_undef.chai new file mode 100644 index 0000000..38572f0 --- /dev/null +++ b/unittests/3.x/is_undef.chai @@ -0,0 +1,4 @@ +var i; +assert_equal(true, i.is_var_undef()); +i = 5; +assert_equal(false, i.is_var_undef()); diff --git a/unittests/3.x/join.chai b/unittests/3.x/join.chai new file mode 100644 index 0000000..1891c46 --- /dev/null +++ b/unittests/3.x/join.chai @@ -0,0 +1 @@ +assert_equal("1*2*3", join([1, 2, 3], "*")) diff --git a/unittests/3.x/lambda.chai b/unittests/3.x/lambda.chai new file mode 100644 index 0000000..6b65a1b --- /dev/null +++ b/unittests/3.x/lambda.chai @@ -0,0 +1,2 @@ +var bob = fun(x) { x + 1 } +assert_equal(4, bob(3)); diff --git a/unittests/3.x/list_push_back.chai b/unittests/3.x/list_push_back.chai new file mode 100644 index 0000000..4d88deb --- /dev/null +++ b/unittests/3.x/list_push_back.chai @@ -0,0 +1,8 @@ +load_module("stl_extra") + +var x = List() +x.push_back(3) +x.push_back("A") + +assert_equal(3, x.front()); +assert_equal("A", x.back()); diff --git a/unittests/3.x/list_push_front.chai b/unittests/3.x/list_push_front.chai new file mode 100644 index 0000000..86e2832 --- /dev/null +++ b/unittests/3.x/list_push_front.chai @@ -0,0 +1,8 @@ +load_module("stl_extra") + +var x = List() +x.push_front(3) +x.push_front("A") + +assert_equal("A", x.front()); +assert_equal(3, x.back()); diff --git a/unittests/3.x/load_module.chai b/unittests/3.x/load_module.chai new file mode 100644 index 0000000..a231a20 --- /dev/null +++ b/unittests/3.x/load_module.chai @@ -0,0 +1,2 @@ +load_module("test_module") +assert_equal("Hello World", hello_world()); diff --git a/unittests/3.x/loop_inner_outer.chai b/unittests/3.x/loop_inner_outer.chai new file mode 100644 index 0000000..64a25e6 --- /dev/null +++ b/unittests/3.x/loop_inner_outer.chai @@ -0,0 +1,9 @@ +var total = 0 + +for (var i = 0; i < 10; ++i) { + for (var j = 0; j < 10; ++j) { + total += 1 + } +} + +assert_equal(100, total); diff --git a/unittests/3.x/malformed_inline_map.chai b/unittests/3.x/malformed_inline_map.chai new file mode 100644 index 0000000..d267bcf --- /dev/null +++ b/unittests/3.x/malformed_inline_map.chai @@ -0,0 +1,2 @@ + +assert_throws("Parse failure", fun() { eval("[\"hello\":5,\"j\",\"k\"]") } ); diff --git a/unittests/3.x/map.chai b/unittests/3.x/map.chai new file mode 100644 index 0000000..a0a31ee --- /dev/null +++ b/unittests/3.x/map.chai @@ -0,0 +1 @@ +assert_equal([true, false, true], map([1,2,3], odd)) diff --git a/unittests/3.x/map_access.chai b/unittests/3.x/map_access.chai new file mode 100644 index 0000000..19ebc1a --- /dev/null +++ b/unittests/3.x/map_access.chai @@ -0,0 +1,2 @@ +var x = ["bob":2, "fred":3] +assert_equal(3, x["fred"]) diff --git a/unittests/3.x/map_inplace_init.chai b/unittests/3.x/map_inplace_init.chai new file mode 100644 index 0000000..b1d8221 --- /dev/null +++ b/unittests/3.x/map_inplace_init.chai @@ -0,0 +1,3 @@ +var x = ["bob":1, "fred":2] + +assert_equal(2, x.size()); diff --git a/unittests/3.x/math_add.chai b/unittests/3.x/math_add.chai new file mode 100644 index 0000000..bcb9036 --- /dev/null +++ b/unittests/3.x/math_add.chai @@ -0,0 +1 @@ +assert_equal(3, (1 + 2)) diff --git a/unittests/3.x/math_add_mixed.chai b/unittests/3.x/math_add_mixed.chai new file mode 100644 index 0000000..b000caf --- /dev/null +++ b/unittests/3.x/math_add_mixed.chai @@ -0,0 +1 @@ +assert_equal(3.5, 1.5 + 2) diff --git a/unittests/3.x/math_dec.chai b/unittests/3.x/math_dec.chai new file mode 100644 index 0000000..e746f29 --- /dev/null +++ b/unittests/3.x/math_dec.chai @@ -0,0 +1,3 @@ +var i = 3 +assert_equal(2, --i) +assert_equal(2, i) diff --git a/unittests/3.x/math_div.chai b/unittests/3.x/math_div.chai new file mode 100644 index 0000000..971f217 --- /dev/null +++ b/unittests/3.x/math_div.chai @@ -0,0 +1 @@ +assert_equal(2, 10/5) diff --git a/unittests/3.x/math_inc.chai b/unittests/3.x/math_inc.chai new file mode 100644 index 0000000..ec317c0 --- /dev/null +++ b/unittests/3.x/math_inc.chai @@ -0,0 +1,3 @@ +var i = 3 +assert_equal(4, ++i) +assert_equal(4, i) diff --git a/unittests/3.x/math_mod.chai b/unittests/3.x/math_mod.chai new file mode 100644 index 0000000..326c35a --- /dev/null +++ b/unittests/3.x/math_mod.chai @@ -0,0 +1 @@ +assert_equal(2, 11 % 3) diff --git a/unittests/3.x/math_mult.chai b/unittests/3.x/math_mult.chai new file mode 100644 index 0000000..94c355d --- /dev/null +++ b/unittests/3.x/math_mult.chai @@ -0,0 +1 @@ +assert_equal(12, 3 * 4) diff --git a/unittests/3.x/math_negate.chai b/unittests/3.x/math_negate.chai new file mode 100644 index 0000000..36bae88 --- /dev/null +++ b/unittests/3.x/math_negate.chai @@ -0,0 +1 @@ +assert_equal(-7, -(3 + 4)) diff --git a/unittests/3.x/math_paren.chai b/unittests/3.x/math_paren.chai new file mode 100644 index 0000000..01b7f20 --- /dev/null +++ b/unittests/3.x/math_paren.chai @@ -0,0 +1 @@ +assert_equal(27, 3*(4+5)) diff --git a/unittests/3.x/math_sub.chai b/unittests/3.x/math_sub.chai new file mode 100644 index 0000000..7e8342c --- /dev/null +++ b/unittests/3.x/math_sub.chai @@ -0,0 +1 @@ +assert_equal(2, 5 - 3) diff --git a/unittests/3.x/max.chai b/unittests/3.x/max.chai new file mode 100644 index 0000000..533e7e8 --- /dev/null +++ b/unittests/3.x/max.chai @@ -0,0 +1 @@ +assert_equal(5, max(3, 5)) diff --git a/unittests/3.x/memberscope.chai b/unittests/3.x/memberscope.chai new file mode 100644 index 0000000..fe46810 --- /dev/null +++ b/unittests/3.x/memberscope.chai @@ -0,0 +1,12 @@ +attr Vector3::x +attr Vector3::y +attr Vector3::z + +def Vector3::Vector3(x, y, z) { + this.x = x + this.y = y + this.z = z +} + +var v = Vector3(1,2,3); +assert_equal(1, v.x); diff --git a/unittests/3.x/method_sugar.chai b/unittests/3.x/method_sugar.chai new file mode 100644 index 0000000..521400b --- /dev/null +++ b/unittests/3.x/method_sugar.chai @@ -0,0 +1 @@ +assert_equal(6, [1, 2, 3].sum()) diff --git a/unittests/3.x/min.chai b/unittests/3.x/min.chai new file mode 100644 index 0000000..0ef1ba7 --- /dev/null +++ b/unittests/3.x/min.chai @@ -0,0 +1 @@ +assert_equal(3, min(3, 5)) diff --git a/unittests/3.x/mmd1.chai b/unittests/3.x/mmd1.chai new file mode 100644 index 0000000..ff38a3c --- /dev/null +++ b/unittests/3.x/mmd1.chai @@ -0,0 +1,20 @@ +def bob(x, y, z) { + x + y + z +} + +def bob(x, y) { + x - y +} + +def bob(x) { + -x +} + +def bob() { + 10 +} + +assert_equal(10, bob()) +assert_equal(-5, bob(5)) +assert_equal(-1, bob(5,6)) +assert_equal(18, bob(5,6,7)) diff --git a/unittests/3.x/mmd2.chai b/unittests/3.x/mmd2.chai new file mode 100644 index 0000000..1c5f177 --- /dev/null +++ b/unittests/3.x/mmd2.chai @@ -0,0 +1,9 @@ +def bob(x, y) : x > 10 { x - y } + +def bob(x, y) : x > 5 { x - y + 10 } + +def bob(x, y) { x + y } + +assert_equal(7, bob(3,4)) +assert_equal(9, bob(6,7)) +assert_equal(-1, bob(11,12)) diff --git a/unittests/3.x/multifile_test_chai.cpp b/unittests/3.x/multifile_test_chai.cpp new file mode 100644 index 0000000..57b8952 --- /dev/null +++ b/unittests/3.x/multifile_test_chai.cpp @@ -0,0 +1,12 @@ +#include "multifile_test_chai.hpp" + +Multi_Test_Chai::Multi_Test_Chai() + : m_chai(new chaiscript::ChaiScript()) +{ +} + + +boost::shared_ptr Multi_Test_Chai::get_chai() +{ + return m_chai; +} diff --git a/unittests/3.x/multifile_test_chai.hpp b/unittests/3.x/multifile_test_chai.hpp new file mode 100644 index 0000000..430b6bc --- /dev/null +++ b/unittests/3.x/multifile_test_chai.hpp @@ -0,0 +1,14 @@ +#include + +class Multi_Test_Chai +{ + public: + Multi_Test_Chai(); + + boost::shared_ptr get_chai(); + + private: + boost::shared_ptr m_chai; +}; + + diff --git a/unittests/3.x/multifile_test_main.cpp b/unittests/3.x/multifile_test_main.cpp new file mode 100644 index 0000000..8352ec8 --- /dev/null +++ b/unittests/3.x/multifile_test_main.cpp @@ -0,0 +1,14 @@ +#include "multifile_test_chai.hpp" +#include "multifile_test_module.hpp" + +#include + +int main() +{ + Multi_Test_Chai chaitest; + Multi_Test_Module chaimodule; + + boost::shared_ptr chai = chaitest.get_chai(); + chai->add(chaimodule.get_module()); + return chai->eval("get_module_value()"); +} diff --git a/unittests/3.x/multifile_test_module.cpp b/unittests/3.x/multifile_test_module.cpp new file mode 100644 index 0000000..2457416 --- /dev/null +++ b/unittests/3.x/multifile_test_module.cpp @@ -0,0 +1,21 @@ +#include + +#include "multifile_test_module.hpp" + +Multi_Test_Module::Multi_Test_Module() +{ +} + +int Multi_Test_Module::get_module_value() +{ + return 0; +} + +chaiscript::ModulePtr Multi_Test_Module::get_module() +{ + chaiscript::ModulePtr module(new chaiscript::Module()); + + module->add(chaiscript::fun(&Multi_Test_Module::get_module_value), "get_module_value"); + + return module; +} diff --git a/unittests/3.x/multifile_test_module.hpp b/unittests/3.x/multifile_test_module.hpp new file mode 100644 index 0000000..f01d8f1 --- /dev/null +++ b/unittests/3.x/multifile_test_module.hpp @@ -0,0 +1,11 @@ +#include + +class Multi_Test_Module +{ + public: + static int get_module_value(); + + Multi_Test_Module(); + + chaiscript::ModulePtr get_module(); +}; diff --git a/unittests/3.x/multiline.chai b/unittests/3.x/multiline.chai new file mode 100644 index 0000000..f13be4e --- /dev/null +++ b/unittests/3.x/multiline.chai @@ -0,0 +1,9 @@ +var x = [1, 2, + 3, 4] + +assert_equal(1, x[0]) + +var y = map(x, + fun(x) { x + 1 }) + +assert_equal(2, y[0]) diff --git a/unittests/3.x/number_formats.chai b/unittests/3.x/number_formats.chai new file mode 100644 index 0000000..c80ece0 --- /dev/null +++ b/unittests/3.x/number_formats.chai @@ -0,0 +1,3 @@ +assert_equal(10, 012) +assert_equal(31, 0x1f) +assert_equal(3, 0b11) diff --git a/unittests/3.x/object_attr.chai b/unittests/3.x/object_attr.chai new file mode 100644 index 0000000..c2da08e --- /dev/null +++ b/unittests/3.x/object_attr.chai @@ -0,0 +1,6 @@ +attr bob::z +def bob::bob() { this.z = 10 } +var x = bob() +def bob::fred(x) { this.z - x } + +assert_equal(7, x.fred(3)) diff --git a/unittests/3.x/object_attr_same_name.chai b/unittests/3.x/object_attr_same_name.chai new file mode 100644 index 0000000..fa20bac --- /dev/null +++ b/unittests/3.x/object_attr_same_name.chai @@ -0,0 +1,9 @@ +attr bob::z +def bob::bob() { this.z = 10 } + +attr bob2::z +def bob2::bob2() { this.z = 12 } + +var b = bob(); +var b2 = bob2(); + diff --git a/unittests/3.x/object_clone.chai b/unittests/3.x/object_clone.chai new file mode 100644 index 0000000..4659f41 --- /dev/null +++ b/unittests/3.x/object_clone.chai @@ -0,0 +1,11 @@ +attr bob::z +def bob::bob() { } + +var x = bob(); +x.z = 10; + +var y = clone(x); +y.z = 20; + +assert_equal(10, x.z) +assert_equal(20, y.z) diff --git a/unittests/3.x/object_constructor_guards.chai b/unittests/3.x/object_constructor_guards.chai new file mode 100644 index 0000000..f48c00a --- /dev/null +++ b/unittests/3.x/object_constructor_guards.chai @@ -0,0 +1,10 @@ +attr bob::val + +def bob::bob(x) : x < 10 { this.val = "Less Than Ten: " + x.to_string(); } +def bob::bob(x) { this.val = "Any Other Value: " + x.to_string(); } + +var b = bob(12) +var c = bob(3) + +assert_equal("Any Other Value: 12", b.val ) +assert_equal("Less Than Ten: 3", c.val ) diff --git a/unittests/3.x/object_lifetime_test.cpp b/unittests/3.x/object_lifetime_test.cpp new file mode 100644 index 0000000..d59957b --- /dev/null +++ b/unittests/3.x/object_lifetime_test.cpp @@ -0,0 +1,66 @@ +#include + +class Test +{ + public: + Test() + { + ++count(); + } + + Test(const Test &) + { + ++count(); + } + + ~Test() + { + --count(); + } + + static int& count() + { + static int c = 0; + return c; + } +}; + +int main() +{ + chaiscript::ModulePtr m = chaiscript::ModulePtr(new chaiscript::Module()); + + CHAISCRIPT_CLASS( m, + Test, + (Test ()) + (Test (const Test &)), + ((count)) + ); + + chaiscript::ChaiScript chai; + chai.add(m); + chai.add(chaiscript::fun(&Test::count), "count"); + + int count = chai.eval("count()"); + + int count2 = chai.eval("var i = 0; { var t = Test(); } return i;"); + + int count3 = chai.eval("var i = 0; { var t = Test(); i = count(); } return i;"); + + int count4 = chai.eval("var i = 0; { var t = Test(); { var t2 = Test(); i = count(); } } return i;"); + + int count5 = chai.eval("var i = 0; { var t = Test(); { var t2 = Test(); } i = count(); } return i;"); + + int count6 = chai.eval("var i = 0; { var t = Test(); { var t2 = Test(); } } i = count(); return i;"); + + if (count == 0 + && count2 == 0 + && count3 == 1 + && count4 == 2 + && count5 == 1 + && count6 == 0) + { + return EXIT_SUCCESS; + } else { + return EXIT_FAILURE; + } +} diff --git a/unittests/3.x/object_method_guards.chai b/unittests/3.x/object_method_guards.chai new file mode 100644 index 0000000..addc850 --- /dev/null +++ b/unittests/3.x/object_method_guards.chai @@ -0,0 +1,7 @@ +def bob::bob() { } +def bob::fred(e) : e < 10 { assert_equal(true, e<10) } +def bob::fred(e) { assert_equal(true, e >= 10) } + +var b = bob() +b.fred(3) +b.fred(12) diff --git a/unittests/3.x/odd.chai b/unittests/3.x/odd.chai new file mode 100644 index 0000000..dbaf2a0 --- /dev/null +++ b/unittests/3.x/odd.chai @@ -0,0 +1 @@ +assert_equal(false, odd(4)) diff --git a/unittests/3.x/operator_overload.chai b/unittests/3.x/operator_overload.chai new file mode 100644 index 0000000..9bd2eb7 --- /dev/null +++ b/unittests/3.x/operator_overload.chai @@ -0,0 +1,9 @@ +def Bob::`+`(y) { this.x + y.x } +def Bob::Bob() { } +attr Bob::x +var b = Bob() +var c = Bob() +b.x = 4 +c.x = 5 + +assert_equal(9, b+c) diff --git a/unittests/3.x/operator_overload2.chai b/unittests/3.x/operator_overload2.chai new file mode 100644 index 0000000..b4afbe7 --- /dev/null +++ b/unittests/3.x/operator_overload2.chai @@ -0,0 +1,9 @@ +def Bob::Bob() { } +attr Bob::x +def `-`(a, b) : is_type(a, "Bob") && is_type(b, "Bob") { a.x - b.x } +var b = Bob() +var c = Bob() +b.x = 4 +c.x = 5 + +assert_equal(-1, b-c) diff --git a/unittests/3.x/operators_float.chai b/unittests/3.x/operators_float.chai new file mode 100644 index 0000000..931606f --- /dev/null +++ b/unittests/3.x/operators_float.chai @@ -0,0 +1,16 @@ +var i = 1.0; +var j = 2.0; +var k = 3.0; + +assert_equal(3, i + j) +assert_equal(1.0, +i) +assert_equal(-1, i-j) +assert_equal(-1, -i) +assert_equal(1.5, k/j) +assert_equal(6, j*k) + +assert_equal(0, i -= i) +assert_equal(3, j *= 1.5) +assert_equal(1.5, j /= 2) +assert_equal(2.5, j += 1) +assert_throws("No modulus for float", fun() { k % 2 } ); diff --git a/unittests/3.x/operators_int.chai b/unittests/3.x/operators_int.chai new file mode 100644 index 0000000..4627b55 --- /dev/null +++ b/unittests/3.x/operators_int.chai @@ -0,0 +1,31 @@ +var i = 1; +var j = 2; +var k = 3; + +assert_equal(3, i + j); +assert_equal(1, +i); +assert_equal(-1, i - j); +assert_equal(-1, -i); +assert_equal(2, j & k); +assert_equal(-3, ~j); +assert_equal(1, j ^ k); +assert_equal(3, i | j); +assert_equal(2, j / i); +assert_equal(4, i << j); +assert_equal(6, j * k); +assert_equal(1, k % j); +assert_equal(1, j >> i); + +assert_equal(0, i &= 2); +assert_equal(1, j ^= 3); +assert_equal(3, j |= 2); +assert_equal(-1, i -= 1); +assert_equal(6, j <<= 1); +assert_equal(12, j *= 2); +assert_equal(6, j /= 2); +assert_equal(2, j %= 4); +assert_equal(1, j >>= 1); +assert_equal(2, j += 1); +assert_equal(1, --j); +assert_equal(2, ++j); + diff --git a/unittests/3.x/pair.chai b/unittests/3.x/pair.chai new file mode 100644 index 0000000..9b3c804 --- /dev/null +++ b/unittests/3.x/pair.chai @@ -0,0 +1,5 @@ +var p = Pair("Hello", "World") + +assert_equal(p.first, "Hello") +assert_equal(p.second, "World") + diff --git a/unittests/3.x/pointer_passed_to_constructor.chai b/unittests/3.x/pointer_passed_to_constructor.chai new file mode 100644 index 0000000..6495ee3 --- /dev/null +++ b/unittests/3.x/pointer_passed_to_constructor.chai @@ -0,0 +1,8 @@ +load_module("test_module") + +var i = 1; +var t0 = TestBaseType(i); + +var t1 = TestBaseType(get_new_int()) + + diff --git a/unittests/3.x/precedence_1.chai b/unittests/3.x/precedence_1.chai new file mode 100644 index 0000000..a538862 --- /dev/null +++ b/unittests/3.x/precedence_1.chai @@ -0,0 +1 @@ +assert_equal(14, 2 + 3 * 4) diff --git a/unittests/3.x/precedence_2.chai b/unittests/3.x/precedence_2.chai new file mode 100644 index 0000000..27a19d4 --- /dev/null +++ b/unittests/3.x/precedence_2.chai @@ -0,0 +1 @@ +assert_equal(-2, 5 - 4 - 3) diff --git a/unittests/3.x/precedence_3.chai b/unittests/3.x/precedence_3.chai new file mode 100644 index 0000000..6eecbf6 --- /dev/null +++ b/unittests/3.x/precedence_3.chai @@ -0,0 +1 @@ +assert_equal(0, 10 / 5 % 2) diff --git a/unittests/3.x/precedence_eq.chai b/unittests/3.x/precedence_eq.chai new file mode 100644 index 0000000..325d667 --- /dev/null +++ b/unittests/3.x/precedence_eq.chai @@ -0,0 +1,3 @@ +var x = var y = 4 +assert_equal(4, x); +assert_equal(4, y); diff --git a/unittests/3.x/product.chai b/unittests/3.x/product.chai new file mode 100644 index 0000000..03ba3cf --- /dev/null +++ b/unittests/3.x/product.chai @@ -0,0 +1 @@ +assert_equal(24, product([1, 2, 3, 4])) diff --git a/unittests/3.x/range.chai b/unittests/3.x/range.chai new file mode 100644 index 0000000..ddef4f2 --- /dev/null +++ b/unittests/3.x/range.chai @@ -0,0 +1,4 @@ +var x = [1, 2, 3, 4] +var r = range(x) +r.pop_front() +assert_equal(2, r.front()); diff --git a/unittests/3.x/range_back.chai b/unittests/3.x/range_back.chai new file mode 100644 index 0000000..6bf5672 --- /dev/null +++ b/unittests/3.x/range_back.chai @@ -0,0 +1,4 @@ +var x = [1, 2, 3, 4] +var r = range(x) +r.pop_back() +assert_equal(3, r.back()) diff --git a/unittests/3.x/range_contains.chai b/unittests/3.x/range_contains.chai new file mode 100644 index 0000000..28a99b1 --- /dev/null +++ b/unittests/3.x/range_contains.chai @@ -0,0 +1,5 @@ +var v = [1,2,"hi", "world", 5.5] +assert_equal(true, v.contains(5.5)) +assert_equal(false, v.contains(0)) +assert_equal(false, v.contains(1, lt)) +assert_equal(true, v.contains(2, `==`)) diff --git a/unittests/3.x/range_find.chai b/unittests/3.x/range_find.chai new file mode 100644 index 0000000..08045e5 --- /dev/null +++ b/unittests/3.x/range_find.chai @@ -0,0 +1,6 @@ +var v = [2, 1, "Hi", 5.5] +var r = v.find("Hi"); + +assert_equal("Hi", r.front()) +var r2 = v.find(2, `<`); +assert_equal(1, r2.front()); diff --git a/unittests/3.x/range_inplace.chai b/unittests/3.x/range_inplace.chai new file mode 100644 index 0000000..d661f5d --- /dev/null +++ b/unittests/3.x/range_inplace.chai @@ -0,0 +1 @@ +assert_equal([3,4,5,6], [3..6]) diff --git a/unittests/3.x/reduce.chai b/unittests/3.x/reduce.chai new file mode 100644 index 0000000..3b255b3 --- /dev/null +++ b/unittests/3.x/reduce.chai @@ -0,0 +1 @@ +assert_equal(10, reduce([1, 2, 3, 4], `+`)) diff --git a/unittests/3.x/ref_equal.chai b/unittests/3.x/ref_equal.chai new file mode 100644 index 0000000..1dbb90e --- /dev/null +++ b/unittests/3.x/ref_equal.chai @@ -0,0 +1,5 @@ +var i = 3 +var j := i +j = 4 + +assert_equal(4, i) diff --git a/unittests/3.x/reflection_test.chai b/unittests/3.x/reflection_test.chai new file mode 100644 index 0000000..88b39cc --- /dev/null +++ b/unittests/3.x/reflection_test.chai @@ -0,0 +1,37 @@ +load_module("reflection") +var parser := ChaiScript_Parser() +var parse_success = parser.parse("3 + 4", "INPUT") +var a := parser.ast() + +assert_equal(eval(a), 7) + +var childs := a.children.front().children +var node := childs[0] + +var parser2 := ChaiScript_Parser() +parser2.parse("9", "INPUT") + + +a.children.front().replace_child(childs[0], parser2.ast()) + +assert_equal(eval(a), 13) +assert_equal(node.filename, "INPUT") + + + +def my_fun() +{ + return 1; +} + + +assert_equal(true, my_fun.has_parse_tree()); +assert_equal(false, `+`.has_parse_tree()); + +assert_throws("Function does not have a parse tree", fun() { `+`.get_parse_tree(); } ); + +var parsetree := my_fun.get_parse_tree(); + +assert_equal(1, eval(parsetree)); + +print(parsetree.text()); diff --git a/unittests/3.x/retro.chai b/unittests/3.x/retro.chai new file mode 100644 index 0000000..d7f6818 --- /dev/null +++ b/unittests/3.x/retro.chai @@ -0,0 +1,4 @@ +var x = [1, 2, 3, 4] +var r = retro(range(x)) +r.pop_front() +assert_equal(3, r.front()) diff --git a/unittests/3.x/retroretro.chai b/unittests/3.x/retroretro.chai new file mode 100644 index 0000000..09af3ca --- /dev/null +++ b/unittests/3.x/retroretro.chai @@ -0,0 +1,7 @@ +var x = [1, 2, 3, 4] +var r = retro(range(x)) +r.pop_back() +var r2 = retro(r) +r2.pop_front() +assert_equal(2, r.back()) +assert_equal(3, r2.front()) diff --git a/unittests/3.x/return.chai b/unittests/3.x/return.chai new file mode 100644 index 0000000..512f52f --- /dev/null +++ b/unittests/3.x/return.chai @@ -0,0 +1,5 @@ +def sam() { + return 5 +} + +assert_equal(5, sam()) diff --git a/unittests/3.x/runtime_error.chai b/unittests/3.x/runtime_error.chai new file mode 100644 index 0000000..e1e2fc1 --- /dev/null +++ b/unittests/3.x/runtime_error.chai @@ -0,0 +1,11 @@ +var caught = false + +try { + throw(runtime_error("error")) +} +catch(e) { + caught = true + assert_equal("error", e.what()) +} + +assert_equal(true, caught) diff --git a/unittests/3.x/shift.chai b/unittests/3.x/shift.chai new file mode 100644 index 0000000..03f7ea3 --- /dev/null +++ b/unittests/3.x/shift.chai @@ -0,0 +1 @@ +assert_equal(8, 2 << 2) diff --git a/unittests/3.x/short_comparison_test.cpp b/unittests/3.x/short_comparison_test.cpp new file mode 100644 index 0000000..a57e39c --- /dev/null +++ b/unittests/3.x/short_comparison_test.cpp @@ -0,0 +1,29 @@ +#include + +class Test { + public: + Test() : value_(5) {} + + short get_value() { return value_; } + + short value_; +}; + +int main() +{ + + chaiscript::ChaiScript chai; + chai.add(chaiscript::user_type(), "Test"); + chai.add(chaiscript::constructor(), "Test"); + + chai.add(chaiscript::fun(&Test::get_value), "get_value"); + + chai.eval("var t := Test();"); + + if (chai.eval("t.get_value() == 5")) + { + return EXIT_SUCCESS; + } else { + return EXIT_FAILURE; + } +} diff --git a/unittests/3.x/string_charptr.chai b/unittests/3.x/string_charptr.chai new file mode 100644 index 0000000..a3065ce --- /dev/null +++ b/unittests/3.x/string_charptr.chai @@ -0,0 +1,6 @@ +assert_equal(true, "hello".c_str().is_var_const()) +assert_equal("char", "hello".c_str().type_name()) + +assert_equal(true, "hello".data().is_var_const()) +assert_equal("char", "hello".data().type_name()) + diff --git a/unittests/3.x/string_concat.chai b/unittests/3.x/string_concat.chai new file mode 100644 index 0000000..40bf4aa --- /dev/null +++ b/unittests/3.x/string_concat.chai @@ -0,0 +1 @@ +assert_equal("hello, there", "hello, " + "there") diff --git a/unittests/3.x/string_find.chai b/unittests/3.x/string_find.chai new file mode 100644 index 0000000..f2cc1f8 --- /dev/null +++ b/unittests/3.x/string_find.chai @@ -0,0 +1 @@ +assert_equal(3, find("123abab", "ab")) diff --git a/unittests/3.x/string_find_first_not_of.chai b/unittests/3.x/string_find_first_not_of.chai new file mode 100644 index 0000000..4d5fd8d --- /dev/null +++ b/unittests/3.x/string_find_first_not_of.chai @@ -0,0 +1 @@ +assert_equal(2, find_first_not_of("abcd", "abd")) diff --git a/unittests/3.x/string_find_first_of.chai b/unittests/3.x/string_find_first_of.chai new file mode 100644 index 0000000..0200bb2 --- /dev/null +++ b/unittests/3.x/string_find_first_of.chai @@ -0,0 +1 @@ +assert_equal(1, find_first_of("abab", "bec")) diff --git a/unittests/3.x/string_find_last_not_of.chai b/unittests/3.x/string_find_last_not_of.chai new file mode 100644 index 0000000..0090f9f --- /dev/null +++ b/unittests/3.x/string_find_last_not_of.chai @@ -0,0 +1 @@ +assert_equal(3, find_last_not_of("abab", "ac")) diff --git a/unittests/3.x/string_find_last_of.chai b/unittests/3.x/string_find_last_of.chai new file mode 100644 index 0000000..72f0f6a --- /dev/null +++ b/unittests/3.x/string_find_last_of.chai @@ -0,0 +1 @@ +assert_equal(3, find_last_of("abab", "bec")) diff --git a/unittests/3.x/string_init.chai b/unittests/3.x/string_init.chai new file mode 100644 index 0000000..a3d1163 --- /dev/null +++ b/unittests/3.x/string_init.chai @@ -0,0 +1 @@ +print("bob") diff --git a/unittests/3.x/string_literal_access.chai b/unittests/3.x/string_literal_access.chai new file mode 100644 index 0000000..e8943a1 --- /dev/null +++ b/unittests/3.x/string_literal_access.chai @@ -0,0 +1 @@ +assert_equal('b', "abc"[1]) diff --git a/unittests/3.x/string_rfind.chai b/unittests/3.x/string_rfind.chai new file mode 100644 index 0000000..01675f3 --- /dev/null +++ b/unittests/3.x/string_rfind.chai @@ -0,0 +1 @@ +assert_equal(5, rfind("123abab", "ab")) diff --git a/unittests/3.x/sum.chai b/unittests/3.x/sum.chai new file mode 100644 index 0000000..7502ae7 --- /dev/null +++ b/unittests/3.x/sum.chai @@ -0,0 +1 @@ +assert_equal(10, sum([1, 2, 3, 4])) diff --git a/unittests/3.x/take.chai b/unittests/3.x/take.chai new file mode 100644 index 0000000..5110392 --- /dev/null +++ b/unittests/3.x/take.chai @@ -0,0 +1 @@ +assert_equal(2, take([1, 2, 3, 4], 2).back()) diff --git a/unittests/3.x/take_while.chai b/unittests/3.x/take_while.chai new file mode 100644 index 0000000..56a4ba2 --- /dev/null +++ b/unittests/3.x/take_while.chai @@ -0,0 +1 @@ +assert_equal([1], take_while([1, 2, 3, 4], odd)) diff --git a/unittests/3.x/type_info.chai b/unittests/3.x/type_info.chai new file mode 100644 index 0000000..fc2dd3e --- /dev/null +++ b/unittests/3.x/type_info.chai @@ -0,0 +1,11 @@ +assert_equal("string", string_type.name()); +assert_equal(false, string_type.is_type_const()); +assert_equal(false, string_type.is_type_reference()); +assert_equal(false, string_type.is_type_void()); +assert_equal(false, string_type.is_type_undef()); +assert_equal(false, string_type.is_type_pointer()); +assert_equal("string", "string".get_type_info().name()); +assert_equal(true, string_type.bare_equal("string".get_type_info())); + +assert_equal(true, "bob".is_type(string_type)); + diff --git a/unittests/3.x/type_info_test.cpp b/unittests/3.x/type_info_test.cpp new file mode 100644 index 0000000..361be80 --- /dev/null +++ b/unittests/3.x/type_info_test.cpp @@ -0,0 +1,32 @@ +// Tests to make sure that the order in which function dispatches occur is correct + +#include + +void test_type(const chaiscript::Type_Info &ti, bool t_is_const, bool t_is_pointer, bool t_is_reference, bool t_is_void, + bool t_is_undef) +{ + if (ti.is_const() == t_is_const + && ti.is_pointer() == t_is_pointer + && ti.is_reference() == t_is_reference + && ti.is_void() == t_is_void + && ti.is_undef() == t_is_undef) + { + return; + } else { + exit(EXIT_FAILURE); + } +} + + +int main() +{ + test_type(chaiscript::user_type(), false, false, false, true, false); + test_type(chaiscript::user_type(), true, false, false, false, false); + test_type(chaiscript::user_type(), true, false, true, false, false); + test_type(chaiscript::user_type(), false, false, false, false, false); + test_type(chaiscript::user_type(), false, true, false, false, false); + test_type(chaiscript::user_type(), true, true, false, false, false); + test_type(chaiscript::Type_Info(), false, false, false, false, true); + + return EXIT_SUCCESS; +} diff --git a/unittests/3.x/unit_test.inc b/unittests/3.x/unit_test.inc new file mode 100644 index 0000000..d746e7b --- /dev/null +++ b/unittests/3.x/unit_test.inc @@ -0,0 +1,53 @@ +def assert_equal(x, y) +{ + if (x == y) + { + // Passes + } else { + // Fails + print("assert_equal failure: got " + to_string(y) + " expected " + to_string(x)); + exit(-1); + } +} + +def assert_false(f) +{ + if (f) + { + print("assert_false failure"); + exit(-1); + } +} + +def assert_true(f) +{ + if (!f) + { + print("assert_false failure"); + exit(-1); + } +} + +def assert_not_equal(x, y) +{ + if (!(x == y)) + { + // Passes + } else { + // Fails + print("assert_not_equal failure: got " + to_string(y) + " which was not expected."); + exit(-1); + } +} + +def assert_throws(desc, x) +{ + if (throws_exception(x)) + { + // Passes + } else { + // Fails + print("assert_throws failure, function did not throw exception: " + to_string(desc)); + exit(-1); + } +} diff --git a/unittests/3.x/use.chai b/unittests/3.x/use.chai new file mode 100644 index 0000000..efd587d --- /dev/null +++ b/unittests/3.x/use.chai @@ -0,0 +1,9 @@ +use("use.inc") + +assert_equal("hello", greet()) + +// Include it a second time and see if there are any errors +use("use.inc") + +assert_equal("hello", greet()) + diff --git a/unittests/3.x/use.inc b/unittests/3.x/use.inc new file mode 100644 index 0000000..204cec4 --- /dev/null +++ b/unittests/3.x/use.inc @@ -0,0 +1,4 @@ +def greet { + return("hello") +} + diff --git a/unittests/3.x/utility_test.cpp b/unittests/3.x/utility_test.cpp new file mode 100644 index 0000000..bcd3240 --- /dev/null +++ b/unittests/3.x/utility_test.cpp @@ -0,0 +1,42 @@ +#include + +class Test +{ + public: + void function() {} + std::string function2() { return "Function2"; } + void function3() {} + std::string functionOverload(double) { return "double"; } + std::string functionOverload(int) { return "int"; } +}; + +int main() +{ + + chaiscript::ModulePtr m = chaiscript::ModulePtr(new chaiscript::Module()); + + CHAISCRIPT_CLASS( m, + Test, + (Test ()) + (Test (const Test &)), + ((function)) + ((function2)) + ((function3)) + ((functionOverload)(std::string (Test::*)(double))) + ((functionOverload)(std::string (Test::*)(int))) + ((operator=)) + ); + + chaiscript::ChaiScript chai; + chai.add(m); + if (chai.eval("var t = Test(); t.function2(); ") == "Function2" + && chai.eval("var t = Test(); t.functionOverload(1); ") == "int" + && chai.eval("var t = Test(); t.functionOverload(1.1); ") == "double") + { + chai.eval("t = Test();"); + return EXIT_SUCCESS; + } else { + return EXIT_FAILURE; + } + +} diff --git a/unittests/3.x/vector_access.chai b/unittests/3.x/vector_access.chai new file mode 100644 index 0000000..34d483c --- /dev/null +++ b/unittests/3.x/vector_access.chai @@ -0,0 +1,2 @@ +var x = [1, 2, 3] +assert_equal(3, x[2]) diff --git a/unittests/3.x/vector_erase_at.chai b/unittests/3.x/vector_erase_at.chai new file mode 100644 index 0000000..9a96218 --- /dev/null +++ b/unittests/3.x/vector_erase_at.chai @@ -0,0 +1,3 @@ +var x = [1, 2, 3] +x.erase_at(1) +assert_equal([1,3], x); diff --git a/unittests/3.x/vector_inplace_init.chai b/unittests/3.x/vector_inplace_init.chai new file mode 100644 index 0000000..f16c15b --- /dev/null +++ b/unittests/3.x/vector_inplace_init.chai @@ -0,0 +1,2 @@ +var x = [1, 2, 3] +assert_equal(3, x.size()) diff --git a/unittests/3.x/vector_insert_at.chai b/unittests/3.x/vector_insert_at.chai new file mode 100644 index 0000000..4f6ec45 --- /dev/null +++ b/unittests/3.x/vector_insert_at.chai @@ -0,0 +1,3 @@ +var x = [1, 2, 3] +x.insert_at(1, 6) +assert_equal([1,6,2,3], x); diff --git a/unittests/3.x/vector_literal_acccess.chai b/unittests/3.x/vector_literal_acccess.chai new file mode 100644 index 0000000..29a7c05 --- /dev/null +++ b/unittests/3.x/vector_literal_acccess.chai @@ -0,0 +1 @@ +assert_equal(1, [1,2,3][0]) diff --git a/unittests/3.x/vector_of_one.chai b/unittests/3.x/vector_of_one.chai new file mode 100644 index 0000000..f4bb01b --- /dev/null +++ b/unittests/3.x/vector_of_one.chai @@ -0,0 +1,2 @@ +var x = [1] +assert_equal(1, x[0]) diff --git a/unittests/3.x/vector_paren_literal_access.chai b/unittests/3.x/vector_paren_literal_access.chai new file mode 100644 index 0000000..a0c6b96 --- /dev/null +++ b/unittests/3.x/vector_paren_literal_access.chai @@ -0,0 +1 @@ +assert_equal(1, ([1,2,3])[0]) diff --git a/unittests/3.x/vector_push_back.chai b/unittests/3.x/vector_push_back.chai new file mode 100644 index 0000000..715082b --- /dev/null +++ b/unittests/3.x/vector_push_back.chai @@ -0,0 +1,5 @@ +var x = [1, 2] +x.push_back(3) +assert_equal(3, x.size()) +assert_equal(3, x.back()) +assert_equal(1, x.front()) diff --git a/unittests/3.x/vector_push_empty.chai b/unittests/3.x/vector_push_empty.chai new file mode 100644 index 0000000..29c568d --- /dev/null +++ b/unittests/3.x/vector_push_empty.chai @@ -0,0 +1,4 @@ +var bob = [] +bob.push_back(3) +assert_equal(1, bob.size()) +assert_equal(3, bob.front()) diff --git a/unittests/3.x/zip.chai b/unittests/3.x/zip.chai new file mode 100644 index 0000000..d39583f --- /dev/null +++ b/unittests/3.x/zip.chai @@ -0,0 +1,5 @@ +var z = zip([1, 2, 3], [4, 5, 6]) + +assert_equal([1,4], z[0]) +assert_equal([2,5], z[1]) +assert_equal([3,6], z[2]) diff --git a/unittests/3.x/zip_with.chai b/unittests/3.x/zip_with.chai new file mode 100644 index 0000000..1fe3dd9 --- /dev/null +++ b/unittests/3.x/zip_with.chai @@ -0,0 +1,3 @@ +var z = zip_with(`+`, [1, 2, 3], [4, 5, 6]) + +assert_equal([5,7,9], z) diff --git a/unittests/assign_const.chai b/unittests/assign_const.chai index 7b2ede5..ff6a8c3 100644 --- a/unittests/assign_const.chai +++ b/unittests/assign_const.chai @@ -1,2 +1,2 @@ -assert_throws("Mismatched types in equation, lhs is const.", []() { 1 = 2 } ); -assert_throws("Mismatched types in equation, lhs is const.", []() { 1 + 2 = 2 } ); +assert_throws("Mismatched types in equation, lhs is const.", fun() { 1 = 2 } ); +assert_throws("Mismatched types in equation, lhs is const.", fun() { 1 + 2 = 2 } ); diff --git a/unittests/bind.chai b/unittests/bind.chai index d89d66d..a3af300 100644 --- a/unittests/bind.chai +++ b/unittests/bind.chai @@ -1,2 +1,2 @@ auto prod = bind(foldl, _, `*`, 1.0) -assert_equal(60, prod({3, 4, 5})) +assert_equal(60, prod([3, 4, 5])) diff --git a/unittests/concat.chai b/unittests/concat.chai index 4b897b7..53950a6 100644 --- a/unittests/concat.chai +++ b/unittests/concat.chai @@ -1,4 +1,4 @@ -auto v = concat({1, 2}, {3, 4}); +auto v = concat([1, 2], [3, 4]); assert_equal(4, v.size()); assert_equal(1, v[0]); diff --git a/unittests/const_range_test.chai b/unittests/const_range_test.chai index d8840f3..044c13d 100644 --- a/unittests/const_range_test.chai +++ b/unittests/const_range_test.chai @@ -1,4 +1,3 @@ //If the following succeeds, the test passes - -"Hello World".for_each([](x) { print(x) } ) +"Hello World".for_each(fun(x) { print(x) } ) diff --git a/unittests/deep_array_lookup.chai b/unittests/deep_array_lookup.chai index d94cb8f..8a86eaa 100644 --- a/unittests/deep_array_lookup.chai +++ b/unittests/deep_array_lookup.chai @@ -1,9 +1,9 @@ -auto a = {1,2,3, {4,5,6} } +auto a = [1,2,3, [4,5,6] ] assert_equal(a[3][0], 4) -def Test::Test() { this.a = {1,2,3}; } +def Test::Test() { this.a = [1,2,3]; } attr Test::a; auto t = Test(); diff --git a/unittests/drop.chai b/unittests/drop.chai index 9758c8f..c64b431 100644 --- a/unittests/drop.chai +++ b/unittests/drop.chai @@ -1 +1 @@ -assert_equal({3,4}, drop({1, 2, 3, 4}, 2)) +assert_equal([3,4], drop([1, 2, 3, 4], 2)) diff --git a/unittests/drop_while.chai b/unittests/drop_while.chai index 6912cf2..08e19f2 100644 --- a/unittests/drop_while.chai +++ b/unittests/drop_while.chai @@ -1 +1 @@ -assert_equal({2, 3}, drop_while({1, 2, 3}, odd)) +assert_equal([2, 3], drop_while([1, 2, 3], odd)) diff --git a/unittests/eval_error.chai b/unittests/eval_error.chai index 54eef2c..b2737a1 100644 --- a/unittests/eval_error.chai +++ b/unittests/eval_error.chai @@ -34,6 +34,6 @@ def while_doing() } } -auto f = []() { while_doing(); } +auto f = fun() { while_doing(); } assert_equal(get_eval_error(f).call_stack.size(), 16) diff --git a/unittests/exception_guards.chai b/unittests/exception_guards.chai index 2c2ec09..1279298 100644 --- a/unittests/exception_guards.chai +++ b/unittests/exception_guards.chai @@ -1,4 +1,4 @@ -auto results = {}; +auto results = []; for (auto i = 2; i < 6; ++i) { try { @@ -31,4 +31,4 @@ catch { results.push_back("defaultcatch"); } -assert_equal({"c2: 2", "c2: 3", "c3: 4", "c3: 5", "defaultcatch"}, results); +assert_equal(["c2: 2", "c2: 3", "c3: 4", "c3: 5", "defaultcatch"], results); diff --git a/unittests/filter.chai b/unittests/filter.chai index 2b8b43a..6d805fe 100644 --- a/unittests/filter.chai +++ b/unittests/filter.chai @@ -1 +1 @@ -assert_equal({1,3}, filter({1, 2, 3, 4}, odd)) +assert_equal([1,3], filter([1, 2, 3, 4], odd)) diff --git a/unittests/foldl.chai b/unittests/foldl.chai index 25de4f3..7e9db51 100644 --- a/unittests/foldl.chai +++ b/unittests/foldl.chai @@ -1 +1 @@ -assert_equal(10, foldl({1, 2, 3, 4}, `+`, 0)) +assert_equal(10, foldl([1, 2, 3, 4], `+`, 0)) diff --git a/unittests/for.chai b/unittests/for.chai index e4ae118..c576999 100644 --- a/unittests/for.chai +++ b/unittests/for.chai @@ -1,7 +1,7 @@ -auto ret = {} +auto ret = [] for (auto i = 0; i < 5; ++i) { ret.push_back(i); } -assert_equal({0,1,2,3,4}, ret); +assert_equal([0,1,2,3,4], ret); diff --git a/unittests/for_each.chai b/unittests/for_each.chai index 0a8d737..242a1ba 100644 --- a/unittests/for_each.chai +++ b/unittests/for_each.chai @@ -1 +1 @@ -for_each({1, 2, 3}, print) +for_each([1, 2, 3], print) diff --git a/unittests/for_each_range.chai b/unittests/for_each_range.chai index 7af3025..3a92641 100644 --- a/unittests/for_each_range.chai +++ b/unittests/for_each_range.chai @@ -1,3 +1,3 @@ -auto v = {1,2,3}; +auto v = [1,2,3]; auto r = range(v); -for_each(r, [](x) { assert_equal(true, x>0); } ) +for_each(r, fun(x) { assert_equal(true, x>0); } ) diff --git a/unittests/for_each_retro.chai b/unittests/for_each_retro.chai index 816d30f..4cd0ff5 100644 --- a/unittests/for_each_retro.chai +++ b/unittests/for_each_retro.chai @@ -1,4 +1,4 @@ // Don't bother checking the output from this one, just makes sure it executes -auto v = {1,2,3}; +auto v = [1,2,3]; auto r = retro(range(v)); for_each(r, print) diff --git a/unittests/function_introspection.chai b/unittests/function_introspection.chai index e58beb6..6d808df 100644 --- a/unittests/function_introspection.chai +++ b/unittests/function_introspection.chai @@ -18,7 +18,7 @@ assert_equal(test_function, test_function); assert_not_equal(test_function, `+`); -assert_equal(test_function.call({1}), 1); +assert_equal(test_function.call([1]), 1); // dynamic object function tests @@ -67,10 +67,10 @@ auto group = group_guard.get_contained_functions(); assert_equal(true, group[0].has_guard()) assert_equal(false, group[1].has_guard()) -assert_throws("Function does not have a guard", []() { group[0].get_guard(); } ); -assert_throws("Function does not have a guard", []() { without_guard.get_guard(); } ); +assert_throws("Function does not have a guard", fun() { group[0].get_guard(); } ); +assert_throws("Function does not have a guard", fun() { without_guard.get_guard(); } ); auto guard = with_guard.get_guard(); assert_equal(false, guard.has_guard()); -assert_throws("Function does not have a guard", []() { guard.get_guard(); } ); +assert_throws("Function does not have a guard", fun() { guard.get_guard(); } ); diff --git a/unittests/generate_range.chai b/unittests/generate_range.chai index 9f729ed..9e25970 100644 --- a/unittests/generate_range.chai +++ b/unittests/generate_range.chai @@ -1 +1 @@ -assert_equal({1,2,3,4,5,6,7,8,9,10}, generate_range(1, 10)) +assert_equal([1,2,3,4,5,6,7,8,9,10], generate_range(1, 10)) diff --git a/unittests/index_operator.chai b/unittests/index_operator.chai index 0b7d770..f807404 100644 --- a/unittests/index_operator.chai +++ b/unittests/index_operator.chai @@ -1,7 +1,7 @@ // tests more complex parses of the index operator -def Bob::bob3() { return {1,2,3}; } +def Bob::bob3() { return [1,2,3]; } def Bob::Bob() {} auto b = Bob(); diff --git a/unittests/invalid_function_assignment.chai b/unittests/invalid_function_assignment.chai index 69ff5ca..99b098d 100644 --- a/unittests/invalid_function_assignment.chai +++ b/unittests/invalid_function_assignment.chai @@ -1 +1 @@ -assert_throws("Illegal const function assignment", []() { clone = `-` } ); +assert_throws("Illegal const function assignment", fun() { clone = `-` } ); diff --git a/unittests/invalid_function_reassignment.chai b/unittests/invalid_function_reassignment.chai index d688a2a..784372a 100644 --- a/unittests/invalid_function_reassignment.chai +++ b/unittests/invalid_function_reassignment.chai @@ -1 +1 @@ -assert_throws("Invalid function reassignment", []() { auto x = 5; x = `-`; } ); +assert_throws("Invalid function reassignment", fun() { auto x = 5; x = `-`; } ); diff --git a/unittests/join.chai b/unittests/join.chai index 4ae6665..1891c46 100644 --- a/unittests/join.chai +++ b/unittests/join.chai @@ -1 +1 @@ -assert_equal("1*2*3", join({1, 2, 3}, "*")) +assert_equal("1*2*3", join([1, 2, 3], "*")) diff --git a/unittests/lambda.chai b/unittests/lambda.chai index f2bd3db..9b717ec 100644 --- a/unittests/lambda.chai +++ b/unittests/lambda.chai @@ -1,2 +1,2 @@ -auto bob = [](x) { x + 1 } +auto bob = fun(x) { x + 1 } assert_equal(4, bob(3)); diff --git a/unittests/malformed_inline_map.chai b/unittests/malformed_inline_map.chai index 1cd8acf..d267bcf 100644 --- a/unittests/malformed_inline_map.chai +++ b/unittests/malformed_inline_map.chai @@ -1,2 +1,2 @@ -assert_throws("Parse failure", []() { eval("{\"hello\":5,\"j\",\"k\"}") } ); +assert_throws("Parse failure", fun() { eval("[\"hello\":5,\"j\",\"k\"]") } ); diff --git a/unittests/map.chai b/unittests/map.chai index 7344f80..a0a31ee 100644 --- a/unittests/map.chai +++ b/unittests/map.chai @@ -1 +1 @@ -assert_equal({true, false, true}, map({1,2,3}, odd)) +assert_equal([true, false, true], map([1,2,3], odd)) diff --git a/unittests/map_access.chai b/unittests/map_access.chai index 1d29123..d544036 100644 --- a/unittests/map_access.chai +++ b/unittests/map_access.chai @@ -1,2 +1,2 @@ -auto x = {"bob":2, "fred":3} +auto x = ["bob":2, "fred":3] assert_equal(3, x["fred"]) diff --git a/unittests/map_inplace_init.chai b/unittests/map_inplace_init.chai index 5806292..1d88494 100644 --- a/unittests/map_inplace_init.chai +++ b/unittests/map_inplace_init.chai @@ -1,3 +1,3 @@ -auto x = {"bob":1, "fred":2} +auto x = ["bob":1, "fred":2] assert_equal(2, x.size()); diff --git a/unittests/method_sugar.chai b/unittests/method_sugar.chai index 97598f9..521400b 100644 --- a/unittests/method_sugar.chai +++ b/unittests/method_sugar.chai @@ -1 +1 @@ -assert_equal(6, {1, 2, 3}.sum()) +assert_equal(6, [1, 2, 3].sum()) diff --git a/unittests/multiline.chai b/unittests/multiline.chai index 52a2912..dfa213c 100644 --- a/unittests/multiline.chai +++ b/unittests/multiline.chai @@ -1,9 +1,9 @@ -auto x = {1, 2, - 3, 4} +auto x = [1, 2, + 3, 4] assert_equal(1, x[0]) auto y = map(x, - [](x) { x + 1 }) + fun(x) { x + 1 }) assert_equal(2, y[0]) diff --git a/unittests/operators_float.chai b/unittests/operators_float.chai index 7dcf629..823d428 100644 --- a/unittests/operators_float.chai +++ b/unittests/operators_float.chai @@ -13,4 +13,4 @@ assert_equal(0, i -= i) assert_equal(3, j *= 1.5) assert_equal(1.5, j /= 2) assert_equal(2.5, j += 1) -assert_throws("No modulous for float", []() { k % 2 } ); +assert_throws("No modulus for float", fun() { k % 2 } ); diff --git a/unittests/product.chai b/unittests/product.chai index f0b9d0a..03ba3cf 100644 --- a/unittests/product.chai +++ b/unittests/product.chai @@ -1 +1 @@ -assert_equal(24, product({1, 2, 3, 4})) +assert_equal(24, product([1, 2, 3, 4])) diff --git a/unittests/range.chai b/unittests/range.chai index cdc5689..97a430b 100644 --- a/unittests/range.chai +++ b/unittests/range.chai @@ -1,4 +1,4 @@ -auto x = {1, 2, 3, 4} +auto x = [1, 2, 3, 4] auto r = range(x) r.pop_front() assert_equal(2, r.front()); diff --git a/unittests/range_back.chai b/unittests/range_back.chai index a493655..b572f94 100644 --- a/unittests/range_back.chai +++ b/unittests/range_back.chai @@ -1,4 +1,4 @@ -auto x = {1, 2, 3, 4} +auto x = [1, 2, 3, 4] auto r = range(x) r.pop_back() assert_equal(3, r.back()) diff --git a/unittests/range_contains.chai b/unittests/range_contains.chai index a5b7705..e79051e 100644 --- a/unittests/range_contains.chai +++ b/unittests/range_contains.chai @@ -1,4 +1,4 @@ -auto v = {1,2,"hi", "world", 5.5} +auto v = [1,2,"hi", "world", 5.5] assert_equal(true, v.contains(5.5)) assert_equal(false, v.contains(0)) assert_equal(false, v.contains(1, lt)) diff --git a/unittests/range_find.chai b/unittests/range_find.chai index e51bc71..1bdb1ba 100644 --- a/unittests/range_find.chai +++ b/unittests/range_find.chai @@ -1,4 +1,4 @@ -auto v = {2, 1, "Hi", 5.5} +auto v = [2, 1, "Hi", 5.5] auto r = v.find("Hi"); assert_equal("Hi", r.front()) diff --git a/unittests/range_inplace.chai b/unittests/range_inplace.chai index ff90a0e..d661f5d 100644 --- a/unittests/range_inplace.chai +++ b/unittests/range_inplace.chai @@ -1 +1 @@ -assert_equal({3,4,5,6}, {3..6}) +assert_equal([3,4,5,6], [3..6]) diff --git a/unittests/reduce.chai b/unittests/reduce.chai index fb347e8..3b255b3 100644 --- a/unittests/reduce.chai +++ b/unittests/reduce.chai @@ -1 +1 @@ -assert_equal(10, reduce({1, 2, 3, 4}, `+`)) +assert_equal(10, reduce([1, 2, 3, 4], `+`)) diff --git a/unittests/reflection_test.chai b/unittests/reflection_test.chai index 231449e..42566bc 100644 --- a/unittests/reflection_test.chai +++ b/unittests/reflection_test.chai @@ -28,7 +28,7 @@ def my_fun() assert_equal(true, my_fun.has_parse_tree()); assert_equal(false, `+`.has_parse_tree()); -assert_throws("Function does not have a parse tree", []() { `+`.get_parse_tree(); } ); +assert_throws("Function does not have a parse tree", fun() { `+`.get_parse_tree(); } ); auto& parsetree = my_fun.get_parse_tree(); diff --git a/unittests/retro.chai b/unittests/retro.chai index 1e8359f..780a06d 100644 --- a/unittests/retro.chai +++ b/unittests/retro.chai @@ -1,4 +1,4 @@ -auto x = {1, 2, 3, 4} +auto x = [1, 2, 3, 4] auto r = retro(range(x)) r.pop_front() assert_equal(3, r.front()) diff --git a/unittests/retroretro.chai b/unittests/retroretro.chai index 8e203cb..36c568c 100644 --- a/unittests/retroretro.chai +++ b/unittests/retroretro.chai @@ -1,4 +1,4 @@ -auto x = {1, 2, 3, 4} +auto x = [1, 2, 3, 4] auto r = retro(range(x)) r.pop_back() auto r2 = retro(r) diff --git a/unittests/sum.chai b/unittests/sum.chai index 5588593..7502ae7 100644 --- a/unittests/sum.chai +++ b/unittests/sum.chai @@ -1 +1 @@ -assert_equal(10, sum({1, 2, 3, 4})) +assert_equal(10, sum([1, 2, 3, 4])) diff --git a/unittests/take.chai b/unittests/take.chai index 06df1cb..5110392 100644 --- a/unittests/take.chai +++ b/unittests/take.chai @@ -1 +1 @@ -assert_equal(2, take({1, 2, 3, 4}, 2).back()) +assert_equal(2, take([1, 2, 3, 4], 2).back()) diff --git a/unittests/take_while.chai b/unittests/take_while.chai index 3bfc1b0..56a4ba2 100644 --- a/unittests/take_while.chai +++ b/unittests/take_while.chai @@ -1 +1 @@ -assert_equal({1}, take_while({1, 2, 3, 4}, odd)) +assert_equal([1], take_while([1, 2, 3, 4], odd)) diff --git a/unittests/vector_access.chai b/unittests/vector_access.chai index 7eaa494..58269a2 100644 --- a/unittests/vector_access.chai +++ b/unittests/vector_access.chai @@ -1,2 +1,2 @@ -auto x = {1, 2, 3} +auto x = [1, 2, 3] assert_equal(3, x[2]) diff --git a/unittests/vector_erase_at.chai b/unittests/vector_erase_at.chai index 3bb77b6..348cd81 100644 --- a/unittests/vector_erase_at.chai +++ b/unittests/vector_erase_at.chai @@ -1,3 +1,3 @@ -auto x = {1, 2, 3} +auto x = [1, 2, 3] x.erase_at(1) -assert_equal({1,3}, x); +assert_equal([1,3], x); diff --git a/unittests/vector_inplace_init.chai b/unittests/vector_inplace_init.chai index 04e0593..7b01cb9 100644 --- a/unittests/vector_inplace_init.chai +++ b/unittests/vector_inplace_init.chai @@ -1,2 +1,2 @@ -auto x = {1, 2, 3} +auto x = [1, 2, 3] assert_equal(3, x.size()) diff --git a/unittests/vector_insert_at.chai b/unittests/vector_insert_at.chai index 9a7fd2b..1b42e1c 100644 --- a/unittests/vector_insert_at.chai +++ b/unittests/vector_insert_at.chai @@ -1,3 +1,3 @@ -auto x = {1, 2, 3} +auto x = [1, 2, 3] x.insert_at(1, 6) -assert_equal({1,6,2,3}, x); +assert_equal([1,6,2,3], x); diff --git a/unittests/vector_literal_acccess.chai b/unittests/vector_literal_acccess.chai index a33a552..29a7c05 100644 --- a/unittests/vector_literal_acccess.chai +++ b/unittests/vector_literal_acccess.chai @@ -1 +1 @@ -assert_equal(1, {1,2,3}[0]) +assert_equal(1, [1,2,3][0]) diff --git a/unittests/vector_of_one.chai b/unittests/vector_of_one.chai index a046e31..2763fc1 100644 --- a/unittests/vector_of_one.chai +++ b/unittests/vector_of_one.chai @@ -1,2 +1,2 @@ -auto x = {1} +auto x = [1] assert_equal(1, x[0]) diff --git a/unittests/vector_paren_literal_access.chai b/unittests/vector_paren_literal_access.chai index f96194e..a0c6b96 100644 --- a/unittests/vector_paren_literal_access.chai +++ b/unittests/vector_paren_literal_access.chai @@ -1 +1 @@ -assert_equal(1, ({1,2,3})[0]) +assert_equal(1, ([1,2,3])[0]) diff --git a/unittests/vector_push_back.chai b/unittests/vector_push_back.chai index f5d81bf..82ba4b4 100644 --- a/unittests/vector_push_back.chai +++ b/unittests/vector_push_back.chai @@ -1,4 +1,4 @@ -auto x = {1, 2} +auto x = [1, 2] x.push_back(3) assert_equal(3, x.size()) assert_equal(3, x.back()) diff --git a/unittests/vector_push_empty.chai b/unittests/vector_push_empty.chai index a279eea..4cb7afe 100644 --- a/unittests/vector_push_empty.chai +++ b/unittests/vector_push_empty.chai @@ -1,4 +1,4 @@ -auto bob = {} +auto bob = [] bob.push_back(3) assert_equal(1, bob.size()) assert_equal(3, bob.front()) diff --git a/unittests/zip.chai b/unittests/zip.chai index a6a8327..6aa5b36 100644 --- a/unittests/zip.chai +++ b/unittests/zip.chai @@ -1,5 +1,5 @@ -auto z = zip({1, 2, 3}, {4, 5, 6}) +auto z = zip([1, 2, 3], [4, 5, 6]) -assert_equal({1,4}, z[0]) -assert_equal({2,5}, z[1]) -assert_equal({3,6}, z[2]) +assert_equal([1,4], z[0]) +assert_equal([2,5], z[1]) +assert_equal([3,6], z[2]) diff --git a/unittests/zip_with.chai b/unittests/zip_with.chai index 9b23222..ca2665a 100644 --- a/unittests/zip_with.chai +++ b/unittests/zip_with.chai @@ -1,3 +1,3 @@ -auto z = zip_with(`+`, {1, 2, 3}, {4, 5, 6}) +auto z = zip_with(`+`, [1, 2, 3], [4, 5, 6]) -assert_equal({5,7,9}, z) +assert_equal([5,7,9], z)