Skip to content

Commit

Permalink
Finished unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anarthal committed Jan 19, 2025
1 parent a48f16b commit cd2bf67
Showing 1 changed file with 70 additions and 1 deletion.
71 changes: 70 additions & 1 deletion test/unit/test/format_sql/individual_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ BOOST_AUTO_TEST_CASE(std_optional)
#endif

#ifdef BOOST_MYSQL_CXX14
BOOST_AUTO_TEST_CASE(decimal32)
BOOST_AUTO_TEST_CASE(decimal32_)
{
using namespace boost::decimal;
BOOST_TEST(format_sql(opts, single_fmt, 200_df) == "SELECT 200.0000;");
Expand All @@ -519,6 +519,56 @@ BOOST_AUTO_TEST_CASE(decimal32)
// BOOST_TEST(format_sql(opts, single_fmt, 9.999999e15_df) == "SELECT 999999900000000;");
// BOOST_TEST(format_sql(opts, single_fmt, 1e-15_df) == "SELECT 0.000000000000001;");
}

BOOST_AUTO_TEST_CASE(decimal64_)
{
using namespace boost::decimal;
BOOST_TEST(format_sql(opts, single_fmt, 200_dd) == "SELECT 200.0000000000000;");
BOOST_TEST(format_sql(opts, single_fmt, 1.56789_dd) == "SELECT 1.567890000000000;");
BOOST_TEST(format_sql(opts, single_fmt, 1.142099e5_dd) == "SELECT 114209.9000000000;");
BOOST_TEST(format_sql(opts, single_fmt, -1.56789_dd) == "SELECT -1.567890000000000;");
BOOST_TEST(format_sql(opts, single_fmt, 9999999999999999_dd) == "SELECT 9999999999999999;");
BOOST_TEST(format_sql(opts, single_fmt, -9999999999999999_dd) == "SELECT -9999999999999999;");
BOOST_TEST(format_sql(opts, single_fmt, 99999.99999999999_dd) == "SELECT 99999.99999999999;");
BOOST_TEST(format_sql(opts, single_fmt, -99999.99999999999_dd) == "SELECT -99999.99999999999;");
}

BOOST_AUTO_TEST_CASE(decimal128_)
{
using namespace boost::decimal;
BOOST_TEST(format_sql(opts, single_fmt, 200_dl) == "SELECT 200.0000000000000000000000000000000;");
BOOST_TEST(format_sql(opts, single_fmt, 1.56789_dl) == "SELECT 1.567890000000000000000000000000000;");
BOOST_TEST(format_sql(opts, single_fmt, 1.142099e5_dl) == "SELECT 114209.9000000000000000000000000000;");
BOOST_TEST(format_sql(opts, single_fmt, -1.56789_dl) == "SELECT -1.567890000000000000000000000000000;");
BOOST_TEST(
format_sql(opts, single_fmt, "9999999999999999999999999999999999"_dl) ==
"SELECT 9999999999999999999999999999999999;"
);
BOOST_TEST(
format_sql(opts, single_fmt, -"9999999999999999999999999999999999"_dl) ==
"SELECT -9999999999999999999999999999999999;"
);
BOOST_TEST(
format_sql(opts, single_fmt, 9.999999999999999999999999999999999_dl) ==
"SELECT 9.999999999999999999999999999999999;"
);
BOOST_TEST(
format_sql(opts, single_fmt, -9.999999999999999999999999999999999_dl) ==
"SELECT -9.999999999999999999999999999999999;"
);
}

BOOST_AUTO_TEST_CASE(decimal_fast)
{
// Spotcheck: fast decimals are also formattable
using namespace boost::decimal;
BOOST_TEST(format_sql(opts, single_fmt, 1.56789_dff) == "SELECT 1.567890;");
BOOST_TEST(format_sql(opts, single_fmt, 1.5678912345678_ddf) == "SELECT 1.567891234567800;");
BOOST_TEST(
format_sql(opts, single_fmt, 1.567891234567887237237943928290828_dlf) ==
"SELECT 1.567891234567887237237943928290828;"
);
}
#endif

//
Expand Down Expand Up @@ -704,4 +754,23 @@ BOOST_AUTO_TEST_CASE(boost_optional_error) { optional_error_test<boost::optional
BOOST_AUTO_TEST_CASE(std_optional_error) { optional_error_test<std::optional>(); }
#endif

#ifdef BOOST_MYSQL_CXX14
BOOST_AUTO_TEST_CASE(decimal_error)
{
using namespace boost::decimal;

// NaN and Inf
using lims32 = std::numeric_limits<decimal32>;
BOOST_TEST(format_single_error("{}", lims32::infinity()) == client_errc::unformattable_value);
BOOST_TEST(format_single_error("{}", -lims32::infinity()) == client_errc::unformattable_value);
BOOST_TEST(format_single_error("{}", lims32::quiet_NaN()) == client_errc::unformattable_value);

// Too long values
BOOST_TEST(format_single_error("{}", 9.99e90_df) == client_errc::unformattable_value);
BOOST_TEST(format_single_error("{}", 1e-94_df) == client_errc::unformattable_value);
// Subnormal values don't seem to work
}

#endif

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit cd2bf67

Please sign in to comment.