Repository navigation
bun:test: take a hole of an array for undefined in toMatchObject and Bun.deepMatch #47896
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
Open
robobun
wants to merge
6
commits into
main
Choose a base branch
from
robobun/d910d3c8/deep-match-array-holes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9493c47
bun:test: take a hole of an array for undefined in toMatchObject and …
robobun a21b532
bun-types: say which properties of two arrays Bun.deepMatch compares
robobun 27c9b6c
bun:test: use Expect::is_asymmetric_matcher in the array key step of …
robobun f4a307f
ci: retrigger
robobun 0fb06e0
Merge branch 'main' into robobun/d910d3c8/deep-match-array-holes
robobun fab0b13
bun:test: keep the rule of main for a private name in the array key step
robobun 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
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
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
22 changes: 22 additions & 0 deletions
22
...-comparison-finds-in-private-fields/a-private-field-that-one-list-alone-has/sees_test.mjs
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,22 @@ | ||
| // Guards: two lists match as a whole, and a key that one of them lacks stands for undefined there. A private field is no such key: both lists need it. Plain Bun took a private field that holds undefined for a key that the other list may lack and passed the pair, and an executable, which counts private fields, failed it. | ||
| import { expect, test } from "bun:test"; | ||
| class Bare extends Array {} | ||
| class Unset extends Array { #kept; } | ||
| class Other extends Array { #other; } | ||
| class Two extends Array { #first; #second; } | ||
| class Held extends Array { #kept; static of(kept, ...items) { const list = super.of(...items); list.#kept = kept; return list; } } | ||
| const says = check => { try { return check() === false ? "false" : "passes"; } catch (error) { return error.constructor.name; } }; | ||
| const holed = list => { delete list[0]; return list; }; | ||
| test("one list alone has the field", () => { | ||
| console.log(says(() => expect(Unset.of(1)).toMatchObject([1])), says(() => expect([1]).toMatchObject(Unset.of(1))), says(() => expect(Unset.of(1)).toMatchObject(Bare.of(1))), says(() => expect(Unset.of(1)).toMatchObject(Other.of(1))), says(() => expect(Two.of(1)).toMatchObject(Unset.of(1))), says(() => expect(Unset.of(1)).toMatchObject(Two.of(1)))); | ||
| console.log(says(() => expect(holed(Unset.of(0, 1))).toMatchObject([undefined, 1])), says(() => expect([undefined, 1]).toMatchObject(holed(Unset.of(0, 1)))), says(() => expect(holed(Unset.of(0, 1))).toMatchObject(Other.of(undefined, 1)))); | ||
| console.log(says(() => Bun.deepMatch([1], Unset.of(1))), says(() => Bun.deepMatch(Unset.of(1), [1])), says(() => Bun.deepMatch(Unset.of(1), Other.of(1))), says(() => Bun.deepMatch([undefined, 1], holed(Unset.of(0, 1))))); | ||
| }); | ||
| test("both lists have the field", () => { | ||
| console.log(says(() => expect(Held.of(1, 1)).toMatchObject(Held.of(1, 1))), says(() => expect(Held.of(2, 1)).toMatchObject(Held.of(1, 1))), says(() => expect(Held.of(1, 1)).toMatchObject(Held.of(expect.any(Number), 1)))); | ||
| console.log(says(() => expect(holed(Held.of(1, 0, 1))).toMatchObject(Held.of(1, undefined, 1))), says(() => expect(Held.of(1, undefined, 1)).toMatchObject(holed(Held.of(1, 0, 1)))), says(() => expect(holed(Held.of(2, 0, 1))).toMatchObject(Held.of(1, undefined, 1)))); | ||
| console.log(says(() => Bun.deepMatch(Held.of(1, undefined, 1), holed(Held.of(1, 0, 1)))), says(() => Bun.deepMatch(Held.of(2, undefined, 1), holed(Held.of(1, 0, 1))))); | ||
| }); | ||
| test("objectContaining", () => { | ||
| console.log(says(() => expect(Unset.of(1)).toEqual(expect.objectContaining([1]))), says(() => expect(Unset.of(1)).toEqual(expect.objectContaining(Unset.of(1)))), says(() => expect(Unset.of(1)).toEqual(expect.objectContaining(Other.of(1)))), says(() => expect(holed(Unset.of(0, 1))).toEqual(expect.objectContaining(Unset.of(undefined, 1))))); | ||
| }); |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.