Skip to content

Commit 14c69ab

Browse files
yjaeseokmhdawson
authored andcommitted
test: write tests for Boolean class
The new tests cover a part of the basic type conversion from JavaScript type to native type. PR-URL: #328 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Nicola Del Gobbo <[email protected]>
1 parent 2ad47a8 commit 14c69ab

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

test/basic_types/boolean.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "napi.h"
2+
3+
using namespace Napi;
4+
5+
Value CreateBoolean(const CallbackInfo& info) {
6+
return Boolean::New(info.Env(), info[0].As<Boolean>().Value());
7+
}
8+
9+
Object InitBasicTypesBoolean(Env env) {
10+
Object exports = Object::New(env);
11+
12+
exports["createBoolean"] = Function::New(env, CreateBoolean);
13+
14+
return exports;
15+
}

test/basic_types/boolean.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
const buildType = process.config.target_defaults.default_configuration;
3+
const assert = require('assert');
4+
5+
test(require(`../build/${buildType}/binding.node`));
6+
test(require(`../build/${buildType}/binding_noexcept.node`));
7+
8+
function test(binding) {
9+
const bool1 = binding.basic_types_boolean.createBoolean(true);
10+
assert.strictEqual(bool1, true);
11+
12+
const bool2 = binding.basic_types_boolean.createBoolean(false);
13+
assert.strictEqual(bool2, false);
14+
}

test/binding.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using namespace Napi;
44

55
Object InitArrayBuffer(Env env);
66
Object InitAsyncWorker(Env env);
7+
Object InitBasicTypesBoolean(Env env);
78
Object InitBasicTypesNumber(Env env);
89
Object InitBasicTypesValue(Env env);
910
Object InitBigInt(Env env);
@@ -25,6 +26,7 @@ Object InitObjectReference(Env env);
2526
Object Init(Env env, Object exports) {
2627
exports.Set("arraybuffer", InitArrayBuffer(env));
2728
exports.Set("asyncworker", InitAsyncWorker(env));
29+
exports.Set("basic_types_boolean", InitBasicTypesBoolean(env));
2830
exports.Set("basic_types_number", InitBasicTypesNumber(env));
2931
exports.Set("basic_types_value", InitBasicTypesValue(env));
3032
exports.Set("bigint", InitBigInt(env));

test/binding.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
'sources': [
44
'arraybuffer.cc',
55
'asyncworker.cc',
6+
'basic_types/boolean.cc',
67
'basic_types/number.cc',
78
'basic_types/value.cc',
89
'bigint.cc',

test/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ process.config.target_defaults.default_configuration =
1010
let testModules = [
1111
'arraybuffer',
1212
'asyncworker',
13+
'basic_types/boolean',
1314
'basic_types/number',
1415
'basic_types/value',
1516
'bigint',

0 commit comments

Comments
 (0)