@@ -1215,7 +1215,7 @@ namespace dom_api_tests {
1215
1215
ASSERT_ERROR ( object[" d" ], NO_SUCH_FIELD );
1216
1216
return true ;
1217
1217
}));
1218
- SUBTEST (" ondemand::value" , test_ondemand_doc (json, [&](auto doc_result) {
1218
+ SUBTEST (" simdjson_result< ondemand::value> " , test_ondemand_doc (json, [&](auto doc_result) {
1219
1219
simdjson_result<ondemand::value> object = doc_result[" outer" ];
1220
1220
ASSERT_EQUAL ( object[" a" ].get_uint64 ().first , 1 );
1221
1221
ASSERT_EQUAL ( object[" b" ].get_uint64 ().first , 2 );
@@ -1690,7 +1690,7 @@ namespace ordering_tests {
1690
1690
}
1691
1691
return (x == 1.1 ) && (y == 2.2 ) && (z == 3.3 );
1692
1692
}
1693
- #endif
1693
+ #endif // SIMDJSON_EXCEPTIONS
1694
1694
1695
1695
bool run () {
1696
1696
return
@@ -1725,6 +1725,7 @@ namespace twitter_tests {
1725
1725
}));
1726
1726
TEST_SUCCEED ();
1727
1727
}
1728
+
1728
1729
#if SIMDJSON_EXCEPTIONS
1729
1730
bool twitter_example () {
1730
1731
TEST_START ();
@@ -1746,7 +1747,7 @@ namespace twitter_tests {
1746
1747
}
1747
1748
TEST_SUCCEED ();
1748
1749
}
1749
- #endif
1750
+ #endif // SIMDJSON_EXCEPTIONS
1750
1751
1751
1752
bool twitter_default_profile () {
1752
1753
TEST_START ();
@@ -1785,11 +1786,21 @@ namespace twitter_tests {
1785
1786
auto media = tweet[" entities" ][" media" ];
1786
1787
if (!media.error ()) {
1787
1788
for (auto image : media) {
1789
+ uint64_t id_val;
1790
+ std::string_view id_string;
1791
+ ASSERT_SUCCESS ( image[" id" ].get (id_val) );
1792
+ ASSERT_SUCCESS ( image[" id_str" ].get (id_string) );
1793
+ std::cout << " id = " << id_val << std::endl;
1794
+ std::cout << " id_string = " << id_string << std::endl;
1795
+
1788
1796
for (auto size : image[" sizes" ].get_object ()) {
1789
- auto size_value = size.value ().get_object ();
1797
+ std::string_view size_key;
1798
+ ASSERT_SUCCESS ( size.unescaped_key ().get (size_key) );
1799
+ std::cout << " Type of image size = " << size_key << std::endl;
1800
+
1790
1801
uint64_t width, height;
1791
- ASSERT_SUCCESS ( size_value [" w" ].get (width) );
1792
- ASSERT_SUCCESS ( size_value [" h" ].get (height) );
1802
+ ASSERT_SUCCESS ( size. value () [" w" ].get (width) );
1803
+ ASSERT_SUCCESS ( size. value () [" h" ].get (height) );
1793
1804
image_sizes.insert (make_pair (width, height));
1794
1805
}
1795
1806
}
@@ -1836,6 +1847,14 @@ namespace twitter_tests {
1836
1847
TEST_SUCCEED ();
1837
1848
}
1838
1849
1850
+ /*
1851
+ * Fun fact: id and id_str can differ:
1852
+ * 505866668485386240 and 505866668485386241.
1853
+ * Presumably, it is because doubles are used
1854
+ * at some point in the process and the number
1855
+ * 505866668485386241 cannot be represented as a double.
1856
+ * (not our fault)
1857
+ */
1839
1858
bool twitter_image_sizes_exception () {
1840
1859
TEST_START ();
1841
1860
padded_string json = padded_string::load (TWITTER_JSON);
@@ -1845,30 +1864,13 @@ namespace twitter_tests {
1845
1864
for (auto tweet : doc_result[" statuses" ]) {
1846
1865
auto media = tweet[" entities" ][" media" ];
1847
1866
if (!media.error ()) {
1848
- for (ondemand::object image : media) {
1849
- /* *
1850
- * Fun fact: id and id_str can differ:
1851
- * 505866668485386240 and 505866668485386241.
1852
- * Presumably, it is because doubles are used
1853
- * at some point in the process and the number
1854
- * 505866668485386241 cannot be represented as a double.
1855
- * (not our fault)
1856
- */
1857
- uint64_t id_val = image[" id" ];
1858
- std::cout << " id = " << id_val << std::endl;
1859
- std::string_view id_string = image[" id_str" ];
1860
- std::cout << " id_string = " << id_string << std::endl;
1867
+ for (auto image : media) {
1868
+ std::cout << " id = " << uint64_t (image[" id" ]) << std::endl;
1869
+ std::cout << " id_string = " << std::string_view (image[" id_str" ]) << std::endl;
1861
1870
for (auto size : image[" sizes" ].get_object ()) {
1862
- /* *
1863
- * We want to know the key that describes the size.
1864
- */
1865
- std::string_view raw_size_key_v = size.unescaped_key ();
1866
- std::cout << " Type of image size = " << raw_size_key_v << std::endl;
1867
- ondemand::object size_value = size.value ();
1868
- int64_t width = size_value[" w" ];
1869
- int64_t height = size_value[" h" ];
1870
- std::cout << width << " x " << height << std::endl;
1871
- image_sizes.insert (make_pair (width, height));
1871
+ std::cout << " Type of image size = " << std::string_view (size.unescaped_key ()) << std::endl;
1872
+ // NOTE: the uint64_t is required so that each value is actually parsed before the pair is created
1873
+ image_sizes.insert (make_pair<uint64_t ,uint64_t >(size.value ()[" w" ], size.value ()[" h" ]));
1872
1874
}
1873
1875
}
1874
1876
}
@@ -1879,7 +1881,7 @@ namespace twitter_tests {
1879
1881
TEST_SUCCEED ();
1880
1882
}
1881
1883
1882
- #endif
1884
+ #endif // SIMDJSON_EXCEPTIONS
1883
1885
1884
1886
bool run () {
1885
1887
return
0 commit comments