aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/embind/embind.test.js13
-rw-r--r--tests/embind/embind_test.cpp15
2 files changed, 27 insertions, 1 deletions
diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js
index 5ca972be..67171822 100644
--- a/tests/embind/embind.test.js
+++ b/tests/embind/embind.test.js
@@ -1938,10 +1938,21 @@ module({
derived.delete();
// Let the memory leak test superfixture check that no leaks occurred.
});
+
+ test("val::as supports variety of types", function() {
+ assert.equal(true, cm.val_as_bool(true));
+ assert.equal(127, cm.val_as_char(127));
+ assert.equal(32767, cm.val_as_short(32767));
+ assert.equal(65536, cm.val_as_int(65536));
+ assert.equal(65536, cm.val_as_long(65536));
+ assert.equal(10.5, cm.val_as_float(10.5));
+ assert.equal(10.5, cm.val_as_double(10.5));
+ });
});
/* global run_all_tests */
// If running as part of the emscripten test runner suite, and not as part of the IMVU suite,
// we launch the test execution from here. IMVU suite uses its own dedicated mechanism instead of this.
-if (typeof run_all_tests !== "undefined")
+if (typeof run_all_tests !== "undefined") {
run_all_tests();
+}
diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp
index 4efc4bd8..af8b2e8d 100644
--- a/tests/embind/embind_test.cpp
+++ b/tests/embind/embind_test.cpp
@@ -2304,3 +2304,18 @@ EMSCRIPTEN_BINDINGS(mixins) {
.constructor<>()
);
}
+
+template<typename T>
+T val_as(const val& v) {
+ return v.as<T>();
+}
+
+EMSCRIPTEN_BINDINGS(val_as) {
+ function("val_as_bool", &val_as<bool>);
+ function("val_as_char", &val_as<char>);
+ function("val_as_short", &val_as<short>);
+ function("val_as_int", &val_as<int>);
+ function("val_as_long", &val_as<long>);
+ function("val_as_float", &val_as<float>);
+ function("val_as_double", &val_as<double>);
+}