Skip to content
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

tests(ext/node): Port buffer_test.ts from deno_std #19556

Merged
merged 6 commits into from
Jun 22, 2023

Conversation

fbaltor
Copy link
Contributor

@fbaltor fbaltor commented Jun 20, 2023

This PR port all the tests from deno_std concerning the Node.js Buffer class, improving the coverage of the task #17840.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a brief overview of the test cases presented in the code:

Test Buffer readUIntLE:
This test is checking if the readUIntLE (read Unsigned Int Little Endian) function is working as expected by reading 1-byte, 2-byte, and 4-byte values from a buffer.

Test Buffer copy works as expected:
This test verifies that a buffer copy operation indeed adds a certain target buffer's contents to another buffer and that it reflects the same content changes in the source object.

Test Buffer copy respects the starting point for copy:
This test checks that the copy operation appropriately respects the specified starting point for the copy.

Test Buffer copy doesn't throw on offset but copies until offset reached:
This test ensures that the copy operation does not throw an error if the specified offset is reached but instead actually copies the contents until the offset is reached.

Test Buffer from string creates a Buffer:
This test checks if creating a Buffer from a string works as expected, both in terms of buffer size and content.

Test Buffer from string hex/base64 and Buffer to string hex/base64:
These tests validate that when creating Buffers from strings in different encodings (hex, base64), the resultant Buffers have the appropriate size and content. Similar checks are done when converting Buffers to strings in these encodings.

Test Buffer from string invalid encoding:
This test ensures that a default "utf8" encoding is used when an invalid or unspecified encoding is provided.

Test Buffer from another buffer creates a Buffer:
This test checks if creating a Buffer from another Buffer works as intended.

Test isBuffer returns true/false:
These tests validate that the static function "isBuffer" accurately detects whether an object is a Buffer or not.

Test Buffer toJSON:
This test verifies that a Buffer can be successfully converted to a JSON object.

Test slice does not create a copy:
This test demonstrates that the slice method applied to a Buffer doesn't create a copy.

Test slice with infinity returns empty buffer:
This test checks if slicing a Buffer with the end value set to Infinity returns an empty Buffer.

Test isEncoding returns true/false:
These tests check if the static function "isEncoding" accurately identifies valid/invalid encodings.

Test utf8Write handle missing optional length argument:
This test ensures that the utf8Write function works correctly even when an optional length argument is missing.

If you have any questions about specific test cases, feel free to ask!

@kt3k kt3k mentioned this pull request Jun 22, 2023
55 tasks
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@kt3k kt3k merged commit b319fa7 into denoland:main Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants