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

Support Buffers in Expect Matchers and Pretty Format #15

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

YetAnotherClown
Copy link

@YetAnotherClown YetAnotherClown commented Jul 11, 2024

This Pull Request adds support for comparing buffers using Expect Matchers and adds support for them in Pretty Format, tests are included for buffers in matchers.

To compare buffers, the matchers use:

buffer.tostring(someBuffer) == buffer.tostring(expectedBuffer)

This represents the bytes in the Buffers as a string, which we can then use to determine if the buffers are strictly equal.

As for Pretty Format, it will print out something like buffer { size = 8, data = "0/0/0/0/0/202/182/64" }. This represents the data as numerical representation of bytes. I've also added a matcher hint when comparing buffers that are not nested in a table to suggest first reading from the buffer, as this should be simple enough when not involving large data structures, and it also will result in a more legible output.

I do believe that it is reasonable to pass buffers to matchers when they're apart of large data structures such as objects or arrays which may prove difficult to read through each buffer.

@YetAnotherClown
Copy link
Author

YetAnotherClown commented Jul 11, 2024

I'm keeping this PR as a draft for now as I don't believe snapshots work with these changes, or at the very least work as intended. If I am assuming correctly, Snapshots use Pretty Format. This would be an issue as the format only prints out the size and not the data, meaning any similar sized buffer would match unexpectedly.

I would need to find a way to print the buffer data using Pretty Format. It's not as simple as using buffer.tostring(), as it contains characters that cannot be parsed in json which has proved to break some tooling which isn't ideal.

@YetAnotherClown YetAnotherClown marked this pull request as ready for review July 12, 2024 00:22
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.

1 participant