Skip to content

Commit

Permalink
Follow naming conventions in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Apr 26, 2021
1 parent 39818e7 commit 847aac4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
27 changes: 13 additions & 14 deletions test/args-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@

#include "fmt/args.h"

#include "gmock.h"
#include "gtest.h"

TEST(ArgsTest, Basic) {
TEST(args_test, basic) {
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
store.push_back(42);
store.push_back("abc1");
store.push_back(1.5f);
EXPECT_EQ("42 and abc1 and 1.5", fmt::vformat("{} and {} and {}", store));
}

TEST(ArgsTest, StringsAndRefs) {
TEST(args_test, strings_and_refs) {
// Unfortunately the tests are compiled with old ABI so strings use COW.
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
char str[] = "1234567890";
Expand Down Expand Up @@ -47,7 +47,7 @@ template <> struct formatter<custom_type> {
};
FMT_END_NAMESPACE

TEST(ArgsTest, CustomFormat) {
TEST(args_test, custom_format) {
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
auto c = custom_type();
store.push_back(c);
Expand All @@ -70,28 +70,27 @@ template <> struct formatter<to_stringable> {
return ctx.begin();
}

template <typename FormatContext>
auto format(const to_stringable&, FormatContext& ctx) -> decltype(ctx.out()) {
auto format(to_stringable, format_context& ctx) -> decltype(ctx.out()) {
return ctx.out();
}
};
FMT_END_NAMESPACE

TEST(ArgsTest, ToStringAndFormatter) {
TEST(args_test, to_string_and_formatter) {
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
auto s = to_stringable();
store.push_back(s);
store.push_back(std::cref(s));
fmt::vformat("", store);
}

TEST(ArgsTest, NamedInt) {
TEST(args_test, named_int) {
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
store.push_back(fmt::arg("a1", 42));
EXPECT_EQ("42", fmt::vformat("{a1}", store));
}

TEST(ArgsTest, NamedStrings) {
TEST(args_test, named_strings) {
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
char str[] = "1234567890";
store.push_back(fmt::arg("a1", str));
Expand All @@ -100,15 +99,15 @@ TEST(ArgsTest, NamedStrings) {
EXPECT_EQ("1234567890 and X234567890", fmt::vformat("{a1} and {a2}", store));
}

TEST(ArgsTest, NamedArgByRef) {
TEST(args_test, named_arg_by_ref) {
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
char band[] = "Rolling Stones";
store.push_back(fmt::arg("band", std::cref(band)));
band[9] = 'c'; // Changing band affects the output.
EXPECT_EQ(fmt::vformat("{band}", store), "Rolling Scones");
}

TEST(ArgsTest, NamedCustomFormat) {
TEST(args_test, named_custom_format) {
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
auto c = custom_type();
store.push_back(fmt::arg("c1", c));
Expand All @@ -121,7 +120,7 @@ TEST(ArgsTest, NamedCustomFormat) {
EXPECT_EQ("cust=0 and cust=1 and cust=3", result);
}

TEST(ArgsTest, Clear) {
TEST(args_test, clear) {
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
store.push_back(42);

Expand All @@ -138,7 +137,7 @@ TEST(ArgsTest, Clear) {
EXPECT_EQ("44", result);
}

TEST(ArgsTest, Reserve) {
TEST(args_test, reserve) {
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
store.reserve(2, 1);
store.push_back(1.5f);
Expand All @@ -163,7 +162,7 @@ template <> struct formatter<copy_throwable> {
};
FMT_END_NAMESPACE

TEST(ArgsTest, ThrowOnCopy) {
TEST(args_test, throw_on_copy) {
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
store.push_back(std::string("foo"));
try {
Expand Down
7 changes: 3 additions & 4 deletions test/assert-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@
#include "fmt/core.h"
#include "gtest.h"

TEST(AssertTest, Fail) {
TEST(assert_test, fail) {
#if GTEST_HAS_DEATH_TEST
EXPECT_DEBUG_DEATH(FMT_ASSERT(false, "don't panic!"), "don't panic!");
#else
fmt::print("warning: death tests are not supported\n");
#endif
}

bool test_condition = false;

TEST(AssertTest, DanglingElse) {
TEST(assert_test, dangling_else) {
bool test_condition = false;
bool executed_else = false;
if (test_condition)
FMT_ASSERT(true, "");
Expand Down
30 changes: 15 additions & 15 deletions test/chrono-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// For the license information refer to format.h.

#ifndef _CRT_SECURE_NO_WARNINGS
# define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif

#include "fmt/chrono.h"
Expand Down Expand Up @@ -48,7 +48,7 @@ std::string format_tm(const std::tm& time, const char* spec,
return os.str();
}

TEST(TimeTest, Format) {
TEST(time_test, Format) {
std::tm tm = std::tm();
tm.tm_year = 116;
tm.tm_mon = 3;
Expand All @@ -57,23 +57,23 @@ TEST(TimeTest, Format) {
fmt::format("The date is {:%Y-%m-%d}.", tm));
}

TEST(TimeTest, GrowBuffer) {
TEST(time_test, GrowBuffer) {
std::string s = "{:";
for (int i = 0; i < 30; ++i) s += "%c";
s += "}\n";
std::time_t t = std::time(nullptr);
fmt::format(s, *std::localtime(&t));
}

TEST(TimeTest, FormatToEmptyContainer) {
TEST(time_test, FormatToEmptyContainer) {
std::string s;
auto time = std::tm();
time.tm_sec = 42;
fmt::format_to(std::back_inserter(s), "{:%S}", time);
EXPECT_EQ(s, "42");
}

TEST(TimeTest, EmptyResult) { EXPECT_EQ("", fmt::format("{}", std::tm())); }
TEST(time_test, EmptyResult) { EXPECT_EQ("", fmt::format("{}", std::tm())); }

static bool EqualTime(const std::tm& lhs, const std::tm& rhs) {
return lhs.tm_sec == rhs.tm_sec && lhs.tm_min == rhs.tm_min &&
Expand All @@ -83,19 +83,19 @@ static bool EqualTime(const std::tm& lhs, const std::tm& rhs) {
lhs.tm_isdst == rhs.tm_isdst;
}

TEST(TimeTest, LocalTime) {
TEST(time_test, LocalTime) {
std::time_t t = std::time(nullptr);
std::tm tm = *std::localtime(&t);
EXPECT_TRUE(EqualTime(tm, fmt::localtime(t)));
}

TEST(TimeTest, GMTime) {
TEST(time_test, GMTime) {
std::time_t t = std::time(nullptr);
std::tm tm = *std::gmtime(&t);
EXPECT_TRUE(EqualTime(tm, fmt::gmtime(t)));
}

TEST(TimeTest, FormatTM) {
TEST(time_test, FormatTM) {
auto point = std::chrono::system_clock::now();
std::time_t t = std::chrono::system_clock::to_time_t(point);
std::tm tm = *std::localtime(&t);
Expand All @@ -117,7 +117,7 @@ template <typename TimePoint> std::string strftime(TimePoint tp) {
return output;
}

TEST(TimeTest, TimePoint) {
TEST(time_test, TimePoint) {
auto t1 = std::chrono::system_clock::now();
EXPECT_EQ(strftime(t1), fmt::format("{:%Y-%m-%d %H:%M:%S}", t1));
using time_point =
Expand All @@ -126,12 +126,12 @@ TEST(TimeTest, TimePoint) {
EXPECT_EQ(strftime(t2), fmt::format("{:%Y-%m-%d %H:%M:%S}", t2));
}

#define EXPECT_TIME(spec, time, duration) \
{ \
std::locale jp_loc("ja_JP.utf8"); \
EXPECT_EQ(format_tm(time, spec, jp_loc), \
fmt::format(loc, "{:" spec "}", duration)); \
}
#define EXPECT_TIME(spec, time, duration) \
{ \
std::locale jp_loc("ja_JP.utf8"); \
EXPECT_EQ(format_tm(time, spec, jp_loc), \
fmt::format(loc, "{:" spec "}", duration)); \
}

#ifndef FMT_STATIC_THOUSANDS_SEPARATOR

Expand Down

0 comments on commit 847aac4

Please sign in to comment.