Skip to content

Commit

Permalink
Added test for bool operator
Browse files Browse the repository at this point in the history
PR-URL: nodejs/node-addon-api#490
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
kevindavies8 committed Jun 18, 2019
1 parent 74603c9 commit 4b8139b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/basic_types/boolean.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ Value CreateBooleanFromPrimitive(const CallbackInfo& info) {
return Boolean::New(info.Env(), boolean);
}

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

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

exports["createBoolean"] = Function::New(env, CreateBoolean);
exports["createEmptyBoolean"] = Function::New(env, CreateEmptyBoolean);
exports["createBooleanFromExistingValue"] = Function::New(env, CreateBooleanFromExistingValue);
exports["createBooleanFromPrimitive"] = Function::New(env, CreateBooleanFromPrimitive);
exports["operatorBool"] = Function::New(env, OperatorBool);
return exports;
}
6 changes: 6 additions & 0 deletions test/basic_types/boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ function test(binding) {
const bool6 = binding.basic_types_boolean.createBooleanFromPrimitive(false);
assert.strictEqual(bool6, false);

const bool7 = binding.basic_types_boolean.operatorBool(true);
assert.strictEqual(bool7, true);

const bool8 = binding.basic_types_boolean.operatorBool(false);
assert.strictEqual(bool8, false);

}

0 comments on commit 4b8139b

Please sign in to comment.