mirror of
https://github.com/fmtlib/fmt.git
synced 2025-02-05 00:40:12 +00:00
More tests.
This commit is contained in:
parent
ed19147441
commit
546b62e74f
@ -29,7 +29,6 @@
|
|||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdarg>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
@ -109,17 +108,6 @@ struct WriteChecker {
|
|||||||
#define CHECK_WRITE_WCHAR(value) \
|
#define CHECK_WRITE_WCHAR(value) \
|
||||||
EXPECT_PRED_FORMAT1(WriteChecker<wchar_t>(), value)
|
EXPECT_PRED_FORMAT1(WriteChecker<wchar_t>(), value)
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
# define vsnprintf vsprintf_s
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void SPrintf(char *buffer, const char *format, ...) {
|
|
||||||
std::va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
vsnprintf(buffer, BUFFER_SIZE, format, args);
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string ReadFile(StringRef filename) {
|
std::string ReadFile(StringRef filename) {
|
||||||
std::ifstream out(filename.c_str());
|
std::ifstream out(filename.c_str());
|
||||||
std::stringstream content;
|
std::stringstream content;
|
||||||
|
@ -165,6 +165,9 @@ TEST(PrintfTest, PlusFlag) {
|
|||||||
EXPECT_PRINTF("-42", "%+d", -42);
|
EXPECT_PRINTF("-42", "%+d", -42);
|
||||||
EXPECT_PRINTF("+0042", "%+05d", 42);
|
EXPECT_PRINTF("+0042", "%+05d", 42);
|
||||||
EXPECT_PRINTF("+0042", "%0++5d", 42);
|
EXPECT_PRINTF("+0042", "%0++5d", 42);
|
||||||
|
|
||||||
|
// '+' flag is ignored for non-numeric types.
|
||||||
|
EXPECT_PRINTF("x", "%+c", 'x');
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(PrintfTest, MinusFlag) {
|
TEST(PrintfTest, MinusFlag) {
|
||||||
@ -177,6 +180,9 @@ TEST(PrintfTest, SpaceFlag) {
|
|||||||
EXPECT_PRINTF("-42", "% d", -42);
|
EXPECT_PRINTF("-42", "% d", -42);
|
||||||
EXPECT_PRINTF(" 0042", "% 05d", 42);
|
EXPECT_PRINTF(" 0042", "% 05d", 42);
|
||||||
EXPECT_PRINTF(" 0042", "%0 5d", 42);
|
EXPECT_PRINTF(" 0042", "%0 5d", 42);
|
||||||
|
|
||||||
|
// ' ' flag is ignored for non-numeric types.
|
||||||
|
EXPECT_PRINTF("x", "% c", 'x');
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(PrintfTest, HashFlag) {
|
TEST(PrintfTest, HashFlag) {
|
||||||
@ -189,15 +195,29 @@ TEST(PrintfTest, HashFlag) {
|
|||||||
EXPECT_PRINTF("-0x42", "%#x", -0x42);
|
EXPECT_PRINTF("-0x42", "%#x", -0x42);
|
||||||
EXPECT_PRINTF("0", "%#x", 0);
|
EXPECT_PRINTF("0", "%#x", 0);
|
||||||
|
|
||||||
|
EXPECT_PRINTF("0x0042", "%#06x", 0x42);
|
||||||
EXPECT_PRINTF("0x0042", "%0##6x", 0x42);
|
EXPECT_PRINTF("0x0042", "%0##6x", 0x42);
|
||||||
|
|
||||||
EXPECT_PRINTF("-42.0000", "%#g", -42.0);
|
EXPECT_PRINTF("-42.000000", "%#f", -42.0);
|
||||||
//EXPECT_PRINTF("-4.200000e+01", "%#e", -42.0);
|
EXPECT_PRINTF("-42.000000", "%#F", -42.0);
|
||||||
|
|
||||||
// TODO: more tests
|
char buffer[BUFFER_SIZE];
|
||||||
|
SPrintf(buffer, "%#e", -42.0);
|
||||||
|
EXPECT_PRINTF(buffer, "%#e", -42.0);
|
||||||
|
SPrintf(buffer, "%#E", -42.0);
|
||||||
|
EXPECT_PRINTF(buffer, "%#E", -42.0);
|
||||||
|
|
||||||
|
EXPECT_PRINTF("-42.0000", "%#g", -42.0);
|
||||||
|
EXPECT_PRINTF("-42.0000", "%#G", -42.0);
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
//EXPECT_PRINTF("-0x1.5p+5", "%#a", -42.0);
|
||||||
|
//EXPECT_PRINTF("-0x1.5A+5", "%#A", -42.0);
|
||||||
|
|
||||||
|
// '#' flag is ignored for non-numeric types.
|
||||||
|
EXPECT_PRINTF("x", "%#c", 'x');
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: test '*' width, precision, length and type specifier
|
// TODO: test '*' width, precision, length and type specifier
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
13
test/util.cc
13
test/util.cc
@ -26,8 +26,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include <cstdarg>
|
||||||
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
# define vsnprintf vsprintf_s
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void SPrintf(char *buffer, const char *format, ...) {
|
||||||
|
std::va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
vsnprintf(buffer, BUFFER_SIZE, format, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
void Increment(char *s) {
|
void Increment(char *s) {
|
||||||
for (int i = static_cast<int>(std::strlen(s)) - 1; i >= 0; --i) {
|
for (int i = static_cast<int>(std::strlen(s)) - 1; i >= 0; --i) {
|
||||||
if (s[i] != '9') {
|
if (s[i] != '9') {
|
||||||
|
@ -27,5 +27,7 @@
|
|||||||
|
|
||||||
enum {BUFFER_SIZE = 256};
|
enum {BUFFER_SIZE = 256};
|
||||||
|
|
||||||
|
void SPrintf(char *buffer, const char *format, ...);
|
||||||
|
|
||||||
// Increment a number in a string.
|
// Increment a number in a string.
|
||||||
void Increment(char *s);
|
void Increment(char *s);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user