@@ -99,6 +99,25 @@ function(test_reading_int)
99
99
)
100
100
endfunction ()
101
101
102
+ function (test_reading_map_list_entry )
103
+ set (expected_length 2 )
104
+ set (expected_name "MapEntry1" )
105
+ set (expected_int 5 )
106
+ yaml_length (actual_length NAME yaml-test KEY cmake test map-list )
107
+ yaml_get (actual_name NAME yaml-test KEY cmake test map-list 0 map-entry-name )
108
+ yaml_get (actual_int NAME yaml-test KEY cmake test map-list 0 map-entry-int )
109
+
110
+ test_assert (TEST ${expected_length} EQUAL ${actual_length}
111
+ COMMENT "yaml key value does not match expectation."
112
+ )
113
+ test_assert (TEST ${expected_name} STREQUAL ${actual_name}
114
+ COMMENT "yaml key value does not match expectation."
115
+ )
116
+ test_assert (TEST ${expected_int} EQUAL ${actual_int}
117
+ COMMENT "yaml key value does not match expectation."
118
+ )
119
+ endfunction ()
120
+
102
121
function (test_reading_not_found )
103
122
set (expected cmake-missing-NOTFOUND )
104
123
yaml_get (actual NAME yaml-test KEY cmake missing test key )
@@ -126,6 +145,15 @@ function(test_reading_not_array)
126
145
)
127
146
endfunction ()
128
147
148
+ function (test_reading_not_found_map_list_entry )
149
+ set (expected cmake-test-map-list-3-NOTFOUND )
150
+ yaml_get (actual NAME yaml-test KEY cmake test map-list 3 map-entry-name )
151
+
152
+ test_assert (TEST ${expected} STREQUAL ${actual}
153
+ COMMENT "Expected -NOTFOUND, but something was found."
154
+ )
155
+ endfunction ()
156
+
129
157
function (test_save_new_file )
130
158
yaml_save (NAME yaml-test FILE ${CMAKE_BINARY_DIR} /${CMAKE_CURRENT_FUNCTION}_test_save.yaml )
131
159
@@ -260,6 +288,137 @@ function(test_setting_list_int)
260
288
endforeach ()
261
289
endfunction ()
262
290
291
+ function (test_setting_map_list_entry )
292
+ yaml_create (FILE ${CMAKE_BINARY_DIR} /${CMAKE_CURRENT_FUNCTION}_test_create.yaml
293
+ NAME ${CMAKE_CURRENT_FUNCTION} _yaml-create
294
+ )
295
+
296
+ set (new_entry_name_0 MapEntryNew1 )
297
+ set (new_entry_int_0 42 )
298
+ set (new_entry_name_1 MapEntryNew2 )
299
+ set (new_entry_int_1 24 )
300
+ set (new_entry_name_2 MapEntryNew3 )
301
+ set (new_entry_int_2 4224 )
302
+ yaml_set (actual NAME ${CMAKE_CURRENT_FUNCTION} _yaml-create
303
+ KEY cmake test set map-list LIST
304
+ MAP "map-entry-name: ${new_entry_name_0} , map-entry-int: ${new_entry_int_0} "
305
+ MAP "map-entry-name: ${new_entry_name_1} , map-entry-int: ${new_entry_int_1} "
306
+ MAP "map-entry-name: ${new_entry_name_2} , map-entry-int: ${new_entry_int_2} "
307
+ )
308
+
309
+ yaml_save (NAME ${CMAKE_CURRENT_FUNCTION} _yaml-create )
310
+
311
+ # Read-back the yaml and verify the values.
312
+ yaml_load (FILE ${CMAKE_BINARY_DIR} /${CMAKE_CURRENT_FUNCTION}_test_create.yaml
313
+ NAME ${CMAKE_CURRENT_FUNCTION} _readback
314
+ )
315
+
316
+ yaml_length (readback NAME ${CMAKE_CURRENT_FUNCTION} _readback KEY cmake test set map-list )
317
+
318
+ test_assert (TEST 3 EQUAL ${readback}
319
+ COMMENT "readback yaml list length does not match original."
320
+ )
321
+
322
+ foreach (index 0 1 2 )
323
+ yaml_get (readback_name NAME ${CMAKE_CURRENT_FUNCTION} _readback KEY cmake test set map-list ${index} map-entry-name )
324
+ yaml_get (readback_int NAME ${CMAKE_CURRENT_FUNCTION} _readback KEY cmake test set map-list ${index} map-entry-int )
325
+
326
+ test_assert (TEST "${readback_name} " STREQUAL "${new_entry_name_${index} }"
327
+ COMMENT "list values mismatch."
328
+ )
329
+ test_assert (TEST "${readback_int} " EQUAL "${new_entry_int_${index} }"
330
+ COMMENT "list values mismatch."
331
+ )
332
+ endforeach ()
333
+ endfunction ()
334
+
335
+ function (test_setting_map_list_entry_windows )
336
+ yaml_create (FILE ${CMAKE_BINARY_DIR} /${CMAKE_CURRENT_FUNCTION}_test_create.yaml
337
+ NAME ${CMAKE_CURRENT_FUNCTION} _yaml-create
338
+ )
339
+
340
+ set (new_entry_name_0 MapEntryWindowsPath1 )
341
+ set (new_entry_path_0 "c:/tmp/zephyr" )
342
+ set (new_entry_name_1 MapEntryWindowsPath2 )
343
+ set (new_entry_path_1 "c:/program files/space" )
344
+ set (new_entry_name_2 MapEntryWindowsPath3 )
345
+ set (new_entry_path_2 "D:/alternative/drive" )
346
+ yaml_set (actual NAME ${CMAKE_CURRENT_FUNCTION} _yaml-create
347
+ KEY cmake test set map-list LIST
348
+ MAP "map-entry-name: ${new_entry_name_0} , map-entry-path: ${new_entry_path_0} "
349
+ MAP "map-entry-name: ${new_entry_name_1} , map-entry-path: ${new_entry_path_1} "
350
+ MAP "map-entry-name: ${new_entry_name_2} , map-entry-path: ${new_entry_path_2} "
351
+ )
352
+
353
+ yaml_save (NAME ${CMAKE_CURRENT_FUNCTION} _yaml-create )
354
+
355
+ # Read-back the yaml and verify the values.
356
+ yaml_load (FILE ${CMAKE_BINARY_DIR} /${CMAKE_CURRENT_FUNCTION}_test_create.yaml
357
+ NAME ${CMAKE_CURRENT_FUNCTION} _readback
358
+ )
359
+
360
+ yaml_length (readback NAME ${CMAKE_CURRENT_FUNCTION} _readback KEY cmake test set map-list )
361
+
362
+ test_assert (TEST 3 EQUAL ${readback}
363
+ COMMENT "readback yaml list length does not match original."
364
+ )
365
+
366
+ foreach (index 0 1 2 )
367
+ yaml_get (readback_name NAME ${CMAKE_CURRENT_FUNCTION} _readback KEY cmake test set map-list ${index} map-entry-name )
368
+ yaml_get (readback_path NAME ${CMAKE_CURRENT_FUNCTION} _readback KEY cmake test set map-list ${index} map-entry-path )
369
+
370
+ test_assert (TEST "${readback_name} " STREQUAL "${new_entry_name_${index} }"
371
+ COMMENT "list values mismatch."
372
+ )
373
+ test_assert (TEST "${readback_path} " STREQUAL "${new_entry_path_${index} }"
374
+ COMMENT "list values mismatch."
375
+ )
376
+ endforeach ()
377
+ endfunction ()
378
+
379
+ function (test_setting_map_list_entry_commas )
380
+ yaml_create (FILE ${CMAKE_BINARY_DIR} /${CMAKE_CURRENT_FUNCTION}_test_create.yaml
381
+ NAME ${CMAKE_CURRENT_FUNCTION} _yaml-create
382
+ )
383
+
384
+ set (new_entry_name_0 TestString1 )
385
+ set (new_entry_str_0 "'A\\ ,string'" )
386
+ set (new_entry_name_1 TestString2 )
387
+ set (new_entry_str_1 "'\\ , is first'" )
388
+ set (new_entry_name_2 TestString3 )
389
+ set (new_entry_str_2 "'\\ , and : is\\ ,everywhere\\ ,'" )
390
+ yaml_set (actual NAME ${CMAKE_CURRENT_FUNCTION} _yaml-create
391
+ KEY cmake test set map-list LIST
392
+ MAP "map-entry-name: ${new_entry_name_0} , map-entry-str: ${new_entry_str_0} "
393
+ MAP "map-entry-name: ${new_entry_name_1} , map-entry-str: ${new_entry_str_1} "
394
+ MAP "map-entry-name: ${new_entry_name_2} , map-entry-str: ${new_entry_str_2} "
395
+ )
396
+
397
+ yaml_save (NAME ${CMAKE_CURRENT_FUNCTION} _yaml-create )
398
+
399
+ # Read-back the yaml and verify the values.
400
+ yaml_load (FILE ${CMAKE_BINARY_DIR} /${CMAKE_CURRENT_FUNCTION}_test_create.yaml
401
+ NAME ${CMAKE_CURRENT_FUNCTION} _readback
402
+ )
403
+
404
+ yaml_length (readback NAME ${CMAKE_CURRENT_FUNCTION} _readback KEY cmake test set map-list )
405
+
406
+ test_assert (TEST 3 EQUAL ${readback}
407
+ COMMENT "readback yaml list length does not match original."
408
+ )
409
+
410
+ foreach (index 0 1 2 )
411
+ yaml_get (readback_name NAME ${CMAKE_CURRENT_FUNCTION} _readback KEY cmake test set map-list ${index} map-entry-name )
412
+ yaml_get (readback_str NAME ${CMAKE_CURRENT_FUNCTION} _readback KEY cmake test set map-list ${index} map-entry-str )
413
+
414
+ test_assert (TEST "${readback_name} " STREQUAL "${new_entry_name_${index} }"
415
+ COMMENT "list values mismatch."
416
+ )
417
+ test_assert (TEST "'${readback_str} '" STREQUAL "${new_entry_str_${index} }"
418
+ COMMENT "list values mismatch."
419
+ )
420
+ endforeach ()
421
+ endfunction ()
263
422
function (test_setting_empty_value )
264
423
yaml_create (FILE ${CMAKE_BINARY_DIR} /${CMAKE_CURRENT_FUNCTION}_test_create.yaml
265
424
NAME ${CMAKE_CURRENT_FUNCTION} _yaml-create
@@ -384,16 +543,21 @@ test_reading_string()
384
543
test_reading_int ()
385
544
test_reading_list_strings ()
386
545
test_reading_list_int ()
546
+ test_reading_map_list_entry ()
387
547
test_reading_not_found ()
388
548
test_reading_not_found_array ()
389
549
test_reading_not_array ()
550
+ test_reading_not_found_map_list_entry ()
390
551
391
552
test_save_new_file ()
392
553
393
554
test_setting_int ()
394
555
test_setting_string ()
395
556
test_setting_list_strings ()
396
557
test_setting_list_int ()
558
+ test_setting_map_list_entry ()
559
+ test_setting_map_list_entry_windows ()
560
+ test_setting_map_list_entry_commas ()
397
561
398
562
test_setting_empty_value ()
399
563
test_setting_empty_list ()
0 commit comments