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

More from_str cleanups #5182

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

Conversation

robertbastian
Copy link
Member

sffc
sffc previously approved these changes Jul 4, 2024
Copy link
Member

@sffc sffc left a comment

Choose a reason for hiding this comment

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

You're removing impls from TinyStr wrapper types and instead using direct construction, which seems like a positive change since it avoids an unwrap, despite being more verbose.


impl FromStr for PluralOperands {
#[cfg(feature = "datagen")]
impl core::str::FromStr for PluralOperands {
Copy link
Member

Choose a reason for hiding this comment

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

Discussion: I'm not sure we want impl FromStr for PluralOperands to be cfg(datagen), although I'm fine if we do since we have a way to get this same functionality via fixed_decimal.

Copy link
Member Author

Choose a reason for hiding this comment

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

Users can create plural operands from all numeric types as well as fixed decimal, infallibly.

dbg!("ret={:?}\n---\n", &ret);
ret
let _nstr = fixed_format(n, &opts);
todo!()
Copy link
Member

Choose a reason for hiding this comment

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

🤷

Copy link
Member Author

Choose a reason for hiding this comment

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

what do you want me to do here? I'm tempted to just remove the whole crate

Copy link
Member

Choose a reason for hiding this comment

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

I think endeavor to keep it working. It's not that much code to keep working.

In this case, just change PluralOperands::from_str to FixedDecimal::from_str.

Manishearth
Manishearth previously approved these changes Jul 5, 2024
@robertbastian robertbastian requested a review from sffc July 8, 2024 14:23
dbg!("ret={:?}\n---\n", &ret);
ret
let _nstr = fixed_format(n, &opts);
todo!()
Copy link
Member

Choose a reason for hiding this comment

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

I think endeavor to keep it working. It's not that much code to keep working.

In this case, just change PluralOperands::from_str to FixedDecimal::from_str.

Comment on lines -195 to -227
#[test]
fn format_conversion() {
#[derive(Debug)]
struct TestCase {
n: f64,
opts: Options,
expected: PluralOperands,
}
let tests = [TestCase {
n: 1.5,
opts: Options {
in_type: Type::Cardinal,
minimum_integer_digits: 3,
minimum_fraction_digits: 2,
maximum_fraction_digits: 3,
minimum_significant_digits: 3,
maximum_significant_digits: 4,
},
expected: RawPluralOperands {
i: 1,
v: 2,
w: 1,
f: 50,
t: 5,
c: 0,
}
.into(),
}];
for test in tests {
let actual = to_icu4x_operands(test.n, test.opts.clone());
assert_eq!(test.expected, actual, "test: {:?}", &test);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Please restore the test for to_icu4x_operands

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm it's broken

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants