55#include " simdjson.h"
66#include " test_macros.h"
77
8+
9+ std::string trim (const std::string s) {
10+ auto start = s.begin ();
11+ auto end = s.end ();
12+ while (start != s.end () && std::isspace (*start)) {
13+ start++;
14+ }
15+ do {
16+ end--;
17+ } while (std::distance (start, end) > 0 && std::isspace (*end));
18+ return std::string (start, end + 1 );
19+ }
20+
821namespace document_stream_tests {
922 static simdjson::dom::document_stream parse_many_stream_return (simdjson::dom::parser &parser, simdjson::padded_string &str) {
1023 simdjson::dom::document_stream stream;
@@ -19,10 +32,18 @@ namespace document_stream_tests {
1932 }
2033 bool test_current_index () {
2134 std::cout << " Running " << __func__ << std::endl;
22- std::string base (" 1 " );// one JSON!
35+ std::string base1 (" 1 " );// one JSON!
36+ std::string base2 (" {\" k\" :1} " );// one JSON!
37+ std::string base3 (" [1,2] " );// one JSON!
38+ assert (base1.size () == base2.size ());
39+ assert (base2.size () == base3.size ());
40+ std::vector<std::string> source_strings = {base1, base2, base3};
41+
2342 std::string json;
2443 for (size_t k = 0 ; k < 1000 ; k++) {
25- json += base;
44+ json += base1;
45+ json += base2;
46+ json += base3;
2647 }
2748 simdjson::dom::parser parser;
2849 const size_t window = 32 ; // deliberately small
@@ -38,7 +59,13 @@ namespace document_stream_tests {
3859 std::cout << " expected index:" << count << std::endl;
3960 return false ;
4061 }
41- count += base.size ();
62+ std::string answer = source_strings[(count / base1.size ()) % source_strings.size ()];
63+ if (trim (std::string (i.source ())) != trim (answer)) {
64+ std::cout << " got: '" << i.source () << " '" << std::endl;
65+ std::cout << " expected : '" << answer << " '" << std::endl;
66+ return false ;
67+ }
68+ count += base1.size ();
4269 }
4370 return true ;
4471 }
0 commit comments