aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChad Austin <caustin@gmail.com>2014-03-22 21:10:46 -0700
committerChad Austin <chad@chadaustin.me>2014-03-28 23:56:40 -0700
commit464f4a3cace3eba27c145d347d031930b9630a51 (patch)
treee4ebd41b75ee637d5a774e62e78830dd71d6d212 /tests
parent555cb8207b9b06f86284a88d97a74c43e20469fb (diff)
make val::as<> compatible with asm.js
Diffstat (limited to 'tests')
-rw-r--r--tests/embind/embind.test.js17
-rw-r--r--tests/embind/embind_test.cpp7
2 files changed, 22 insertions, 2 deletions
diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js
index 033b47b5..64b3e889 100644
--- a/tests/embind/embind.test.js
+++ b/tests/embind/embind.test.js
@@ -1939,9 +1939,10 @@ module({
// Let the memory leak test superfixture check that no leaks occurred.
});
- BaseFixture.extend("val::as built-in types", function() {
- test("primitives", function() {
+ BaseFixture.extend("val::as", function() {
+ test("built-ins", function() {
assert.equal(true, cm.val_as_bool(true));
+ assert.equal(false, cm.val_as_bool(false));
assert.equal(127, cm.val_as_char(127));
assert.equal(32767, cm.val_as_short(32767));
assert.equal(65536, cm.val_as_int(65536));
@@ -1959,6 +1960,18 @@ module({
//var ab = cm.val_as_memory_view(new ArrayBuffer(13));
//assert.equal(13, ab.byteLength);
});
+
+ test("value types", function() {
+ var tuple = [1, 2, 3, 4];
+ assert.deepEqual(tuple, cm.val_as_value_array(tuple));
+
+ var struct = {x: 1, y: 2, z: 3, w: 4};
+ assert.deepEqual(struct, cm.val_as_value_object(struct));
+ });
+
+ test("enums", function() {
+ assert.equal(cm.Enum.ONE, cm.val_as_enum(cm.Enum.ONE));
+ });
});
});
diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp
index 6aa543ef..2f78fa2f 100644
--- a/tests/embind/embind_test.cpp
+++ b/tests/embind/embind_test.cpp
@@ -2323,5 +2323,12 @@ EMSCRIPTEN_BINDINGS(val_as) {
function("val_as_string", &val_as<std::string>);
function("val_as_wstring", &val_as<std::wstring>);
function("val_as_val", &val_as<val>);
+
+ function("val_as_value_object", &val_as<StructVector>);
+ function("val_as_value_array", &val_as<TupleVector>);
+
+ function("val_as_enum", &val_as<Enum>);
+
+ // memory_view is always JS -> C++
//function("val_as_memory_view", &val_as<memory_view>);
}