1313
1414#import < inmemory_filesystem_utils.hpp>
1515#import < memory_stream.hpp>
16- #import < json.hpp>
16+ #import < nlohmann/ json.hpp>
1717#import < json_util.hpp>
1818
1919using json = nlohmann::json;
2525 inline Content (std::string identifier, std::string value) noexcept
2626 :identifier(std::move(identifier)), value(std::move(value))
2727 {}
28-
28+
2929 inline Content () noexcept
3030 :identifier(" " ), value(" " )
3131 {}
32-
32+
3333 std::string identifier;
3434 std::string value;
3535};
@@ -80,7 +80,7 @@ T from_memory_buffer(const std::shared_ptr<MemoryBuffer>& buffer) {
8080 for (size_t i = 0 ; i < length; ++i) {
8181 result += chars[rand () % (sizeof (chars) - 1 )];
8282 }
83-
83+
8484 return result;
8585}
8686
@@ -178,12 +178,12 @@ - (void)testWriteItemAtPath {
178178 Content content (" abc" , " xyz" );
179179 std::shared_ptr<MemoryBuffer> buffer = to_memory_buffer (content);
180180 std::error_code error;
181-
181+
182182 XCTAssertTrue (fs.make_directory ({" dir1" }, InMemoryFileSystem::Attributes (), false , error));
183183 XCTAssertTrue (fs.make_file ({" dir1" , " content.json" }, buffer, InMemoryFileSystem::Attributes (), false /* overwrite*/ , error));
184184 XCTAssertTrue (fs.make_directory ({" dir1" , " dir2" }, InMemoryFileSystem::Attributes (), false , error));
185185 XCTAssertTrue (fs.make_file ({" dir1" , " dir2" , " content.json" }, buffer, InMemoryFileSystem::Attributes (), false /* overwrite*/ , error));
186-
186+
187187 NSURL *dirURL = [[NSURL fileURLWithPath: NSTemporaryDirectory ()] URLByAppendingPathComponent: [NSUUID UUID ].UUIDString];
188188 NSFileManager *fm = [[NSFileManager alloc ] init ];
189189 NSError *localError = nil ;
@@ -220,7 +220,7 @@ - (void)testCreationFromFileSystem {
220220 NSData *data = [NSData dataWithBytesNoCopy: buffer->data () length: buffer->size () freeWhenDone: NO ];
221221 XCTAssertTrue ([data writeToURL: [dirURL URLByAppendingPathComponent: @" dir1/content.json" ] atomically: YES ]);
222222 XCTAssertTrue ([data writeToURL: [dirURL URLByAppendingPathComponent: @" dir2/content.json" ] atomically: YES ]);
223-
223+
224224 std::filesystem::path dirPath (dirURL.path .UTF8String );
225225 std::error_code error;
226226 auto fs = InMemoryFileSystem::make_from_directory (dirPath,
@@ -256,31 +256,31 @@ - (void)_testSerdeWithConfig:(SerdeVerificationConfig)config {
256256 }
257257 XCTAssertTrue (fs.write_item_to_disk ({}, dirURL.path .UTF8String , true , error));
258258 }
259-
259+
260260 // Verify serialization.
261261 std::shared_ptr<MemoryBuffer> buffer = nullptr ;
262262 {
263263 std::error_code error;
264264 auto fs = InMemoryFileSystem::make_from_directory (dirURL.path .UTF8String ,
265265 config.file_load_option ,
266266 error);
267-
267+
268268 XCTAssertTrue (fs != nullptr );
269269 size_t length = inmemoryfs::get_buffer_size_for_serialization (*fs, {}, config.alignment );
270270 switch (config.file_load_option ) {
271271 case InMemoryFileSystem::FileLoadOption::LazyMMap: {
272272 buffer = MemoryBuffer::make_using_mmap (length);
273273 break ;
274274 }
275-
275+
276276 default :
277277 buffer = MemoryBuffer::make_using_malloc (length);
278278 break ;
279279 }
280-
280+
281281 XCTAssertTrue (inmemoryfs::serialize (*fs, {}, config.alignment , buffer->data (), error));
282282 }
283-
283+
284284 // Verify de-serialization.
285285 {
286286 auto fs = inmemoryfs::make_from_buffer (buffer);
@@ -290,7 +290,7 @@ - (void)_testSerdeWithConfig:(SerdeVerificationConfig)config {
290290 XCTAssertEqual (from_memory_buffer<Content>(fs->get_file_content ({" test" , " dir" , content.identifier }, error)), content);
291291 }
292292 }
293-
293+
294294 [fm removeItemAtURL: dirURL error: nil ];
295295}
296296
@@ -332,7 +332,7 @@ - (void)testSerde {
332332 .file_base_length = 100 ,
333333 .alignment = 2 * (size_t )getpagesize (),
334334 });
335-
335+
336336 for (const auto & config : configs) {
337337 [self _testSerdeWithConfig: config];
338338 }
@@ -349,16 +349,16 @@ - (void)testReadJSONObject {
349349 auto j = json::parse (object.value ().begin (), object.value ().end ());
350350 XCTAssertEqual (j[" x" ], 1 , " The value must match" );
351351 }
352-
352+
353353 {
354354 std::stringstream ss;
355355 std::string fragment (" {\" x\" : 1" );
356356 ss << fragment;
357357 auto object = executorchcoreml::json::read_object_from_stream (ss);
358358 XCTAssertFalse (object.has_value (), " There is no closing brace, `read_json_object` must return nullopt" );
359359 }
360-
361-
360+
361+
362362 {
363363 std::stringstream ss;
364364 std::string fragment (" {\" x\" : \"\\\" 1\" }xyz" );
@@ -369,7 +369,7 @@ - (void)testReadJSONObject {
369369 std::string value = j[" x" ];
370370 XCTAssertEqual (value, std::string (" \" 1" ), " The value must match" );
371371 }
372-
372+
373373 {
374374 std::stringstream ss;
375375 std::string fragment (" {sdhalskjks}" );
@@ -384,7 +384,7 @@ - (void)testReadJSONObject {
384384 }
385385 XCTAssertNotEqual (eptr, nullptr , " Parsing invalid json object must throw an exception" );
386386 }
387-
387+
388388}
389389
390390@end
0 commit comments