Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify CompileTimeFormattingTest tests by reordering arguments of EXPECT_EQ #2044

Conversation

alexezeder
Copy link
Contributor

Extends #2019 by simplifying tests. This change was requested there #2019 (comment) but I didn't manage to simplify it.

Turns out that the position in EXPECT_EQ macro is the key:

EXPECT_EQ(test_format<5>(FMT_COMPILE("{}"), true), "true"); // compilation error
EXPECT_EQ("true", test_format<5>(FMT_COMPILE("{}"), true)); // ok

In this PR arguments are just swapped, so the result is the first argument. Just like all over the file:

fmt/test/compile-test.cc

Lines 125 to 136 in 5a49356

TEST(CompileTest, FormatDefault) {
EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), 42));
EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), 42u));
EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), 42ll));
EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), 42ull));
EXPECT_EQ("true", fmt::format(FMT_COMPILE("{}"), true));
EXPECT_EQ("x", fmt::format(FMT_COMPILE("{}"), 'x'));
EXPECT_EQ("4.2", fmt::format(FMT_COMPILE("{}"), 4.2));
EXPECT_EQ("foo", fmt::format(FMT_COMPILE("{}"), "foo"));
EXPECT_EQ("foo", fmt::format(FMT_COMPILE("{}"), std::string("foo")));
EXPECT_EQ("foo", fmt::format(FMT_COMPILE("{}"), test_formattable()));
}

@vitaut vitaut merged commit aabe0a8 into fmtlib:master Dec 3, 2020
@vitaut
Copy link
Contributor

vitaut commented Dec 3, 2020

Nice!

@alexezeder alexezeder deleted the feature/compile-time-formatting-tests-simplification branch January 15, 2021 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants