#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 | |
---|---|---|---|---|---|
#6 | 16768 | ShadauxCat |
Improvements to error handling in builds with exceptions disabled: - In debug builds or with SPRAWL_ERRORSTATE_STRICT enabled, ErrorState will output a message to stderr and terminate if Get() is called when an error flag is set. (In release buils or with SPRAWL_ERRORSTATE_PERMISSIVE defined, Get() will return junk memory in this case.) - In debug builds or with SPRAWL_ERRORSTATE_STRICT enabled, ErrorState will output a message to stderr and terminate if its destructor is called without checking the errorstate if an error is present (equivalent to an exception terminating the application if no catch() block is present for it). - On linux builds and when running "Analyze" through visual studio, a warning will be issued if any function returning ErrorState has its return value ignored. (This only applies to builds with exceptions not enabled; when exceptions are enabled no warning is issued) - Many functions that could return ErrorState were having their return values silently ignored in internal sprawl code so the user would not find out about errors if exceptions are disabled; now anything in sprawl code that calls a function returning ErrorState will either handle the error, or (in most cases) surface it back up to the user. - As a positive side-effect of the warnings for ignoring ErrorState, several constructors that were capable of throwing exceptions are no longer capable of doing so. #review-16769 |
||
#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 |