diff --git a/test/unittest/simdtest.cpp b/test/unittest/simdtest.cpp index 4407c25..00f5200 100644 --- a/test/unittest/simdtest.cpp +++ b/test/unittest/simdtest.cpp @@ -66,3 +66,39 @@ TEST(SIMD, SIMD_SUFFIX(SkipWhitespace)) { TestSkipWhitespace(); TestSkipWhitespace(); } + +struct ScanCopyUnescapedStringHandler : BaseReaderHandler, ScanCopyUnescapedStringHandler> { + bool String(const char* str, size_t length, bool copy) { + memcpy(buffer, str, length + 1); + return true; + } + char buffer[1024 + 5]; +}; + +template +void TestScanCopyUnescapedString() { + for (size_t step = 0; step < 1024; step++) { + char json[1024 + 5]; + char *p = json; + *p ++= '\"'; + for (size_t i = 0; i < step; i++) + *p++= "ABCD"[i % 4]; + *p++ = '\\'; + *p++ = '\\'; + *p++ = '\"'; + *p++ = '\0'; + + StreamType s(json); + Reader reader; + ScanCopyUnescapedStringHandler h; + reader.Parse(s, h); + EXPECT_TRUE(memcmp(h.buffer, json + 1, step) == 0); + EXPECT_EQ('\\', h.buffer[step]); // escaped + EXPECT_EQ('\0', h.buffer[step + 1]); + } +} + +TEST(SIMD, SIMD_SUFFIX(ScanCopyUnescapedString)) { + TestScanCopyUnescapedString(); + TestScanCopyUnescapedString(); +}