Skip to content

Commit 2677323

Browse files
committed
Committing clang-format changes
1 parent 885c91d commit 2677323

File tree

1 file changed

+46
-33
lines changed

1 file changed

+46
-33
lines changed

tests/example_json/example_json.cpp

+46-33
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static_assert(glz::detail::reflectable<BasicStruct>);
2121
// Demonstration of reading and writing a basic reflectable struct without `glz::meta`.
2222
suite basic_reflection = [] {
2323
"basic_struct_reflection"_test = [] {
24-
BasicStruct obj{42, 3.14, "Hello", {1,2,3}};
24+
BasicStruct obj{42, 3.14, "Hello", {1, 2, 3}};
2525
std::string json;
2626
expect(not glz::write_json(obj, json));
2727
expect(json == R"({"i":42,"d":3.14,"str":"Hello","arr":[1,2,3]})");
@@ -31,7 +31,7 @@ suite basic_reflection = [] {
3131
expect(obj2.i == 42);
3232
expect(obj2.d == 3.14);
3333
expect(obj2.str == "Hello");
34-
expect(obj2.arr == std::array<uint32_t,3>{1,2,3});
34+
expect(obj2.arr == std::array<uint32_t, 3>{1, 2, 3});
3535
};
3636
};
3737

@@ -135,11 +135,11 @@ suite enum_test = [] {
135135
//------------------------------------
136136
struct ContainerStruct
137137
{
138-
std::vector<int> vec{1,2,3};
139-
std::array<std::string, 2> arr{"Hello","World"};
140-
std::tuple<int,double,std::string> tup{42, 2.718, "pi?"};
138+
std::vector<int> vec{1, 2, 3};
139+
std::array<std::string, 2> arr{"Hello", "World"};
140+
std::tuple<int, double, std::string> tup{42, 2.718, "pi?"};
141141
std::deque<float> dq{3.14f, 2.71f};
142-
std::list<int> lis{10,11,12};
142+
std::list<int> lis{10, 11, 12};
143143
};
144144
static_assert(glz::detail::reflectable<ContainerStruct>);
145145

@@ -149,12 +149,13 @@ suite container_test = [] {
149149
std::string json;
150150
expect(not glz::write_json(c, json));
151151
// Check output structure includes all
152-
expect(json == R"({"vec":[1,2,3],"arr":["Hello","World"],"tup":[42,2.718,"pi?"],"dq":[3.14,2.71],"lis":[10,11,12]})");
152+
expect(json ==
153+
R"({"vec":[1,2,3],"arr":["Hello","World"],"tup":[42,2.718,"pi?"],"dq":[3.14,2.71],"lis":[10,11,12]})");
153154

154155
ContainerStruct c2{};
155156
expect(!glz::read_json(c2, json));
156-
expect(c2.vec == std::vector<int>{1,2,3});
157-
expect(c2.lis == std::list<int>{10,11,12});
157+
expect(c2.vec == std::vector<int>{1, 2, 3});
158+
expect(c2.lis == std::list<int>{10, 11, 12});
158159
expect(std::get<2>(c2.tup) == "pi?");
159160
};
160161
};
@@ -164,8 +165,8 @@ suite container_test = [] {
164165
//------------------------------------
165166
struct MapStruct
166167
{
167-
std::map<std::string,int> str_map{{"one",1},{"two",2}};
168-
std::unordered_map<int,std::string> umap{{5,"five"},{7,"seven"}};
168+
std::map<std::string, int> str_map{{"one", 1}, {"two", 2}};
169+
std::unordered_map<int, std::string> umap{{5, "five"}, {7, "seven"}};
169170
};
170171
static_assert(glz::detail::reflectable<MapStruct>);
171172

@@ -189,8 +190,14 @@ suite map_test = [] {
189190
//------------------------------------
190191
// Variants
191192
//------------------------------------
192-
struct VarA { int x{}; };
193-
struct VarB { double y{}; };
193+
struct VarA
194+
{
195+
int x{};
196+
};
197+
struct VarB
198+
{
199+
double y{};
200+
};
194201

195202
template <>
196203
struct glz::meta<VarA>
@@ -248,7 +255,7 @@ struct PartialStruct
248255
suite partial_test = [] {
249256
"partial_write"_test = [] {
250257
PartialStruct p{};
251-
static constexpr auto selected = glz::json_ptrs("/a","/c");
258+
static constexpr auto selected = glz::json_ptrs("/a", "/c");
252259
std::string json;
253260
expect(not glz::write_json<selected>(p, json));
254261
expect(json == R"({"a":1,"c":3})");
@@ -296,7 +303,7 @@ struct RawExample
296303

297304
suite formatting_and_raw = [] {
298305
"prettify_minify"_test = [] {
299-
PrettifyStruct pd{123,"Hello"};
306+
PrettifyStruct pd{123, "Hello"};
300307
std::string json;
301308
expect(!glz::write_json(pd, json));
302309
// Minify is default, let's prettify
@@ -321,25 +328,25 @@ suite formatting_and_raw = [] {
321328
//------------------------------------
322329
struct PointerStruct
323330
{
324-
std::array<int,3> arr{10,20,30};
325-
std::map<std::string,std::string> m{{"key","value"}};
331+
std::array<int, 3> arr{10, 20, 30};
332+
std::map<std::string, std::string> m{{"key", "value"}};
326333
};
327334

328335
suite pointer_access = [] {
329336
"json_pointer_get_set"_test = [] {
330337
PointerStruct ps{};
331-
auto val = glz::get<int>(ps,"/arr/1");
338+
auto val = glz::get<int>(ps, "/arr/1");
332339
expect(val.has_value());
333340
if (val) expect(val.value().get() == 20);
334341

335-
glz::set(ps,"/arr/1",42);
342+
glz::set(ps, "/arr/1", 42);
336343
expect(ps.arr[1] == 42);
337344

338-
auto map_val = glz::get<std::string>(ps,"/m/key");
345+
auto map_val = glz::get<std::string>(ps, "/m/key");
339346
expect(map_val.has_value());
340347
if (map_val) expect(map_val.value().get() == "value");
341348

342-
glz::set(ps,"/m/key","new_value");
349+
glz::set(ps, "/m/key", "new_value");
343350
expect(ps.m["key"] == "new_value");
344351
};
345352
};
@@ -357,17 +364,17 @@ struct NDJItem
357364

358365
suite ndjson_test = [] {
359366
"ndjson_io"_test = [] {
360-
std::vector<NDJItem> items{{1,"A"},{2,"B"}};
367+
std::vector<NDJItem> items{{1, "A"}, {2, "B"}};
361368

362369
std::string ndjson;
363370
// NDJSON = each object on a newline
364-
expect(not glz::write<glz::opts{.format=glz::NDJSON}>(items, ndjson));
371+
expect(not glz::write<glz::opts{.format = glz::NDJSON}>(items, ndjson));
365372
// Should look like:
366373
// {"x":1,"y":"A"}
367374
// {"x":2,"y":"B"}
368375

369376
std::vector<NDJItem> read_back;
370-
expect(!glz::read<glz::opts{.format=glz::NDJSON}>(read_back, ndjson));
377+
expect(!glz::read<glz::opts{.format = glz::NDJSON}>(read_back, ndjson));
371378
expect(read_back.size() == 2);
372379
expect(read_back[0].x == 1 && read_back[0].y == "A");
373380
};
@@ -405,7 +412,7 @@ suite float_precision_test = [] {
405412
FloatPrecision fp{};
406413
std::string json;
407414
// limit float precision to float32
408-
expect(not glz::write<glz::opts{.float_max_write_precision=glz::float_precision::float32}>(fp, json));
415+
expect(not glz::write<glz::opts{.float_max_write_precision = glz::float_precision::float32}>(fp, json));
409416
// This should produce fewer decimal places.
410417
expect(json.find("3.1415927") != std::string::npos); // approximate float32 rounding
411418
};
@@ -424,15 +431,18 @@ struct SchemaDemo
424431
template <>
425432
struct glz::json_schema<SchemaDemo>
426433
{
427-
schema x{.description="An integer x"};
428-
schema name{.description="A name for something"};
429-
schema flag{.description="A boolean flag"};
434+
schema x{.description = "An integer x"};
435+
schema name{.description = "A name for something"};
436+
schema flag{.description = "A boolean flag"};
430437
};
431438

432439
suite schema_generation = [] {
433440
"schema_demo"_test = [] {
434441
auto schema = glz::write_json_schema<SchemaDemo>().value_or("error");
435-
expect(schema == R"({"type":["object"],"properties":{"flag":{"$ref":"#/$defs/bool","description":"A boolean flag"},"name":{"$ref":"#/$defs/std::string","description":"A name for something"},"x":{"$ref":"#/$defs/int32_t","description":"An integer x"}},"additionalProperties":false,"$defs":{"bool":{"type":["boolean"]},"int32_t":{"type":["integer"],"minimum":-2147483648,"maximum":2147483647},"std::string":{"type":["string"]}}})") << schema;
442+
expect(
443+
schema ==
444+
R"({"type":["object"],"properties":{"flag":{"$ref":"#/$defs/bool","description":"A boolean flag"},"name":{"$ref":"#/$defs/std::string","description":"A name for something"},"x":{"$ref":"#/$defs/int32_t","description":"An integer x"}},"additionalProperties":false,"$defs":{"bool":{"type":["boolean"]},"int32_t":{"type":["integer"],"minimum":-2147483648,"maximum":2147483647},"std::string":{"type":["string"]}}})")
445+
<< schema;
436446
};
437447
};
438448

@@ -449,16 +459,19 @@ struct LocalSchema
449459

450460
struct glaze_json_schema
451461
{
452-
glz::schema count{.description="A count"};
453-
glz::schema file{.description="A file path"};
454-
glz::schema valid{.description="Validity flag"};
462+
glz::schema count{.description = "A count"};
463+
glz::schema file{.description = "A file path"};
464+
glz::schema valid{.description = "Validity flag"};
455465
};
456466
};
457467

458468
suite local_schema_test = [] {
459469
"local_schema"_test = [] {
460470
auto schema = glz::write_json_schema<LocalSchema>().value_or("error");
461-
expect(schema == R"({"type":["object"],"properties":{"count":{"$ref":"#/$defs/int32_t","description":"A count"},"file":{"$ref":"#/$defs/std::string","description":"A file path"},"valid":{"$ref":"#/$defs/bool","description":"Validity flag"}},"additionalProperties":false,"$defs":{"bool":{"type":["boolean"]},"int32_t":{"type":["integer"],"minimum":-2147483648,"maximum":2147483647},"std::string":{"type":["string"]}}})") << schema;
471+
expect(
472+
schema ==
473+
R"({"type":["object"],"properties":{"count":{"$ref":"#/$defs/int32_t","description":"A count"},"file":{"$ref":"#/$defs/std::string","description":"A file path"},"valid":{"$ref":"#/$defs/bool","description":"Validity flag"}},"additionalProperties":false,"$defs":{"bool":{"type":["boolean"]},"int32_t":{"type":["integer"],"minimum":-2147483648,"maximum":2147483647},"std::string":{"type":["string"]}}})")
474+
<< schema;
462475
};
463476
};
464477

0 commit comments

Comments
 (0)