@@ -32,19 +32,21 @@ template <typename T>
32
32
static void parse_and_validate (const std::string src, T expected) {
33
33
std::cout << " src: " << src << " , " ;
34
34
const padded_string pstr{src};
35
- auto json = build_parsed_json (pstr);
35
+ simdjson::document::parser parser;
36
+ auto [pj, error] = parser.parse (pstr);
37
+ if (error) {
38
+ printf (" could not parse\n " );
39
+ abort ();
40
+ }
41
+
36
42
37
- ASSERT (json.is_valid ());
38
- ParsedJson::Iterator it{json};
39
- ASSERT (it.down ());
40
- ASSERT (it.next ());
41
43
bool result;
42
44
if constexpr (std::is_same<int64_t , T>::value) {
43
- const auto actual = it. get_integer ();
44
- result = expected == actual;
45
+ int64_t actual = pj. root (). as_object ()[ " key " ]. as_int64_t ();
46
+ result = ( expected == actual) ;
45
47
} else {
46
- const auto actual = it. get_unsigned_integer ();
47
- result = expected == actual;
48
+ uint64_t actual = pj. root (). as_object ()[ " key " ]. as_uint64_t ();
49
+ result = ( expected == actual) ;
48
50
}
49
51
std::cout << std::boolalpha << " test: " << result << std::endl;
50
52
if (!result) {
@@ -56,25 +58,28 @@ static void parse_and_validate(const std::string src, T expected) {
56
58
static bool parse_and_check_signed (const std::string src) {
57
59
std::cout << " src: " << src << " , expecting signed" << std::endl;
58
60
const padded_string pstr{src};
59
- auto json = build_parsed_json (pstr);
60
-
61
- ASSERT (json.is_valid ());
62
- ParsedJson::Iterator it{json};
63
- ASSERT (it.down ());
64
- ASSERT (it.next ());
65
- return it.is_integer () && it.is_number ();
61
+ simdjson::document::parser parser;
62
+ auto [pj, error] = parser.parse (pstr);
63
+ if (error) {
64
+ printf (" could not parse\n " );
65
+ abort ();
66
+ }
67
+ auto [v,e] = pj.root ().as_object ()[" key" ];
68
+ return v.is_integer () && v.is_number ();
66
69
}
67
70
71
+
68
72
static bool parse_and_check_unsigned (const std::string src) {
69
- std::cout << " src: " << src << " , expecting unsigned " << std::endl;
73
+ std::cout << " src: " << src << " , expecting signed " << std::endl;
70
74
const padded_string pstr{src};
71
- auto json = build_parsed_json (pstr);
72
-
73
- ASSERT (json.is_valid ());
74
- ParsedJson::Iterator it{json};
75
- ASSERT (it.down ());
76
- ASSERT (it.next ());
77
- return it.is_unsigned_integer () && it.is_number ();
75
+ simdjson::document::parser parser;
76
+ auto [pj, error] = parser.parse (pstr);
77
+ if (error) {
78
+ printf (" could not parse\n " );
79
+ abort ();
80
+ }
81
+ auto [v,e] = pj.root ().as_object ()[" key" ];
82
+ return v.is_unsigned_integer () && v.is_number ();
78
83
}
79
84
80
85
0 commit comments