1
1
#include < vcpkg-test/util.h>
2
2
3
3
#include < vcpkg/base/json.h>
4
+ #include < vcpkg/base/messages.h>
4
5
5
6
#include < iostream>
6
7
@@ -18,7 +19,7 @@ static auto u8_string_to_char_string(const char8_t (&literal)[Sz]) -> const char
18
19
#define U8_STR (s ) (u8" " s)
19
20
#endif
20
21
21
- namespace Json = vcpkg::Json ;
22
+ using namespace vcpkg ;
22
23
using Json::Value;
23
24
24
25
TEST_CASE (" JSON stringify weird strings" , " [json]" )
@@ -55,9 +56,9 @@ TEST_CASE ("JSON parse strings", "[json]")
55
56
REQUIRE (res.get ()->value .is_string ());
56
57
REQUIRE (res.get ()->value .string (VCPKG_LINE_INFO) == " \xED\xA0\x80 " );
57
58
58
- const auto make_json_string = [](vcpkg:: StringView sv) { return ' "' + sv.to_string () + ' "' ; };
59
- const vcpkg:: StringView radical = U8_STR (" ⎷" );
60
- const vcpkg:: StringView grin = U8_STR (" 😁" );
59
+ const auto make_json_string = [](StringView sv) { return ' "' + sv.to_string () + ' "' ; };
60
+ const StringView radical = U8_STR (" ⎷" );
61
+ const StringView grin = U8_STR (" 😁" );
61
62
62
63
res = Json::parse (R"( "\uD83D\uDE01")" , " test" ); // paired surrogates for grin
63
64
REQUIRE (res);
@@ -212,14 +213,14 @@ TEST_CASE ("JSON parse objects", "[json]")
212
213
213
214
TEST_CASE (" JSON parse full file" , " [json]" )
214
215
{
215
- vcpkg:: StringView json =
216
+ StringView json =
216
217
#include " large-json-document.json.inc"
217
218
;
218
219
219
220
auto res = Json::parse (json, " test" );
220
221
if (!res)
221
222
{
222
- std::cerr << res.error ()-> to_string () << ' \n ' ;
223
+ std::cerr << res.error () << ' \n ' ;
223
224
}
224
225
REQUIRE (res);
225
226
}
@@ -228,47 +229,43 @@ TEST_CASE ("JSON track newlines", "[json]")
228
229
{
229
230
auto res = Json::parse (" {\n ," , " filename" );
230
231
REQUIRE (!res);
231
- REQUIRE (res.error ()-> to_string () ==
232
- R"( filename:2:1: error: Unexpected character; expected property name
232
+ REQUIRE (res.error () ==
233
+ LocalizedString::from_raw ( R"( filename:2:1: error: Unexpected character; expected property name
233
234
on expression: ,
234
- ^)" );
235
+ ^)" )) ;
235
236
}
236
237
237
238
TEST_CASE (" JSON duplicated object keys" , " [json]" )
238
239
{
239
240
auto res = Json::parse (" {\" name\" : 1, \" name\" : 2}" , " filename" );
240
241
REQUIRE (!res);
241
- REQUIRE (res.error ()->to_string () ==
242
- R"( filename:1:13: error: Duplicated key "name" in an object
242
+ REQUIRE (res.error () == LocalizedString::from_raw (R"( filename:1:13: error: Duplicated key "name" in an object
243
243
on expression: {"name": 1, "name": 2}
244
- ^)" );
244
+ ^)" )) ;
245
245
}
246
246
247
247
TEST_CASE (" JSON support unicode characters in errors" , " [json]" )
248
248
{
249
249
// unicode characters w/ bytes >1
250
250
auto res = Json::parse (R"json( "Δx/Δt" "")json" , " filename" );
251
251
REQUIRE (!res);
252
- CHECK (res.error ()->to_string () ==
253
- R"( filename:1:9: error: Unexpected character; expected EOF
252
+ CHECK (res.error () == LocalizedString::from_raw (R"( filename:1:9: error: Unexpected character; expected EOF
254
253
on expression: "Δx/Δt" ""
255
- ^)" );
254
+ ^)" )) ;
256
255
257
256
// full width unicode characters
258
257
// note that the A is full width
259
258
res = Json::parse (R"json( "姐姐aA" "")json" , " filename" );
260
259
REQUIRE (!res);
261
- CHECK (res.error ()->to_string () ==
262
- R"( filename:1:8: error: Unexpected character; expected EOF
260
+ CHECK (res.error () == LocalizedString::from_raw (R"( filename:1:8: error: Unexpected character; expected EOF
263
261
on expression: "姐姐aA" ""
264
- ^)" );
262
+ ^)" )) ;
265
263
266
264
// incorrect errors in the face of combining characters
267
265
// (this test should be fixed once the underlying bug is fixed)
268
266
res = Json::parse (R"json( "é" "")json" , " filename" );
269
267
REQUIRE (!res);
270
- CHECK (res.error ()->to_string () ==
271
- R"( filename:1:6: error: Unexpected character; expected EOF
268
+ CHECK (res.error () == LocalizedString::from_raw (R"( filename:1:6: error: Unexpected character; expected EOF
272
269
on expression: "é" ""
273
- ^)" );
270
+ ^)" )) ;
274
271
}
0 commit comments