-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: improve n-api array func coverage #12890
Conversation
- add coverage for napi_has_element - add coverage for napi_create_array_with_length
The other thing I noticed while adding these tests is that we should probably change size_t for the array length in napi_create_array_with_length to a uint32_t since I think that's the maximum allowed, however I've deferred doing that to a later PR. |
test/addons-napi/test_array/test.js
Outdated
@@ -19,19 +19,26 @@ const array = [ | |||
] | |||
]; | |||
|
|||
assert.strictEqual(test_array.Test(array, array.length + 1), | |||
assert.strictEqual(test_array.TestGetElement(array, array.length + 1), | |||
'Index out of bound!'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally unrelated to this PR, but just wanted to say that this implementation doesn't look correct to me. "Index out of bound!" should be thrown as an Error. As it is, "Index out of bound!" could be a value in the Array.
I think the reasoning here was that the public API would consistently use |
@jasongin based on that explanation we can just leave as is then, although I'll probably check at some point later if that is consistent with how size_t is used elsewhere, particularly when the bit size can be used to help indicate the maximum range. |
@thefourtheye fixed up that part of the test. |
assert.strictEqual(test_array.Test(array, array.length + 1), | ||
'Index out of bound!'); | ||
assert.throws( | ||
() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this arrow function fit on a single line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was keeping it consistent with what I saw most often in tests. For example: test/parallel/test-punycode.js.
test/addons-napi/test_array/test.js
Outdated
() => { | ||
test_array.TestGetElement(array, array.length + 1); | ||
}, | ||
/Index out of bounds!/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you able to make this more strict? We've been moving toward adding ^
, $
, and the error type to the regular expression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops missed that one, will add.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also fixed up the other instance which was there from the existing version of the test.
test/addons-napi/test_array/test.js
Outdated
}); | ||
|
||
|
||
assert.deepStrictEqual(test_array.New(array), array); | ||
|
||
assert(test_array.TestHasElement(array, 0)); | ||
assert.strictEqual(false, test_array.TestHasElement(array, array.length + 1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you switch the argument order to strictEqual()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do.
test/addons-napi/test_array/test.js
Outdated
|
||
assert(test_array.NewWithLength(0) instanceof Array); | ||
assert(test_array.NewWithLength(1) instanceof Array); | ||
assert(test_array.NewWithLength(2 ^ 32 - 1) instanceof Array); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you attempting to do exponentiation here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would need to be (2 ** 32 - 1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, maybe coding at 2am in your hotel room is not always the best idea. Will fix.
@cjihrig pushed commit to address comments. |
CI good landing. |
Landed as 654afa2 |
- add coverage for napi_has_element - add coverage for napi_create_array_with_length PR-URL: #12890 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
- add coverage for napi_has_element - add coverage for napi_create_array_with_length PR-URL: nodejs#12890 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
- add coverage for napi_has_element - add coverage for napi_create_array_with_length PR-URL: nodejs#12890 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
- add coverage for napi_has_element - add coverage for napi_create_array_with_length Backport-PR-URL: #19447 PR-URL: #12890 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test, n-api