From 6aa6dfe35fc72c2efe01eca8f9982b3d1855f174 Mon Sep 17 00:00:00 2001 From: Luis Blanco Date: Sun, 29 Mar 2020 22:49:25 +0300 Subject: [PATCH] Use static cast --- include/addon-tools.hpp | 2 +- test/test-hpp-arg.js | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/addon-tools.hpp b/include/addon-tools.hpp index 7850b9b..fe41eb2 100644 --- a/include/addon-tools.hpp +++ b/include/addon-tools.hpp @@ -19,7 +19,7 @@ #define JS_NULL env.Null() #define JS_STR(VAL) Napi::String::New(env, VAL) #define JS_NUM(VAL) Napi::Number::New(env, static_cast(VAL)) -#define JS_EXT(VAL) Napi::External::New(env, (void*)(VAL)) +#define JS_EXT(VAL) Napi::External::New(env, static_cast(VAL)) #define JS_BOOL(VAL) Napi::Boolean::New(env, static_cast(VAL)) #define JS_OBJECT Napi::Object::New(env) #define JS_ARRAY Napi::Array::New(env) diff --git a/test/test-hpp-arg.js b/test/test-hpp-arg.js index b2b5032..ef45187 100644 --- a/test/test-hpp-arg.js +++ b/test/test-hpp-arg.js @@ -6,10 +6,22 @@ const test = require('./build/Release/test.node'); describe('Function arguments', () => { - it('can require 3 args / REQ_ARGS', () => { - expect(test.reqArgs3).to.be.a('function'); - expect(() => test.reqArgs3(1)).to.throw('Expected at least 3 arguments'); - expect(test.reqArgs3(1, 2, 3)).to.be.true; + describe('REQ_ARGS', () => { + it('exports reqArgs3', () => { + expect(test.reqArgs3).to.be.a('function'); + }); + it('throws if no args passed', () => { + expect(() => test.reqArgs3()).to.throw('Expected at least 3 arguments'); + }); + it('throws if 1 arg passed', () => { + expect(() => test.reqArgs3(1)).to.throw('Expected at least 3 arguments'); + }); + it('returns true if 3 args passed', () => { + expect(test.reqArgs3(1, 2, 3)).to.be.true; + }); + it('returns true if 5 args passed', () => { + expect(test.reqArgs3(1, 2, 3, 4, 5)).to.be.true; + }); }); describe('IS_ARG_EMPTY', () => {