Skip to content

Add more tests to scolapasta-hex #2598

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 4 commits into from
Jun 11, 2023
Merged

Add more tests to scolapasta-hex #2598

merged 4 commits into from
Jun 11, 2023

Conversation

lopopolo
Copy link
Member

Also add impl<'a, const N: usize> From<&'a [u8; N]> for Hex impl.

I'll let ChatGPT describe the tests we added together.

Test Description

The test_try_encode function tests the try_encode function by encoding a byte slice and asserting that the result matches the expected output.

The test_try_encode_into function tests the try_encode_into function by encoding a byte slice into a pre-allocated String and asserting that the resulting String matches the expected output.

The test_format_into function tests the format_into function by encoding a byte slice into a pre-allocated String using the fmt::Write trait and asserting that the resulting String matches the expected output.

The test_write_into function (enabled only with the std feature) tests the write_into function by encoding a byte slice into a vector of bytes using the io::Write trait and asserting that the resulting vector of bytes matches the expected output.

The test_hex_iterator function tests the Hex iterator by creating an iterator from a string, collecting the elements into a String, and asserting that the resulting String matches the expected output.

Here's a brief overview of the additional tests:

  1. literal_exhaustive: This test iterates over all possible byte values (0 to 255) and checks that the corresponding hex digits are correctly generated.

  2. test_hex_iterator_with_remaining_escaped_byte: This test verifies that the Hex iterator handles a sequence of bytes correctly, even if there is a remaining escaped byte.

  3. test_hex_iterator_empty_after_exhausted: This test ensures that the Hex iterator becomes empty after consuming all the bytes.

  4. test_hex_iterator_not_empty_with_remaining_escaped_byte: This test checks that the Hex iterator is not empty when there are remaining escaped bytes.

  5. test_hex_iterator_not_empty_with_remaining_byte: Similar to the previous test, this one checks that the Hex iterator is not empty when there are remaining unescaped bytes.

  6. test_hex_iterator_empty: This test verifies that the Hex iterator is empty when the input byte slice is empty.

  7. test_hex_iterator_with_single_escaped_byte: This test checks that the Hex iterator correctly handles a sequence with a single escaped byte.

  8. test_hex_iterator_with_multiple_escaped_bytes: This test ensures that the Hex iterator handles multiple escaped bytes correctly.

  9. test_hex_iterator_with_invalid_escape_sequence: This test verifies the behavior of the Hex iterator when an invalid escape sequence is encountered.

  10. test_hex_iterator_with_no_remaining_bytes: This test checks the Hex iterator when there are no remaining bytes after iteration.

  11. test_hex_iterator_with_emoji_sequence: This test validates that the Hex iterator handles an input sequence containing emojis correctly.

  12. test_hex_iterator_with_chinese_hanzi_sequence: Similar to the previous test, this one checks the Hex iterator with a sequence containing Chinese characters.

These tests cover various scenarios and edge cases to ensure the correctness of the Hex iterator implementation.

@lopopolo lopopolo added A-parser Area: Parser implementations. C-quality Category: Refactoring, cleanup, and quality improvements. labels Jun 11, 2023
@lopopolo lopopolo merged commit 3c8bd17 into trunk Jun 11, 2023
@lopopolo lopopolo deleted the lopopolo/hex-tests branch June 11, 2023 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: Parser implementations. C-quality Category: Refactoring, cleanup, and quality improvements.
Development

Successfully merging this pull request may close these issues.

1 participant