Test MakeArg and fix formatting.

This commit is contained in:
Victor Zverovich
2014-07-03 08:50:57 -07:00
parent 43a873f7ff
commit 4e260e8599
4 changed files with 68 additions and 59 deletions
+7 -7
View File
@@ -29,9 +29,12 @@ expect_compile_error("fmt::internal::Array<char, 5> a, b; b = a;")
expect_compile_error("const fmt::Writer a, b(a);")
expect_compile_error("fmt::Writer a, b; b = a;")
# Formatter is not copyable from a temporary.
expect_compile_error("fmt::Formatter<> a(fmt::Formatter<>(\"a\"));")
expect_compile_error("fmt::Formatter<> b(\"a\"); b = fmt::Formatter<>(\"b\");")
# MakeArg doesn't accept [const] volatile char *.
expect_compile_error("volatile char s[] = \"test\"; (fmt::internal::MakeArg<char>)(s);")
expect_compile_error("const volatile char s[] = \"test\"; (fmt::internal::MakeArg<char>)(s);")
# MakeArg<char> doesn't accept wchar_t.
expect_compile_error("fmt::internal::MakeArg<char>(L'a');")
# Writing a wide character to a character stream Writer is forbidden.
expect_compile_error("fmt::Writer() << L'a';")
@@ -39,7 +42,4 @@ expect_compile_error("fmt::Writer() << fmt::pad(\"abc\", 5, L' ');")
expect_compile_error("fmt::Writer() << fmt::pad(42, 5, L' ');")
# Formatting a wide character with a narrow format string is forbidden.
expect_compile_error("fmt::Format(\"{}\") << L'a';")
# There is no implicit conversion from FILE* to FileSink.
expect_compile_error("fmt::FileSink fs = 0;")
expect_compile_error("fmt::format(\"{}\", L'a';")
+14 -6
View File
@@ -73,7 +73,7 @@ TEST(UtilTest, Increment) {
}
#define EXPECT_ARG_(Char, type_code, Type, field, value) { \
Type expected_value = value; \
Type expected_value = static_cast<Type>(value); \
fmt::internal::Arg arg = \
fmt::internal::MakeArg<Char>(expected_value); \
EXPECT_EQ(fmt::internal::Arg::type_code, arg.type); \
@@ -91,17 +91,17 @@ TEST(UtilTest, MakeArg) {
EXPECT_ARG(INT, bool, int_value, true);
// Test char.
EXPECT_ARG(CHAR, signed char, int_value, 42);
EXPECT_ARG(CHAR, signed char, int_value, 'a');
EXPECT_ARG(CHAR, signed char, int_value, SCHAR_MIN);
EXPECT_ARG(CHAR, signed char, int_value, SCHAR_MAX);
EXPECT_ARG(CHAR, unsigned char, int_value, 42);
EXPECT_ARG(CHAR, unsigned char, int_value, 'a');
EXPECT_ARG(CHAR, unsigned char, int_value, UCHAR_MAX );
EXPECT_ARG(CHAR, char, int_value, 'a');
EXPECT_ARG(CHAR, char, int_value, CHAR_MIN);
EXPECT_ARG(CHAR, char, int_value, CHAR_MAX);
// Test wchar_t.
EXPECT_ARGW(CHAR, wchar_t, int_value, 42);
EXPECT_ARGW(CHAR, wchar_t, int_value, L'a');
EXPECT_ARGW(CHAR, wchar_t, int_value, WCHAR_MIN);
EXPECT_ARGW(CHAR, wchar_t, int_value, WCHAR_MAX);
@@ -163,9 +163,17 @@ TEST(UtilTest, MakeArg) {
char STR[] = "test";
EXPECT_ARG(STRING, char*, string.value, STR);
EXPECT_ARG(STRING, const char*, string.value, STR);
//EXPECT_ARG(STRING, volatile char*, string.value, STR);
EXPECT_ARG(STRING, std::string, string.value, STR);
EXPECT_ARG(STRING, fmt::StringRef, string.value, STR);
// TODO: test pointers
// Test wide string.
wchar_t WSTR[] = L"test";
EXPECT_ARGW(WSTRING, wchar_t*, wstring.value, WSTR);
EXPECT_ARGW(WSTRING, const wchar_t*, wstring.value, WSTR);
EXPECT_ARGW(WSTRING, std::wstring, wstring.value, WSTR);
EXPECT_ARGW(WSTRING, fmt::WStringRef, wstring.value, WSTR);
// TODO: test that wide string is rejected by MakeArg<char>
}
// Tests fmt::internal::CountDigits for integer type Int.