Make specs_checker constexpr

This commit is contained in:
Victor Zverovich
2017-10-24 07:46:30 -07:00
parent dd0b72e1ee
commit aadb38a5e6
2 changed files with 69 additions and 34 deletions
+24
View File
@@ -1747,3 +1747,27 @@ TEST(FormatTest, ConstexprDynamicSpecsHandler) {
static_assert(parse_dynamic_specs(".{42}").precision_ref.index == 42, "");
static_assert(parse_dynamic_specs("d").type() == 'd', "");
}
constexpr test_format_specs_handler check_specs(const char *s) {
fmt::internal::specs_checker<test_format_specs_handler>
checker(test_format_specs_handler(), fmt::internal::DOUBLE);
parse_format_specs(s, checker);
return checker;
}
TEST(FormatTest, ConstexprSpecsChecker) {
using handler = test_format_specs_handler;
static_assert(check_specs("<").align == fmt::ALIGN_LEFT, "");
static_assert(check_specs("*^").fill == '*', "");
static_assert(check_specs("+").res == handler::PLUS, "");
static_assert(check_specs("-").res == handler::MINUS, "");
static_assert(check_specs(" ").res == handler::SPACE, "");
static_assert(check_specs("#").res == handler::HASH, "");
static_assert(check_specs("0").res == handler::ZERO, "");
static_assert(check_specs("42").width == 42, "");
static_assert(check_specs("{42}").width_ref.index == 42, "");
static_assert(check_specs(".42").precision == 42, "");
static_assert(check_specs(".{42}").precision_ref.index == 42, "");
static_assert(check_specs("d").type == 'd', "");
static_assert(check_specs("{<").res == handler::ERROR, "");
}