diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2021-03-08 22:01:26 +0100 |
|---|---|---|
| committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2021-03-08 22:12:50 +0100 |
| commit | 255af607ec3dc3e3d7e20738a775800fc50e5b30 (patch) | |
| tree | aa1c41ac61a3b7aeca70bcf06f47d36f80ebcf92 /installed-tests/js/testRegress.js | |
| parent | d3d365ba7cce1ccacaffab97ef91afe9c494528c (diff) | |
| download | gjs-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.js | 14 |
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); }); }); |
