Skip to content

Commit 5fb149f

Browse files
committed
Converted inter_tests...
1 parent abb0bf9 commit 5fb149f

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

tests/basictests.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ namespace number_tests {
212212
bool powers_of_ten() {
213213
std::cout << __func__ << std::endl;
214214
char buf[1024];
215-
simdjson::ParsedJson pj;
216215
for (int i = -1000000; i <= 308; ++i) {// large negative values should be zero.
217216
auto n = sprintf(buf,"1e%d", i);
218217
buf[n] = '\0';

tests/integer_tests.cpp

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,21 @@ template <typename T>
3232
static void parse_and_validate(const std::string src, T expected) {
3333
std::cout << "src: " << src << ", ";
3434
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+
3642

37-
ASSERT(json.is_valid());
38-
ParsedJson::Iterator it{json};
39-
ASSERT(it.down());
40-
ASSERT(it.next());
4143
bool result;
4244
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);
4547
} 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);
4850
}
4951
std::cout << std::boolalpha << "test: " << result << std::endl;
5052
if(!result) {
@@ -56,25 +58,28 @@ static void parse_and_validate(const std::string src, T expected) {
5658
static bool parse_and_check_signed(const std::string src) {
5759
std::cout << "src: " << src << ", expecting signed" << std::endl;
5860
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();
6669
}
6770

71+
6872
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;
7074
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();
7883
}
7984

8085

0 commit comments

Comments
 (0)