X-Git-Url: https://git.josue.xyz/?p=VSoRC%2F.git;a=blobdiff_plain;f=node_modules%2Fnode-pty%2Fdeps%2Fwinpty%2Fsrc%2Fshared%2FStringBuilderTest.cc;fp=node_modules%2Fnode-pty%2Fdeps%2Fwinpty%2Fsrc%2Fshared%2FStringBuilderTest.cc;h=e6c2d3138c88c626b52b7b2e0012559e95a1dc83;hp=0000000000000000000000000000000000000000;hb=e79e4a5a87f3e84f7c1777f10a954453a69bf540;hpb=4339da12467b75fb8b6ca831f4bf0081c485ed2c diff --git a/node_modules/node-pty/deps/winpty/src/shared/StringBuilderTest.cc b/node_modules/node-pty/deps/winpty/src/shared/StringBuilderTest.cc new file mode 100644 index 0000000..e6c2d31 --- /dev/null +++ b/node_modules/node-pty/deps/winpty/src/shared/StringBuilderTest.cc @@ -0,0 +1,114 @@ +// Copyright (c) 2016 Ryan Prichard +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. + +#define STRING_BUILDER_TESTING + +#include "StringBuilder.h" + +#include +#include + +#include +#include + +void display(const std::string &str) { fprintf(stderr, "%s", str.c_str()); } +void display(const std::wstring &str) { fprintf(stderr, "%ls", str.c_str()); } + +#define CHECK_EQ(x, y) \ + do { \ + const auto xval = (x); \ + const auto yval = (y); \ + if (xval != yval) { \ + fprintf(stderr, "error: %s:%d: %s != %s: ", \ + __FILE__, __LINE__, #x, #y); \ + display(xval); \ + fprintf(stderr, " != "); \ + display(yval); \ + fprintf(stderr, "\n"); \ + } \ + } while(0) + +template +std::basic_string decOfIntSS(const I value) { + // std::to_string and std::to_wstring are missing in Cygwin as of this + // writing (early 2016). + std::basic_stringstream ss; + ss << +value; // We must promote char to print it as an integer. + return ss.str(); +} + + +template +std::basic_string hexOfIntSS(const I value) { + typedef typename std::make_unsigned::type U; + const unsigned long long u64Value = value & static_cast(~0); + std::basic_stringstream ss; + if (leadingZeros) { + ss << std::setfill(static_cast('0')) << std::setw(sizeof(I) * 2); + } + ss << std::hex << u64Value; + return ss.str(); +} + +template +void testValue(I value) { + CHECK_EQ(decOfInt(value).str(), (decOfIntSS(value))); + CHECK_EQ(wdecOfInt(value).str(), (decOfIntSS(value))); + CHECK_EQ((hexOfInt(value).str()), (hexOfIntSS(value))); + CHECK_EQ((hexOfInt(value).str()), (hexOfIntSS(value))); + CHECK_EQ((whexOfInt(value).str()), (hexOfIntSS(value))); + CHECK_EQ((whexOfInt(value).str()), (hexOfIntSS(value))); +} + +template +void testType() { + typedef typename std::make_unsigned::type U; + const U quarter = static_cast(1) << (sizeof(U) * 8 - 2); + for (unsigned quarterIndex = 0; quarterIndex < 4; ++quarterIndex) { + for (int offset = -18; offset <= 18; ++offset) { + const I value = quarter * quarterIndex + static_cast(offset); + testValue(value); + } + } + testValue(static_cast(42)); + testValue(static_cast(123456)); + testValue(static_cast(0xdeadfacecafebeefull)); +} + +int main() { + testType(); + + testType(); + testType(); + testType(); + testType(); + testType(); + + testType(); + testType(); + testType(); + testType(); + testType(); + + StringBuilder() << static_cast("TEST"); + WStringBuilder() << static_cast("TEST"); + + fprintf(stderr, "All tests completed!\n"); +}