#include <map> #include <unordered_map> #define SPRAWL_STRINGBUILDER_FAVOR_SPEED_OVER_MEMORY 1 #include "../string/String.hpp" #include "../collections/HashMap.hpp" #include "gtest_helpers.hpp" #include <gtest/gtest.h> struct TestStruct{}; sprawl::StringBuilder& operator<<(sprawl::StringBuilder& builder, TestStruct const&) { builder << "TestStruct"; return builder; } TestStruct t; TEST(StringTest, FormatWorks_AllNumbers) { sprawl::String str = sprawl::String(sprawl::StringLiteral("{0:03}, {1}, {2}, {3}, {4}")).format(30LL, true, "foo", t, &t); EXPECT_EQ(sprawl::String("030, True, foo, TestStruct, TestStruct"), str); } #ifndef _WIN32 TEST(StringTest, FormatLiteralWorks) { sprawl::String str = "{0:03}, {1}, {2}, {3}, {4}"_format(30LL, true, "foo", t, &t); EXPECT_EQ(sprawl::String("030, True, foo, TestStruct, TestStruct"), str); } #endif TEST(StringTest, FormatWorks_AllEmpty) { sprawl::String str = sprawl::String(sprawl::StringLiteral("{:03}, {}, {}, {}, {}")).format(30LL, true, "foo", t, &t); EXPECT_EQ(sprawl::String("030, True, foo, TestStruct, TestStruct"), str); } TEST(StringTest, FormatWorks_Mixed) { sprawl::String str = sprawl::String(sprawl::StringLiteral("{0:03}, {1}, {2}, {}, {}")).format(30LL, true, "foo", t, &t); EXPECT_EQ(sprawl::String("030, True, foo, TestStruct, TestStruct"), str); } TEST(StringTest, FormatWorks_BackwardNumbers) { sprawl::String str = sprawl::String(sprawl::StringLiteral("{4}, {3}, {2}, {1}, {0:03}")).format(30LL, true, "foo", t, &t); EXPECT_EQ(sprawl::String("TestStruct, TestStruct, foo, True, 030"), str); } TEST(StringTest, FormatWorks_RepeatNumbers) { sprawl::String str = sprawl::String(sprawl::StringLiteral("{4}, {1}, {3}, {2}, {1}, {4}, {0:03}")).format(30LL, true, "foo", t, &t); EXPECT_EQ(sprawl::String("TestStruct, True, TestStruct, foo, True, TestStruct, 030"), str); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 18645 | brandon_m_bare | Integrated latest version of libsprawl. | ||
#1 | 15089 | brandon_m_bare | First integration of sprawl. | ||
//guest/ShadauxCat/Sprawl/Mainline/UnitTests/UnitTests_String.cpp | |||||
#5 | 14771 | ShadauxCat |
Sadface. User-defined literals not supported in visual studio 2013. Disabled for win32. #review-14772 |
||
#4 | 14769 | ShadauxCat |
Added string literal to allow format strings to be used in a way that's closer to python: "{} {} {}"_format(foo, bar, baz); .format() would be great, but not possible; _format() is almost as good. #review-14770 |
||
#3 | 14146 | ShadauxCat |
Moving a gtest-specific function out of String.hpp #review-14147 |
||
#2 | 14144 | ShadauxCat |
Switching unit tests to gtest. 100 is a decent number of tests to start with, but it needs to be more like 400 to test the current codebase. #review-14145 |
||
#1 | 11496 | ShadauxCat | Initial checkin: Current states for csbuild and libSprawl |