1+ #include " unit_test_yaml_parser_simple_array.h"
2+ #include < vector>
3+ #include < iostream>
4+ #include < fallen.h>
5+ #include < wsjcpp_yaml.h>
6+
7+ REGISTRY_UNIT_TEST (UnitTestYamlParserSimpleArray)
8+
9+ UnitTestYamlParserSimpleArray::UnitTestYamlParserSimpleArray()
10+ : UnitTestBase(" UnitTestYamlParserSimpleArray" ) {
11+ //
12+ }
13+
14+ // ---------------------------------------------------------------------
15+
16+ void UnitTestYamlParserSimpleArray::init () {
17+ // nothing
18+ }
19+
20+ // ---------------------------------------------------------------------
21+
22+ bool UnitTestYamlParserSimpleArray::run () {
23+
24+ std::string g_sTestYaml =
25+ " # simple array test\n "
26+ " param1: none value1 # it's value for something # olala \n "
27+ " array-test2 : # some comment 2 \n "
28+ " - value21 # comment v21 \n "
29+ " - value22 # comment v22 \n "
30+ " - true # comment true \n "
31+ " - falsesome \n "
32+ " - free@free \n "
33+ " - # empty \n "
34+ " - 1\n "
35+ ;
36+
37+ bool bTestSuccess = true ;
38+
39+ WSJCppYAML yaml;
40+ if (yaml.loadFromString (g_sTestYaml)) {
41+ Log::throw_err (TAG, " Error parsing" );
42+ return -1 ;
43+ }
44+
45+ WSJCppYAMLItem *pItem = nullptr ;
46+
47+ compareS (bTestSuccess, " param1-value" , yaml.getRoot ()->getElement (" param1" )->getValue (), " none value1" );
48+ compareS (bTestSuccess, " param1-line" , yaml.getRoot ()->getElement (" param1" )->getOriginalLine (), " param1: none value1 # it's value for something # olala " );
49+ compareN (bTestSuccess, " param1-original-number-of-line" , yaml.getRoot ()->getElement (" param1" )->getOriginalNumberOfLine (), 1 );
50+ compareS (bTestSuccess, " param1-comment" , yaml.getRoot ()->getElement (" param1" )->getComment (), " it's value for something # olala" );
51+
52+ compareN (bTestSuccess, " array-test2-length" , yaml.getRoot ()->getElement (" array-test2" )->getLength (), 7 );
53+ compareS (bTestSuccess, " array-test2-comment" , yaml.getRoot ()->getElement (" array-test2" )->getComment (), " some comment 2" );
54+
55+ pItem = yaml.getRoot ()->getElement (" array-test2" )->getElement (0 );
56+ compareS (bTestSuccess, " array-test2-element0-value" , pItem->getValue (), " value21" );
57+ compareS (bTestSuccess, " array-test2-element0-comment" , pItem->getComment (), " comment v21" );
58+
59+ pItem = yaml.getRoot ()->getElement (" array-test2" )->getElement (1 );
60+ compareS (bTestSuccess, " array-test2-element1-value" , pItem->getValue (), " value22" );
61+ compareS (bTestSuccess, " array-test2-element1-comment" , pItem->getComment (), " comment v22" );
62+
63+ std::string sSaved = " " ;
64+ if (yaml.saveToString (sSaved )) {
65+ compareS (bTestSuccess, " yaml_save" , sSaved ,
66+ " # simple array test\n " // expected
67+ " param1: none value1 # it's value for something # olala\n "
68+ " array-test2: # some comment 2\n "
69+ " - value21 # comment v21\n "
70+ " - value22 # comment v22\n "
71+ " - true # comment true\n "
72+ " - falsesome\n "
73+ " - free@free\n "
74+ " - # empty\n "
75+ " - 1"
76+ );
77+ } else {
78+ Log::err (TAG, " Could not save to string" );
79+ bTestSuccess = false ;
80+ }
81+ return bTestSuccess;
82+ }
0 commit comments