Merge branch 'develop' into Fix_Crash_From_CppCon
This commit is contained in:
12
unittests/bool_comparisons.chai
Normal file
12
unittests/bool_comparisons.chai
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
assert_true(true == true)
|
||||
assert_false(true == false)
|
||||
assert_true(true != false)
|
||||
assert_true(false != true)
|
||||
assert_true(false || true)
|
||||
assert_true(true || false)
|
||||
assert_false(true && false)
|
||||
assert_false(false && true)
|
||||
assert_true(!false)
|
||||
assert_false(!true)
|
||||
|
@@ -784,6 +784,23 @@ TEST_CASE("Variable Scope When Calling From C++ 2")
|
||||
CHECK_THROWS(func());
|
||||
}
|
||||
|
||||
void ulonglong(unsigned long long i) {
|
||||
std::cout << i << '\n';
|
||||
}
|
||||
|
||||
|
||||
void longlong(long long i) {
|
||||
std::cout << i << '\n';
|
||||
}
|
||||
|
||||
TEST_CASE("Test long long dispatch")
|
||||
{
|
||||
chaiscript::ChaiScript chai;
|
||||
chai.add(chaiscript::fun(&longlong), "longlong");
|
||||
chai.add(chaiscript::fun(&ulonglong), "ulonglong");
|
||||
chai.eval("longlong(15)");
|
||||
chai.eval("ulonglong(15)");
|
||||
}
|
||||
|
||||
|
||||
struct Returned_Converted_Config
|
||||
|
14
unittests/dynamic_object_dynamic_attrs_explicit.chai
Normal file
14
unittests/dynamic_object_dynamic_attrs_explicit.chai
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
class MyClass {
|
||||
def MyClass()
|
||||
{
|
||||
this.set_explicit(true);
|
||||
}
|
||||
};
|
||||
|
||||
var o = MyClass();
|
||||
|
||||
assert_true(o.is_explicit());
|
||||
|
||||
assert_throws("error", fun[o](){o.x = 2})
|
||||
|
6
unittests/hex_escapes.chai
Normal file
6
unittests/hex_escapes.chai
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
assert_equal("\x39", "9")
|
||||
assert_equal("\x039", "9")
|
||||
assert_equal("\x39g", "9g")
|
||||
assert_equal("b\x39g", "b9g")
|
||||
|
@@ -5,9 +5,10 @@
|
||||
template<typename T>
|
||||
bool test_literal(T val, const std::string &str)
|
||||
{
|
||||
std::cout << "Comparing : " << val;
|
||||
chaiscript::ChaiScript chai;
|
||||
T val2 = chai.eval<T>(str);
|
||||
std::cout << "Comparing : " << val << " " << val2 << '\n';
|
||||
std::cout << " " << val2 << '\n';
|
||||
return val == val2;
|
||||
}
|
||||
|
||||
@@ -74,6 +75,39 @@ int main()
|
||||
&& TEST_LITERAL(177777777777777777)
|
||||
&& TEST_LITERAL(1777777777777777777)
|
||||
|
||||
&& test_literal(0xF, "0b1111")
|
||||
&& test_literal(0xFF, "0b11111111")
|
||||
&& test_literal(0xFFF, "0b111111111111")
|
||||
&& test_literal(0xFFFF, "0b1111111111111111")
|
||||
&& test_literal(0xFFFFF, "0b11111111111111111111")
|
||||
&& test_literal(0xFFFFFF, "0b111111111111111111111111")
|
||||
&& test_literal(0xFFFFFFF, "0b1111111111111111111111111111")
|
||||
&& test_literal(0xFFFFFFFF, "0b11111111111111111111111111111111")
|
||||
&& test_literal(0xFFFFFFFFF, "0b111111111111111111111111111111111111")
|
||||
&& test_literal(0xFFFFFFFFFF, "0b1111111111111111111111111111111111111111")
|
||||
&& test_literal(0xFFFFFFFFFFF, "0b11111111111111111111111111111111111111111111")
|
||||
&& test_literal(0xFFFFFFFFFFFF, "0b111111111111111111111111111111111111111111111111")
|
||||
&& test_literal(0xFFFFFFFFFFFFF, "0b1111111111111111111111111111111111111111111111111111")
|
||||
&& test_literal(0xFFFFFFFFFFFFFF, "0b11111111111111111111111111111111111111111111111111111111")
|
||||
&& test_literal(0xFFFFFFFFFFFFFFF, "0b111111111111111111111111111111111111111111111111111111111111")
|
||||
&& test_literal(0xFFFFFFFFFFFFFFFF, "0b1111111111111111111111111111111111111111111111111111111111111111")
|
||||
|
||||
&& test_literal(0x7, "0b111")
|
||||
&& test_literal(0x7F, "0b1111111")
|
||||
&& test_literal(0x7FF, "0b11111111111")
|
||||
&& test_literal(0x7FFF, "0b111111111111111")
|
||||
&& test_literal(0x7FFFF, "0b1111111111111111111")
|
||||
&& test_literal(0x7FFFFF, "0b11111111111111111111111")
|
||||
&& test_literal(0x7FFFFFF, "0b111111111111111111111111111")
|
||||
&& test_literal(0x7FFFFFFF, "0b1111111111111111111111111111111")
|
||||
&& test_literal(0x7FFFFFFFF, "0b11111111111111111111111111111111111")
|
||||
&& test_literal(0x7FFFFFFFFF, "0b111111111111111111111111111111111111111")
|
||||
&& test_literal(0x7FFFFFFFFFF, "0b1111111111111111111111111111111111111111111")
|
||||
&& test_literal(0x7FFFFFFFFFFF, "0b11111111111111111111111111111111111111111111111")
|
||||
&& test_literal(0x7FFFFFFFFFFFF, "0b111111111111111111111111111111111111111111111111111")
|
||||
&& test_literal(0x7FFFFFFFFFFFFF, "0b1111111111111111111111111111111111111111111111111111111")
|
||||
&& test_literal(0x7FFFFFFFFFFFFFF, "0b11111111111111111111111111111111111111111111111111111111111")
|
||||
&& test_literal(0x7FFFFFFFFFFFFFFF, "0b111111111111111111111111111111111111111111111111111111111111111")
|
||||
)
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
|
3
unittests/json_1.chai
Normal file
3
unittests/json_1.chai
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
assert_true(from_json("null").is_var_null())
|
1
unittests/json_10.chai
Normal file
1
unittests/json_10.chai
Normal file
@@ -0,0 +1 @@
|
||||
assert_equal(from_json("\"This is a\\n\\nMultiline string\""), "This is a\n\nMultiline string")
|
14
unittests/json_11.chai
Normal file
14
unittests/json_11.chai
Normal file
@@ -0,0 +1,14 @@
|
||||
assert_equal(from_json(
|
||||
"{\n" +
|
||||
" \"T1\" : \"Value With a Quote : \\\"\",\n" +
|
||||
" \"T2\" : \"Value With a Rev Solidus : \\/\",\n" +
|
||||
" \"T3\" : \"Value with a Solidus : \\\\\",\n" +
|
||||
" \"T4\" : \"Value with a Backspace : \\b\",\n" +
|
||||
" \"T5\" : \"Value with a Formfeed : \\f\",\n" +
|
||||
" \"T6\" : \"Value with a Newline : \\n\",\n" +
|
||||
" \"T7\" : \"Value with a Carriage Return : \\r\",\n" +
|
||||
" \"T8\" : \"Value with a Horizontal Tab : \\t\"\n" +
|
||||
"}"), [ "T1" : "Value With a Quote : \"", "T2" : "Value With a Rev Solidus : /", "T3" : "Value with a Solidus : \\", "T4" : "Value with a Backspace : \b", "T5" : "Value with a Formfeed : \f", "T6" : "Value with a Newline : \n", "T7" : "Value with a Carriage Return : \r", "T8" : "Value with a Horizontal Tab : \t" ]);
|
||||
|
||||
|
||||
|
1
unittests/json_12.chai
Normal file
1
unittests/json_12.chai
Normal file
@@ -0,0 +1 @@
|
||||
assert_equal(from_json("\"\""), "")
|
1
unittests/json_13.chai
Normal file
1
unittests/json_13.chai
Normal file
@@ -0,0 +1 @@
|
||||
assert_equal(from_json("1.20E+2"), 1.20e2)
|
3
unittests/json_2.chai
Normal file
3
unittests/json_2.chai
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
assert_true(from_json("true"))
|
||||
|
1
unittests/json_3.chai
Normal file
1
unittests/json_3.chai
Normal file
@@ -0,0 +1 @@
|
||||
assert_equal(from_json("100"), 100)
|
1
unittests/json_4.chai
Normal file
1
unittests/json_4.chai
Normal file
@@ -0,0 +1 @@
|
||||
assert_equal(from_json("1.234"), 1.234)
|
1
unittests/json_5.chai
Normal file
1
unittests/json_5.chai
Normal file
@@ -0,0 +1 @@
|
||||
assert_equal(from_json("\"StringTest\""), "StringTest")
|
1
unittests/json_6.chai
Normal file
1
unittests/json_6.chai
Normal file
@@ -0,0 +1 @@
|
||||
assert_equal(from_json("{}"), Map())
|
4
unittests/json_7.chai
Normal file
4
unittests/json_7.chai
Normal file
@@ -0,0 +1,4 @@
|
||||
assert_equal(from_json("\n" +
|
||||
"{\n" +
|
||||
" \"Key\" : \"Value\"\n" +
|
||||
"}\n"), ["Key":"Value"])
|
1
unittests/json_8.chai
Normal file
1
unittests/json_8.chai
Normal file
@@ -0,0 +1 @@
|
||||
assert_equal(from_json("[]"), [])
|
2
unittests/json_9.chai
Normal file
2
unittests/json_9.chai
Normal file
@@ -0,0 +1,2 @@
|
||||
assert_equal(from_json("[1,2,3]"), [1,2,3])
|
||||
|
6
unittests/json_roundtrip.chai
Normal file
6
unittests/json_roundtrip.chai
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
var m = ["a" : 1, "b" : [ 1, 2, 3 ], "c" : [1, "a string", ["d" : 15.4]]]
|
||||
|
||||
assert_equal(from_json(to_json(m)), m)
|
||||
|
||||
|
@@ -2,8 +2,8 @@ assert_equal(true, int_type.bare_equal(1.get_type_info()))
|
||||
assert_equal(true, unsigned_int_type.bare_equal(1u.get_type_info()))
|
||||
assert_equal(true, unsigned_long_type.bare_equal(1lu.get_type_info()))
|
||||
assert_equal(true, long_type.bare_equal(1l.get_type_info()))
|
||||
assert_equal(true, int64_t_type.bare_equal(1ll.get_type_info()))
|
||||
assert_equal(true, uint64_t_type.bare_equal(1ull.get_type_info()))
|
||||
assert_equal(true, long_long_type.bare_equal(1ll.get_type_info()))
|
||||
assert_equal(true, unsigned_long_long_type.bare_equal(1ull.get_type_info()))
|
||||
|
||||
assert_equal(true, double_type.bare_equal(1.6.get_type_info()))
|
||||
assert_equal(true, float_type.bare_equal(1.6f.get_type_info()))
|
||||
|
6
unittests/octal_escapes.chai
Normal file
6
unittests/octal_escapes.chai
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
assert_equal("\71", "9")
|
||||
assert_equal("\071", "9")
|
||||
assert_equal("\71a", "9a")
|
||||
assert_equal("b\71a", "b9a")
|
||||
|
7
unittests/operator_overload3.chai
Normal file
7
unittests/operator_overload3.chai
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
|
||||
def string::`/=`(double d) { this = "${this}/=${d}"; return this; }
|
||||
|
||||
var s = "Hello World"
|
||||
s /= 2
|
||||
|
6
unittests/operator_overload4.chai
Normal file
6
unittests/operator_overload4.chai
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
|
||||
def string::`*`(double d) { return "${this} * ${d}"; }
|
||||
|
||||
"Hello World" * 2
|
||||
|
18
unittests/switch_default_2.chai
Normal file
18
unittests/switch_default_2.chai
Normal file
@@ -0,0 +1,18 @@
|
||||
var total = 0;
|
||||
|
||||
switch(2) {
|
||||
case (1) {
|
||||
total += 1;
|
||||
}
|
||||
default {
|
||||
total += 16;
|
||||
}
|
||||
case (3) {
|
||||
total += 4;
|
||||
}
|
||||
case (4) {
|
||||
total += 8;
|
||||
}
|
||||
}
|
||||
|
||||
assert_equal(total, 28)
|
18
unittests/vector_assignment.chai
Normal file
18
unittests/vector_assignment.chai
Normal file
@@ -0,0 +1,18 @@
|
||||
var v = []
|
||||
v.push_back(3.4);
|
||||
v.push_back(1);
|
||||
v.push_back("bob");
|
||||
|
||||
assert_true(v[0] == 3.4)
|
||||
assert_true(v[1] == 1)
|
||||
assert_true(v[2] == "bob")
|
||||
|
||||
v[0] = 2.9
|
||||
v[1] = 3
|
||||
v[2] = "tom"
|
||||
|
||||
assert_true(v[0] == 2.9)
|
||||
assert_true(v[1] == 3)
|
||||
assert_true(v[2] == "tom")
|
||||
|
||||
|
5
unittests/vector_assignment_3.chai
Normal file
5
unittests/vector_assignment_3.chai
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
var v = []
|
||||
v.push_back(int(1));
|
||||
v[0] = 3;
|
||||
|
Reference in New Issue
Block a user