Skip to content

Commit d749306

Browse files
committed
Move invalid-str tests to impl_trait_from_str
1 parent 7b926e4 commit d749306

File tree

2 files changed

+32
-41
lines changed

2 files changed

+32
-41
lines changed

src/impl_trait_from_str.rs

+32
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,36 @@ mod tests {
4444
impl_case!(case_999d521_939: "999.521_939" => 999521939 E -6);
4545
impl_case!(case_679d35_84_03en2: "679.35_84_03E-2" => 679358403 E -8);
4646
impl_case!(case_271576662d_e4: "271576662.__E4" => 271576662 E 4);
47+
48+
impl_case!(case_1_d_2: "1_._2" => 12 E -1);
49+
}
50+
51+
52+
#[cfg(test)]
53+
mod test_invalid {
54+
use super::*;
55+
56+
macro_rules! impl_case {
57+
($name:ident: $input:literal => $exp:literal) => {
58+
#[test]
59+
#[should_panic(expected = $exp)]
60+
fn $name() {
61+
BigDecimal::from_str($input).unwrap();
62+
}
63+
};
64+
}
65+
66+
impl_case!(case_bad_string_empty : "" => "Empty");
67+
impl_case!(case_bad_string_empty_exponent : "123.123E" => "Empty");
68+
impl_case!(case_bad_string_only_decimal_point : "." => "Empty");
69+
impl_case!(test_bad_string_only_decimal_and_exponent : ".e4" => "Empty");
70+
71+
impl_case!(test_bad_string_only_decimal_and_underscore : "_._" => "InvalidDigit");
72+
73+
impl_case!(case_bad_string_hello : "hello" => "InvalidDigit");
74+
impl_case!(case_bad_string_nan : "nan" => "InvalidDigit");
75+
impl_case!(case_bad_string_invalid_char : "12z3.12" => "InvalidDigit");
76+
impl_case!(case_bad_string_nan_exponent : "123.123eg" => "InvalidDigit");
77+
impl_case!(case_bad_string_multiple_decimal_points : "123.12.45" => "InvalidDigit");
78+
impl_case!(case_bad_string_hex : "0xCafeBeef" => "InvalidDigit");
4779
}

src/lib.rs

-41
Original file line numberDiff line numberDiff line change
@@ -2228,47 +2228,6 @@ mod bigdecimal_tests {
22282228
}
22292229
}
22302230

2231-
#[test]
2232-
#[should_panic(expected = "InvalidDigit")]
2233-
fn test_bad_string_nan() {
2234-
BigDecimal::from_str("hello").unwrap();
2235-
}
2236-
#[test]
2237-
#[should_panic(expected = "Empty")]
2238-
fn test_bad_string_empty() {
2239-
BigDecimal::from_str("").unwrap();
2240-
}
2241-
#[test]
2242-
#[should_panic(expected = "InvalidDigit")]
2243-
fn test_bad_string_invalid_char() {
2244-
BigDecimal::from_str("12z3.12").unwrap();
2245-
}
2246-
#[test]
2247-
#[should_panic(expected = "InvalidDigit")]
2248-
fn test_bad_string_nan_exponent() {
2249-
BigDecimal::from_str("123.123eg").unwrap();
2250-
}
2251-
#[test]
2252-
#[should_panic(expected = "Empty")]
2253-
fn test_bad_string_empty_exponent() {
2254-
BigDecimal::from_str("123.123E").unwrap();
2255-
}
2256-
#[test]
2257-
#[should_panic(expected = "InvalidDigit")]
2258-
fn test_bad_string_multiple_decimal_points() {
2259-
BigDecimal::from_str("123.12.45").unwrap();
2260-
}
2261-
#[test]
2262-
#[should_panic(expected = "Empty")]
2263-
fn test_bad_string_only_decimal() {
2264-
BigDecimal::from_str(".").unwrap();
2265-
}
2266-
#[test]
2267-
#[should_panic(expected = "Empty")]
2268-
fn test_bad_string_only_decimal_and_exponent() {
2269-
BigDecimal::from_str(".e4").unwrap();
2270-
}
2271-
22722231
#[test]
22732232
fn test_from_i128() {
22742233
let value = BigDecimal::from_i128(-368934881474191032320).unwrap();

0 commit comments

Comments
 (0)