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

feat: add support for types from ascii crate #255

Merged
merged 15 commits into from
Nov 13, 2023
Merged

feat: add support for types from ascii crate #255

merged 15 commits into from
Nov 13, 2023

Conversation

mina86
Copy link
Contributor

@mina86 mina86 commented Oct 30, 2023

No description provided.

@mina86 mina86 requested review from frol and dj8yfo as code owners October 30, 2023 20:26
borsh/src/de/mod.rs Outdated Show resolved Hide resolved
borsh/src/ser/mod.rs Outdated Show resolved Hide resolved
borsh/src/schema.rs Outdated Show resolved Hide resolved
borsh/src/schema.rs Outdated Show resolved Hide resolved
borsh/src/de/mod.rs Outdated Show resolved Hide resolved
borsh/src/de/mod.rs Outdated Show resolved Hide resolved

#[cfg(feature = "ascii")]
#[test]
fn test_ascii() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

please change logic and naming of tests:
test_ascii_string_to_ascii_string_roundtrip
test_ascii_str_to_ascii_string_roundtrip
And 2 separate tests for ascii/std-Strings interoperability (which are optional):
test_str_to_ascii_string_maybe_roundtrip
test_ascii_str_to_string_roundtrip.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will definitely not do that.

@dj8yfo dj8yfo changed the title Add support for types from ascii crate feat: add support for types from ascii crate Oct 31, 2023
test_string!(test_hello_10, "hello world!".repeat(30), true);
test_string!(test_hello_1000, "hello world!".repeat(1000), false);
test_string!(test_non_ascii, "💩", true);
test_string!(empty_string, "", true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. please duplicate macro test_string! with test_ascii_string! , so that
    there's a duplicate for each test_string! entry, besides test_string!(non_ascii, "💩", true);
  2. please move all ascii tests to borsh/tests/test_ascii_strings.rs (besides test_string!(non_ascii, "💩", true);)
  3. please move ascii counterpart of test_string!(non_ascii, "💩", true); to borsh/test/test_de_errors.rs , as mentioned in comment.
  4. please split test, generated by test_ascii_string! into 4 tests, mentioned in comment, 2 of which are not mandatory, as borsh library doesn't have to guarantee interoperability of ascii/std strings serializations, though illustrating this aspect is useful.
#![cfg(feature = "ascii")]
...
    test_ascii_string!(a, "a", true);
    test_ascii_string!(hello_world, "hello world", true);
    test_ascii_string!(x_1024, "x".repeat(1024), true);
    test_ascii_string!(x_4096, "x".repeat(4096), false);
    test_ascii_string!(x_65535, "x".repeat(65535), false);
    test_ascii_string!(hello_10, "hello world!".repeat(30), true);
    test_ascii_string!(hello_1000, "hello world!".repeat(1000), false);
...

The problem with proposed solution,

                if let Ok(ascii_str) = ascii::AsciiStr::from_ascii(&value) {
...
                } else {
..
                }

it doesn't set expectations on conversions from specific &str, whether they're gonna fail or not.
The tests should be along the lines of:

    let ascii_str = ascii::AsciiStr::from_ascii($str).unwrap();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

please move all ascii tests to borsh/tests/test_ascii_strings.rs

How is duplicating the same test_string/test_ascii_string invocations in two different files better than keeping it DRY in a single file? You’re asking me to duplicate code for no reason.

borsh/tests/test_strings.rs Outdated Show resolved Hide resolved
borsh/tests/test_strings.rs Outdated Show resolved Hide resolved
borsh/src/schema.rs Outdated Show resolved Hide resolved
.github/test.sh Outdated Show resolved Hide resolved
.github/test.sh Outdated Show resolved Hide resolved
@mina86
Copy link
Contributor Author

mina86 commented Nov 10, 2023

Address all but moving stuff to separate file and duplicating test cases. I’ve no intention of doing that ’cuz it’s silly.

@dj8yfo dj8yfo self-requested a review November 13, 2023 14:54
@dj8yfo dj8yfo merged commit 2d4cf20 into near:master Nov 13, 2023
7 checks passed
@frol frol mentioned this pull request Nov 13, 2023
@mina86 mina86 deleted the a branch November 13, 2023 16:38
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.

2 participants