From 706003f80018bf27a15a4cf07d26747c1abc2d9a Mon Sep 17 00:00:00 2001 From: Jaeseok Yoon Date: Thu, 6 Sep 2018 09:42:27 +0900 Subject: [PATCH 1/2] Write tests for Boolean class The new tests cover a part of the basic type conversion from JavaScript type to native type. --- test/basic_types/boolean.cc | 15 +++++++++++++++ test/basic_types/boolean.js | 15 +++++++++++++++ test/binding.cc | 2 ++ test/binding.gyp | 1 + test/index.js | 1 + 5 files changed, 34 insertions(+) create mode 100644 test/basic_types/boolean.cc create mode 100644 test/basic_types/boolean.js diff --git a/test/basic_types/boolean.cc b/test/basic_types/boolean.cc new file mode 100644 index 000000000..3ed802bc6 --- /dev/null +++ b/test/basic_types/boolean.cc @@ -0,0 +1,15 @@ +#include "napi.h" + +using namespace Napi; + +Value CreateBoolean(const CallbackInfo& info) { + return Boolean::New(info.Env(), info[0].As().Value()); +} + +Object InitBasicTypesBoolean(Env env) { + Object exports = Object::New(env); + + exports["createBoolean"] = Function::New(env, CreateBoolean); + + return exports; +} diff --git a/test/basic_types/boolean.js b/test/basic_types/boolean.js new file mode 100644 index 000000000..5b030d6b3 --- /dev/null +++ b/test/basic_types/boolean.js @@ -0,0 +1,15 @@ +'use strict'; +const buildType = process.config.target_defaults.default_configuration; +const assert = require('assert'); + +test(require(`../build/${buildType}/binding.node`)); +test(require(`../build/${buildType}/binding_noexcept.node`)); + +function test(binding) { + + const bool1 = binding.basic_types_boolean.createBoolean(true); + assert.strictEqual(bool1, true); + + const bool2 = binding.basic_types_boolean.createBoolean(false); + assert.strictEqual(bool2, false); +} diff --git a/test/binding.cc b/test/binding.cc index 3b4bb7b0a..5e06da4e9 100644 --- a/test/binding.cc +++ b/test/binding.cc @@ -4,6 +4,7 @@ using namespace Napi; Object InitArrayBuffer(Env env); Object InitAsyncWorker(Env env); +Object InitBasicTypesBoolean(Env env); Object InitBasicTypesNumber(Env env); Object InitBasicTypesValue(Env env); Object InitBuffer(Env env); @@ -24,6 +25,7 @@ Object InitObjectReference(Env env); Object Init(Env env, Object exports) { exports.Set("arraybuffer", InitArrayBuffer(env)); exports.Set("asyncworker", InitAsyncWorker(env)); + exports.Set("basic_types_boolean", InitBasicTypesBoolean(env)); exports.Set("basic_types_number", InitBasicTypesNumber(env)); exports.Set("basic_types_value", InitBasicTypesValue(env)); exports.Set("buffer", InitBuffer(env)); diff --git a/test/binding.gyp b/test/binding.gyp index 698eb45b7..25db41b02 100644 --- a/test/binding.gyp +++ b/test/binding.gyp @@ -3,6 +3,7 @@ 'sources': [ 'arraybuffer.cc', 'asyncworker.cc', + 'basic_types/boolean.cc', 'basic_types/number.cc', 'basic_types/value.cc', 'binding.cc', diff --git a/test/index.js b/test/index.js index 5b6bc2cd9..108b2553b 100644 --- a/test/index.js +++ b/test/index.js @@ -10,6 +10,7 @@ process.config.target_defaults.default_configuration = let testModules = [ 'arraybuffer', 'asyncworker', + 'basic_types/boolean', 'basic_types/number', 'basic_types/value', 'buffer', From 7f875a71f5d0e239e54b4cb8784085f64c716ae6 Mon Sep 17 00:00:00 2001 From: Jaeseok Yoon Date: Thu, 6 Sep 2018 10:03:03 +0900 Subject: [PATCH 2/2] Remove unnecessary blank line --- test/basic_types/boolean.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/basic_types/boolean.js b/test/basic_types/boolean.js index 5b030d6b3..3a9c88da8 100644 --- a/test/basic_types/boolean.js +++ b/test/basic_types/boolean.js @@ -6,7 +6,6 @@ test(require(`../build/${buildType}/binding.node`)); test(require(`../build/${buildType}/binding_noexcept.node`)); function test(binding) { - const bool1 = binding.basic_types_boolean.createBoolean(true); assert.strictEqual(bool1, true);