From f29c57d367bd2da46aa8e64f3d1723857f037244 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Fri, 25 Aug 2023 23:05:36 +0200 Subject: [PATCH] style: formatting to make pre-commit happy --- .../glide_computer_lib/glide_computer_lib.cpp | 3 +- src/core/include/mp-units/bits/magnitude.h | 11 +- .../include/mp-units/bits/unit_concepts.h | 3 +- test/unit_test/runtime/fmt_test.cpp | 148 ++++++++---------- test/unit_test/static/international_test.cpp | 3 +- test/unit_test/static/natural_test.cpp | 3 +- test/unit_test/static/quantity_point_test.cpp | 12 +- 7 files changed, 86 insertions(+), 97 deletions(-) diff --git a/example/glide_computer_lib/glide_computer_lib.cpp b/example/glide_computer_lib/glide_computer_lib.cpp index 64263f6c..c0fa44d7 100644 --- a/example/glide_computer_lib/glide_computer_lib.cpp +++ b/example/glide_computer_lib/glide_computer_lib.cpp @@ -45,7 +45,8 @@ std::vector task::make_leg_total_distances(const legs& legs) std::vector res; res.reserve(legs.size()); auto to_length = [](const leg& l) { return l.get_distance(); }; - std::transform_inclusive_scan(legs.cbegin(), legs.cend(), std::back_inserter(res), std::plus(), to_length, distance::zero()); + std::transform_inclusive_scan(legs.cbegin(), legs.cend(), std::back_inserter(res), std::plus(), to_length, + distance::zero()); return res; } diff --git a/src/core/include/mp-units/bits/magnitude.h b/src/core/include/mp-units/bits/magnitude.h index 9b193fe3..3d9fce46 100644 --- a/src/core/include/mp-units/bits/magnitude.h +++ b/src/core/include/mp-units/bits/magnitude.h @@ -107,8 +107,8 @@ concept Magnitude = detail::is_magnitude; /** * @brief A basis vector in our magnitude representation, raised to some rational power. * - * The public API is that there is a `power` member variable (of type `ratio`), and a `get_base_value()` member function (of - * type either `std::intmax_t` or `long double`, as appropriate), for any specialization. + * The public API is that there is a `power` member variable (of type `ratio`), and a `get_base_value()` member function + * (of type either `std::intmax_t` or `long double`, as appropriate), for any specialization. * * These types exist to be used as NTTPs for the variadic `magnitude<...>` template. We represent a magnitude (which is * a positive real number) as the product of rational powers of "basis vectors", where each "basis vector" is a positive @@ -184,7 +184,8 @@ namespace detail { template [[nodiscard]] consteval auto get_base(Element element) { - if constexpr (detail::is_specialization_of_power_v) return Element::base; + if constexpr (detail::is_specialization_of_power_v) + return Element::base; else return element; } @@ -394,8 +395,8 @@ namespace detail { // // and/or iterations. We can still _perform_ the factorization for these by using the `known_first_factor` // // workaround. However, we can't _check_ that they are prime, because this workaround depends on the input being // // usable in a constexpr expression. This is true for `prime_factorization` (below), where the input `N` is a -// // template parameter, but is not true for our case, where the input `bp.get_base_value()` is a function parameter. -// (See +// // template parameter, but is not true for our case, where the input `bp.get_base_value()` is a function +// parameter. (See // // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1045r1.html for some background reading on this // // distinction.) // // diff --git a/src/core/include/mp-units/bits/unit_concepts.h b/src/core/include/mp-units/bits/unit_concepts.h index 7fcdec2a..51b806d2 100644 --- a/src/core/include/mp-units/bits/unit_concepts.h +++ b/src/core/include/mp-units/bits/unit_concepts.h @@ -141,7 +141,8 @@ template inline constexpr bool is_specialization_of_prefixed_unit> = true; template - requires requires(T* t) { is_unit_impl(t); } && (!is_specialization_of_named_unit) && (!is_specialization_of_prefixed_unit) + requires requires(T* t) { is_unit_impl(t); } && (!is_specialization_of_named_unit) && + (!is_specialization_of_prefixed_unit) struct is_unit : std::true_type {}; template diff --git a/test/unit_test/runtime/fmt_test.cpp b/test/unit_test/runtime/fmt_test.cpp index db834f94..9bdce188 100644 --- a/test/unit_test/runtime/fmt_test.cpp +++ b/test/unit_test/runtime/fmt_test.cpp @@ -415,23 +415,20 @@ TEST_CASE("unknown unit modifiers should throw", "[text][fmt][exception]") SECTION("invalid modifier in the front") { - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%xUdaq}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, Catch::Matchers::Message("invalid unit modifier specified")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%xUdaq}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, Catch::Matchers::Message("invalid unit modifier specified")); } SECTION("invalid modifier in the end") { - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%Udaxq}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, Catch::Matchers::Message("invalid unit modifier specified")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%Udaxq}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, Catch::Matchers::Message("invalid unit modifier specified")); } SECTION("invalid modifier in the middle") { - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%Udxaq}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, Catch::Matchers::Message("invalid unit modifier specified")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%Udxaq}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, Catch::Matchers::Message("invalid unit modifier specified")); } } @@ -441,50 +438,41 @@ TEST_CASE("repeated unit modifiers should throw", "[text][fmt][exception]") SECTION("text encoding") { - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%UdaUq}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, - Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec")); - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%dUaUq}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, - Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec")); - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%dUUaq}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, - Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%UdaUq}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, + Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%dUaUq}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, + Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%dUUaq}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, + Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec")); } SECTION("solidus") { - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%aUdaq}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, - Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec")); - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%daUaq}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, - Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec")); - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%daaUq}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, - Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%aUdaq}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, + Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%daUaq}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, + Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%daaUq}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, + Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec")); } SECTION("separator") { - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%dUadq}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, - Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec")); - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%dadUq}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, - Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec")); - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%addUq}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, - Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%dUadq}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, + Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%dadUq}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, + Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%addUq}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, + Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec")); } } @@ -494,50 +482,41 @@ TEST_CASE("more then one modifier of the same kind should throw", "[text][fmt][e SECTION("text encoding") { - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%UdaAq}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, - Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec")); - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%dAaUq}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, - Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec")); - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%dAUaq}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, - Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%UdaAq}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, + Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%dAaUq}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, + Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%dAUaq}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, + Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec")); } SECTION("solidus") { - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%aUdnq}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, - Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec")); - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%dnUaq}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, - Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec")); - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%daoUq}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, - Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%aUdnq}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, + Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%dnUaq}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, + Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%daoUq}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, + Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec")); } SECTION("separator") { - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%dUasq}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, - Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec")); - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%sadUq}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, - Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec")); - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%adsUq}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, - Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%dUasq}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, + Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%sadUq}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, + Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%adsUq}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, + Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec")); } } @@ -704,10 +683,9 @@ TEST_CASE("precision specification for integral representation should throw", "[ SECTION("full format {:%Q %q} on a quantity") { - REQUIRE_THROWS_MATCHES( - MP_UNITS_STD_FMT::vformat("{:%.1Q %q}", MP_UNITS_STD_FMT::make_format_args(q)), - MP_UNITS_STD_FMT::format_error, - Catch::Matchers::Message("precision not allowed for integral quantity representation")); + REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%.1Q %q}", MP_UNITS_STD_FMT::make_format_args(q)), + MP_UNITS_STD_FMT::format_error, + Catch::Matchers::Message("precision not allowed for integral quantity representation")); } SECTION("value only format {:%Q} on a quantity") diff --git a/test/unit_test/static/international_test.cpp b/test/unit_test/static/international_test.cpp index 85d219fc..a5a31219 100644 --- a/test/unit_test/static/international_test.cpp +++ b/test/unit_test/static/international_test.cpp @@ -63,7 +63,8 @@ static_assert(1 * isq::length[nmi] == 1852 * isq::length[si::metre]); static_assert(1 * isq::speed[kn] == isq::length(1 * nmi) / isq::time(1 * si::hour)); // Force -static_assert(1 * isq::force[pdl] == isq::mass(1 * lb) * isq::length(1 * ft) / (isq::time(1 * si::second) * isq::time(1 * si::second))); +static_assert(1 * isq::force[pdl] == + isq::mass(1 * lb) * isq::length(1 * ft) / (isq::time(1 * si::second) * isq::time(1 * si::second))); static_assert(1 * isq::force[lbf] == isq::mass(1 * lb) * (1 * si::standard_gravity)); static_assert(1 * isq::force[kip] == 1000 * isq::force[lbf]); diff --git a/test/unit_test/static/natural_test.cpp b/test/unit_test/static/natural_test.cpp index 61508251..5666991f 100644 --- a/test/unit_test/static/natural_test.cpp +++ b/test/unit_test/static/natural_test.cpp @@ -33,7 +33,8 @@ using namespace mp_units; using namespace mp_units::natural::unit_symbols; static_assert(1 * natural::length[1 / GeV] / (1 * natural::time[1 / GeV]) == 1 * natural::speed[one]); -static_assert(1 * natural::length[1 / GeV] / (1 * natural::time[1 / GeV] * (1 * natural::time[1 / GeV])) == 1 * natural::acceleration[GeV]); +static_assert(1 * natural::length[1 / GeV] / (1 * natural::time[1 / GeV] * (1 * natural::time[1 / GeV])) == + 1 * natural::acceleration[GeV]); static_assert(1 * natural::mass[GeV] * (1 * natural::velocity[one]) == 1 * natural::momentum[GeV]); static_assert(1 * natural::mass[GeV] * (1 * natural::acceleration[GeV]) == 1 * natural::force[GeV2]); static_assert(1 * natural::mass[GeV] * (1 * natural::acceleration[GeV]) * (1 * natural::length[1 / GeV]) == diff --git a/test/unit_test/static/quantity_point_test.cpp b/test/unit_test/static/quantity_point_test.cpp index 3e027a5d..1ccdd56e 100644 --- a/test/unit_test/static/quantity_point_test.cpp +++ b/test/unit_test/static/quantity_point_test.cpp @@ -693,7 +693,9 @@ static_assert(invalid_compound_assignments); template typename QP, auto Origin, auto OtherOrigin> concept invalid_binary_operations = requires { // can't add two quantity points - requires !requires { QP(1 * m) + QP(1 * m); }; + requires !requires { + QP(1 * m) + QP(1 * m); + }; requires !requires { mean_sea_level + QP(1 * m); }; requires !requires { QP(1 * m) + mean_sea_level; }; requires !requires { Origin + Origin; }; @@ -722,8 +724,12 @@ concept invalid_binary_operations = requires { requires !requires { Origin - 1 * s; }; // can't subtract two quantity points of incompatible origins - requires !requires { QP(1 * m) - QP(1 * m); }; - requires !requires { QP(1 * m) - QP(1 * m); }; + requires !requires { + QP(1 * m) - QP(1 * m); + }; + requires !requires { + QP(1 * m) - QP(1 * m); + }; requires !requires { mean_sea_level - QP(1 * m); }; requires !requires { QP(1 * m) - other_absolute_level; };