Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.

Add more tests to scolapasta-hex - #2598

Merged
lopopolo merged 4 commits into
trunkfrom
lopopolo/hex-tests
Jun 11, 2023
Merged

lopopolo merged 4 commits into
trunkfrom
lopopolo/hex-tests

Conversation

@lopopolo

Copy link
Copy Markdown
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 subscribe to this conversation on GitHub. Already have an account? Sign in.

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