fmt/test/string-test.cc

72 lines
1.6 KiB
C++
Raw Normal View History

2016-05-19 02:54:52 +00:00
/*
Tests of string utilities
Copyright (c) 2012 - 2016, Victor Zverovich
All rights reserved.
For the license information refer to format.h.
*/
#include "fmt/string.h"
#include "gtest/gtest.h"
2017-02-17 14:23:16 +00:00
using fmt::string_buffer;
2016-07-14 14:41:00 +00:00
TEST(StringBufferTest, Empty) {
2017-02-17 14:23:16 +00:00
string_buffer buffer;
2016-07-14 14:41:00 +00:00
EXPECT_EQ(0, buffer.size());
EXPECT_EQ(0, buffer.capacity());
std::string data;
// std::string may have initial capacity.
std::size_t capacity = data.capacity();
buffer.move_to(data);
EXPECT_EQ("", data);
EXPECT_EQ(capacity, data.capacity());
}
TEST(StringBufferTest, Reserve) {
2017-02-17 14:23:16 +00:00
string_buffer buffer;
2016-07-14 14:41:00 +00:00
std::size_t capacity = std::string().capacity() + 10;
buffer.reserve(capacity);
EXPECT_EQ(0, buffer.size());
EXPECT_EQ(capacity, buffer.capacity());
std::string data;
buffer.move_to(data);
EXPECT_EQ("", data);
}
TEST(StringBufferTest, Resize) {
2017-02-17 14:23:16 +00:00
string_buffer buffer;
2016-07-14 14:41:00 +00:00
std::size_t size = std::string().capacity() + 10;
buffer.resize(size);
EXPECT_EQ(size, buffer.size());
EXPECT_EQ(size, buffer.capacity());
std::string data;
buffer.move_to(data);
EXPECT_EQ(size, data.size());
}
TEST(StringBufferTest, MoveTo) {
2017-02-17 14:23:16 +00:00
string_buffer buffer;
2016-07-14 14:41:00 +00:00
std::size_t size = std::string().capacity() + 10;
buffer.resize(size);
const char *p = &buffer[0];
std::string data;
buffer.move_to(data);
EXPECT_EQ(p, &data[0]);
EXPECT_EQ(0, buffer.size());
EXPECT_EQ(0, buffer.capacity());
}
2017-02-17 14:23:16 +00:00
TEST(StringBufferTest, WString) {
fmt::wstring_buffer out;
out.push_back(L'x');
std::wstring s;
out.move_to(s);
2017-02-17 14:23:16 +00:00
EXPECT_EQ(L"x", s);
}
2016-05-19 02:54:52 +00:00
TEST(StringTest, ToString) {
EXPECT_EQ("42", fmt::to_string(42));
}