-
-
Notifications
You must be signed in to change notification settings - Fork 620
Add WeakSet edge case tests #4914
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -253,3 +253,6 @@ impl WeakSet { | |
| Ok(set.contains_key(value.inner()).into()) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| use crate::{JsNativeErrorKind, TestAction, run_test_actions}; | ||
|
|
||
| #[test] | ||
| fn weakset_add_and_has() { | ||
| run_test_actions([ | ||
| TestAction::run("var ws = new WeakSet(); var obj = {}; ws.add(obj);"), | ||
| TestAction::assert("ws.has(obj)"), | ||
| ]); | ||
| } | ||
|
|
||
| #[test] | ||
| fn weakset_add_chaining() { | ||
| run_test_actions([ | ||
| TestAction::run("var ws = new WeakSet(); var obj = {};"), | ||
| TestAction::assert("ws.add(obj) === ws"), | ||
| ]); | ||
| } | ||
|
|
||
| #[test] | ||
| fn weakset_delete_behavior() { | ||
| run_test_actions([ | ||
| TestAction::run("var ws = new WeakSet(); var obj = {}; ws.add(obj);"), | ||
| TestAction::assert("ws.delete(obj) === true"), | ||
| TestAction::assert("ws.delete(obj) === false"), | ||
| TestAction::assert("ws.has(obj) === false"), | ||
| ]); | ||
| } | ||
|
|
||
| #[test] | ||
| fn weakset_add_primitive_rejection() { | ||
| run_test_actions([ | ||
| TestAction::run("var ws = new WeakSet();"), | ||
| TestAction::assert_native_error( | ||
| "ws.add(1);", | ||
| JsNativeErrorKind::Type, | ||
| "WeakSet.add: expected target argument of type `object`, got target of type `number`", | ||
| ), | ||
| TestAction::assert_native_error( | ||
| "ws.add('x');", | ||
| JsNativeErrorKind::Type, | ||
| "WeakSet.add: expected target argument of type `object`, got target of type `string`", | ||
| ), | ||
| TestAction::assert_native_error( | ||
| "ws.add(true);", | ||
| JsNativeErrorKind::Type, | ||
| "WeakSet.add: expected target argument of type `object`, got target of type `boolean`", | ||
| ), | ||
| TestAction::assert_native_error( | ||
| "ws.add(null);", | ||
| JsNativeErrorKind::Type, | ||
| "WeakSet.add: expected target argument of type `object`, got target of type `object`", | ||
| ), | ||
| TestAction::assert_native_error( | ||
| "ws.add(undefined);", | ||
| JsNativeErrorKind::Type, | ||
| "WeakSet.add: expected target argument of type `object`, got target of type `undefined`", | ||
| ), | ||
| TestAction::assert_native_error( | ||
| "ws.add(Symbol('id'));", | ||
| JsNativeErrorKind::Type, | ||
| "WeakSet.add: expected target argument of type `object`, got target of type `symbol`", | ||
| ), | ||
| ]); | ||
| } | ||
|
|
||
| #[test] | ||
| fn weakset_has_primitive_returns_false() { | ||
| run_test_actions([ | ||
| TestAction::run("var ws = new WeakSet();"), | ||
| TestAction::assert("ws.has(1) === false"), | ||
| TestAction::assert("ws.has('x') === false"), | ||
| TestAction::assert("ws.has(null) === false"), | ||
| ]); | ||
| } | ||
|
|
||
| #[test] | ||
| fn weakset_delete_primitive_returns_false() { | ||
| run_test_actions([ | ||
| TestAction::run("var ws = new WeakSet();"), | ||
| TestAction::assert("ws.delete(1) === false"), | ||
| TestAction::assert("ws.delete('x') === false"), | ||
| TestAction::assert("ws.delete(null) === false"), | ||
| ]); | ||
| } | ||
|
|
||
| #[test] | ||
| fn weakset_add_duplicate() { | ||
| run_test_actions([ | ||
| TestAction::run("var ws = new WeakSet(); var obj = {}; ws.add(obj);"), | ||
| TestAction::assert("ws.has(obj) === true"), | ||
| TestAction::run("ws.add(obj);"), | ||
| TestAction::assert("ws.has(obj) === true"), | ||
| ]); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The null case asserts an error message where the "got" type is
object(becausetypeof nullis"object"), which makes the message read like there was no type mismatch ("expected object … got object"). This makes the test misleading/brittle and also locks in a confusing engine error string. Consider either (a) updating the WeakSet.add TypeError message to special-casenull(e.g., reportnullexplicitly) and then adjusting this assertion accordingly, or (b) changing this test to assert only that a TypeError is thrown fornullwithout coupling to the exact message text.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.
it's fine, we'll fix it eventually
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.
rn I was working on this fix only should I push it 🙆♂️!?