@@ -59,6 +59,17 @@ void test_roundtrip(const std::array<T, N>& decimals, const std::array<StringsTy
5959 }
6060}
6161
62+ template <typename TargetDecimalType, typename T, std::size_t N>
63+ void test_invalid_values (const std::array<T, N>& strings)
64+ {
65+ for (std::size_t i {}; i < strings.size (); ++i)
66+ {
67+ TargetDecimalType val;
68+ const auto r {from_chars (strings[i], strings[i] + sizeof (strings[i]), val, chars_format::cohort_preserving_scientific)};
69+ BOOST_TEST (!r);
70+ }
71+ }
72+
6273template <typename T>
6374const std::array<T, 7 > decimals = {
6475 T{3 , 2 },
@@ -116,6 +127,12 @@ constexpr std::array<const char*, 5> negative_values_strings = {
116127 " -3.210000e-47"
117128};
118129
130+ constexpr std::array<const char *, 3 > invalid_decimal32_strings = {
131+ " +3.2e+20" ,
132+ " 3.421" ,
133+ " 9.999999999999999e+05" ,
134+ };
135+
119136int main ()
120137{
121138 test_to_chars_scientific (decimals<decimal32_t >, strings);
@@ -142,5 +159,12 @@ int main()
142159 test_roundtrip (negative_values<decimal64_t >, negative_values_strings);
143160 test_roundtrip (negative_values<decimal128_t >, negative_values_strings);
144161
162+ test_invalid_values<decimal32_t >(invalid_decimal32_strings);
163+
164+ // Every value for fast types are invalid
165+ test_invalid_values<decimal_fast32_t >(strings);
166+ test_invalid_values<decimal_fast64_t >(decimals_with_exp_strings);
167+ test_invalid_values<decimal_fast128_t >(negative_values_strings);
168+
145169 return boost::report_errors ();
146170}
0 commit comments