summaryrefslogtreecommitdiff
path: root/installed-tests/js/testRegress.js
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2021-03-08 22:01:26 +0100
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2021-03-08 22:12:50 +0100
commit255af607ec3dc3e3d7e20738a775800fc50e5b30 (patch)
treeaa1c41ac61a3b7aeca70bcf06f47d36f80ebcf92 /installed-tests/js/testRegress.js
parentd3d365ba7cce1ccacaffab97ef91afe9c494528c (diff)
downloadgjs-255af607ec3dc3e3d7e20738a775800fc50e5b30.tar.gz
testRegress: Verify that undefined can be passed to C functions
When a C function takes integer values an undefined argument should be handled as 0, as expected in JS, if instead the function takes a floating point value the function value is set to NaN. Add tests to ensure we handle undefined in function calls as expected. Fixes: #379
Diffstat (limited to 'installed-tests/js/testRegress.js')
-rw-r--r--installed-tests/js/testRegress.js14
1 files changed, 12 insertions, 2 deletions
diff --git a/installed-tests/js/testRegress.js b/installed-tests/js/testRegress.js
index 56296d94..f067f1a1 100644
--- a/installed-tests/js/testRegress.js
+++ b/installed-tests/js/testRegress.js
@@ -28,10 +28,13 @@ describe('Life, the Universe and Everything', function () {
const method = `test_int${bits}`;
expect(Regress[method](42)).toBe(42);
expect(Regress[method](-42)).toBe(-42);
+ expect(Regress[method](undefined)).toBe(0);
});
it(`includes unsigned ${bits}-bit integers`, function () {
- expect(Regress[`test_uint${bits}`](42)).toBe(42);
+ const method = `test_uint${bits}`;
+ expect(Regress[method](42)).toBe(42);
+ expect(Regress[method](undefined)).toBe(0);
});
});
@@ -40,12 +43,19 @@ describe('Life, the Universe and Everything', function () {
const method = `test_${type}`;
expect(Regress[method](42)).toBe(42);
expect(Regress[method](-42)).toBe(-42);
+
+ if (['float', 'double'].includes(type))
+ expect(Number.isNaN(Regress[method](undefined))).toBeTruthy();
+ else
+ expect(Regress[method](undefined)).toBe(0);
});
});
['ushort', 'uint', 'ulong', 'size'].forEach(type => {
it(`includes ${type}s`, function () {
- expect(Regress[`test_${type}`](42)).toBe(42);
+ const method = `test_${type}`;
+ expect(Regress[method](42)).toBe(42);
+ expect(Regress[method](undefined)).toBe(0);
});
});