Skip to content

Commit

Permalink
test: write tests for Boolean class
Browse files Browse the repository at this point in the history
The new tests cover a part of the basic type conversion from JavaScript
type to native type.

PR-URL: nodejs/node-addon-api#328
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Nicola Del Gobbo <[email protected]>
  • Loading branch information
John French committed Sep 18, 2018
1 parent 41b376b commit 051d988
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/basic_types/boolean.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "napi.h"

using namespace Napi;

Value CreateBoolean(const CallbackInfo& info) {
return Boolean::New(info.Env(), info[0].As<Boolean>().Value());
}

Object InitBasicTypesBoolean(Env env) {
Object exports = Object::New(env);

exports["createBoolean"] = Function::New(env, CreateBoolean);

return exports;
}
14 changes: 14 additions & 0 deletions test/basic_types/boolean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'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);
}
2 changes: 2 additions & 0 deletions test/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 InitBigInt(Env env);
Expand All @@ -25,6 +26,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("bigint", InitBigInt(env));
Expand Down
1 change: 1 addition & 0 deletions test/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'sources': [
'arraybuffer.cc',
'asyncworker.cc',
'basic_types/boolean.cc',
'basic_types/number.cc',
'basic_types/value.cc',
'bigint.cc',
Expand Down
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ process.config.target_defaults.default_configuration =
let testModules = [
'arraybuffer',
'asyncworker',
'basic_types/boolean',
'basic_types/number',
'basic_types/value',
'bigint',
Expand Down

0 comments on commit 051d988

Please sign in to comment.