-
Notifications
You must be signed in to change notification settings - Fork 5k
node:assert: preserve partial semantics for TypedArrays, Sets and sparse arrays in partialDeepStrictEqual #34585
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
farm/4e6809c4/partial-deep-strict-equal
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.
+176
−29
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fd04b11
node:assert: preserve partial semantics for TypedArrays, Sets and spa…
robobun 014e86a
[autofix.ci] apply automated fixes
autofix-ci[bot] 9fecba9
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] f64cf6d
test: move partialDeepStrictEqual tests to .test.ts
robobun 1e7b635
[autofix.ci] apply automated fixes
autofix-ci[bot] 07ff6ff
Use isSharedArrayBuffer brand check and drop unused byteLength primor…
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
85 changes: 85 additions & 0 deletions
85
test/js/node/assert/assert-partial-deep-strict-equal.test.ts
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,85 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import assert from "node:assert"; | ||
|
|
||
| describe("assert.partialDeepStrictEqual", () => { | ||
| test("TypedArrays, Buffers and DataViews match the expected bytes as an in-order subsequence", () => { | ||
| assert.partialDeepStrictEqual(new Uint8Array([1, 2, 3]), new Uint8Array([1, 3])); | ||
| assert.partialDeepStrictEqual(new Uint8Array([1, 2, 1, 3]), new Uint8Array([1, 1, 3])); | ||
| assert.partialDeepStrictEqual(new Uint8Array([1, 2, 3]), new Uint8Array([])); | ||
| assert.partialDeepStrictEqual(new Uint16Array([1, 2, 3]), new Uint16Array([1, 3])); | ||
| assert.partialDeepStrictEqual(new Float32Array([1.5, 2.5, 3.5]), new Float32Array([1.5, 3.5])); | ||
| assert.partialDeepStrictEqual(new Float64Array([1, NaN, 3]), new Float64Array([NaN])); | ||
| assert.partialDeepStrictEqual(new BigInt64Array([1n, 2n, 3n]), new BigInt64Array([1n, 3n])); | ||
| assert.partialDeepStrictEqual(Buffer.from([1, 2, 3]), Buffer.from([1, 2])); | ||
| assert.partialDeepStrictEqual(Buffer.from([1, 2, 3]), new Uint8Array([1, 3])); | ||
| assert.partialDeepStrictEqual( | ||
| new DataView(new Uint8Array([1, 2, 3]).buffer), | ||
| new DataView(new Uint8Array([1, 3]).buffer), | ||
| ); | ||
|
|
||
| expect(() => assert.partialDeepStrictEqual(new Uint8Array([1, 2, 3]), new Uint8Array([3, 1]))).toThrow( | ||
| assert.AssertionError, | ||
| ); | ||
| expect(() => assert.partialDeepStrictEqual(new Uint8Array([1, 2, 3]), new Uint8Array([1, 2, 3, 4]))).toThrow( | ||
| assert.AssertionError, | ||
| ); | ||
| expect(() => assert.partialDeepStrictEqual(new Uint8Array([1, 2, 3]), new Int8Array([1, 3]))).toThrow( | ||
| assert.AssertionError, | ||
| ); | ||
| expect(() => | ||
| assert.partialDeepStrictEqual(new Uint8Array([1, 2, 3]), new DataView(new Uint8Array([1, 3]).buffer)), | ||
| ).toThrow(assert.AssertionError); | ||
| }); | ||
|
|
||
| test("ArrayBuffers match the expected bytes as an in-order subsequence", () => { | ||
| assert.partialDeepStrictEqual(new Uint8Array([1, 2, 3]).buffer, new Uint8Array([1, 3]).buffer); | ||
| assert.partialDeepStrictEqual(new SharedArrayBuffer(3), new SharedArrayBuffer(2)); | ||
|
|
||
| expect(() => assert.partialDeepStrictEqual(new Uint8Array([1, 2, 3]).buffer, new Uint8Array([1, 3]))).toThrow( | ||
| assert.AssertionError, | ||
| ); | ||
| expect(() => assert.partialDeepStrictEqual(new Uint8Array([1, 2, 3]), new Uint8Array([1, 3]).buffer)).toThrow( | ||
| assert.AssertionError, | ||
| ); | ||
| expect(() => assert.partialDeepStrictEqual(new ArrayBuffer(3), new SharedArrayBuffer(2))).toThrow( | ||
| assert.AssertionError, | ||
| ); | ||
| }); | ||
|
|
||
| test("Set members are compared with the partial algorithm", () => { | ||
| assert.partialDeepStrictEqual(new Set([{ a: 1, b: 2 }]), new Set([{ a: 1 }])); | ||
| assert.partialDeepStrictEqual(new Set([{ a: 1, b: 2 }, { c: 3 }]), new Set([{ a: 1 }])); | ||
| assert.partialDeepStrictEqual(new Set([[1, 2, 3]]), new Set([[1, 3]])); | ||
| assert.partialDeepStrictEqual(new Set([{ a: 1 }, { a: 1, b: 2 }]), new Set([{ a: 1 }, { a: 1 }])); | ||
| assert.partialDeepStrictEqual(new Set([{ a: 1, nested: { x: 1, y: 2 } }]), new Set([{ nested: { x: 1 } }])); | ||
|
|
||
| expect(() => assert.partialDeepStrictEqual(new Set([{ a: 1 }]), new Set([{ a: 1, b: 2 }]))).toThrow( | ||
| assert.AssertionError, | ||
| ); | ||
| expect(() => assert.partialDeepStrictEqual(new Set([{ a: 1 }]), new Set([{ a: 1 }, { b: 1 }]))).toThrow( | ||
| assert.AssertionError, | ||
| ); | ||
|
|
||
| // Circular Set structures still terminate. | ||
| const a = new Set<object>(); | ||
| a.add({ s: a }); | ||
| const b = new Set<object>(); | ||
| b.add({ s: b }); | ||
| assert.partialDeepStrictEqual(a, b); | ||
| }); | ||
|
|
||
| test("holes in the expected array are skipped", () => { | ||
| assert.partialDeepStrictEqual([1, 2, 3], [, 2]); | ||
| assert.partialDeepStrictEqual([1, 2, 3], [1, , 3]); | ||
| assert.partialDeepStrictEqual([1, 2, 3], [, , ,]); | ||
| assert.partialDeepStrictEqual([1, undefined, 3], [, undefined]); | ||
| assert.partialDeepStrictEqual({ x: [5, 6, 7] }, { x: [, 6] }); | ||
| assert.partialDeepStrictEqual([, 2, 3], [2]); | ||
|
|
||
| // Holes do not relax the length gate. | ||
| expect(() => assert.partialDeepStrictEqual([1, 2, 3], [, , , ,])).toThrow(assert.AssertionError); | ||
| expect(() => assert.partialDeepStrictEqual([1, 2], [, , ,])).toThrow(assert.AssertionError); | ||
| // An explicit undefined in expected does not match a hole in actual. | ||
| expect(() => assert.partialDeepStrictEqual([, 2, 3], [undefined])).toThrow(assert.AssertionError); | ||
| }); | ||
| }); |
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.