44#include " wsjcpp_yaml.h"
55#include " fallen.h"
66
7- int g_nErrors = 0 ;
8- std::string g_sTestYaml =
9- " # Some comment 1\n "
10- " test10: one\n "
11- " test20: two # some comment 2\n "
12- " \n " // empty line
13- " array30:\n "
14- " - one31 # this field for test array30 \n "
15- " - two32\n "
16- " - three33\n "
17- " \n " // empty line
18- " array40: # some comment 3\n "
19- " - \" one#1\" # some comment\n "
20- " # some comment\n "
21- " - \" two#2\"\n "
22- " array50: # some comment 3\n "
23- " - p1: test501\n "
24- " p2: test502\n "
25- " - p1: test503\n "
26- " p2: test504\n "
27- " \n " // empty line
28- " map60: # some comment 4\n "
29- " test70: opa1\n "
30- " test80: opa2\n "
31- ;
32-
33- void check (std::string sTestName , std::string sGotValue , std::string sExpectedValue ) {
34- if (sGotValue != sExpectedValue ) {
35- Log::err (sTestName , " Expected value: '" + sExpectedValue + " ', but got: '" + sGotValue + " '" );
36- g_nErrors++;
37- return ;
38- }
39- Log::ok (sTestName , " fine" );
40- };
41-
42- void check (std::string sTestName , bool bGotValue, bool bExpectedValue) {
43- std::string sGotValue = bGotValue ? " yes" : " no" ;
44- std::string sExpectedValue = bExpectedValue ? " yes" : " no" ;
45- if (sGotValue != sExpectedValue ) {
46- Log::err (sTestName , " Expected value: '" + sExpectedValue + " ', but got: '" + sGotValue + " '" );
47- g_nErrors++;
48- return ;
49- }
50- Log::ok (sTestName , " fine" );
51- };
52-
53-
547int main (int argc, char * argv[]) {
558 std::string TAG = " MAIN" ;
569 std::string appName = std::string (WSJCPP_NAME);
@@ -61,67 +14,7 @@ int main(int argc, char* argv[]) {
6114 Fallen::makeDir (appLogPath);
6215 }
6316
64- // tests
65-
66-
67- WSJCppYAML yaml;
68- if (yaml.loadFromString (g_sTestYaml)) {
69- Log::throw_err (TAG, " Error parsing" );
70- return -1 ;
71- }
72- std::string sSaved = " " ;
73- if (yaml.saveToString (sSaved )) {
74- Log::info (TAG, " \n >>>>\n " + sSaved );
75- }
76-
77- WSJCppYAMLItem *pItem = nullptr ;
78- check (" test10" , yaml.getRoot ()->getElement (" test10" )->getValue (), " one" );
79- check (" test20" , yaml.getRoot ()->getElement (" test20" )->getValue (), " two" );
80-
81- pItem = yaml.getRoot ()->getElement (" array30" );
82- check (" array30_length" , pItem->getLength (), 3 );
83- pItem = yaml.getRoot ()->getElement (" array30" )->getElement (0 );
84- check (" test30_value" , pItem->getValue (), " one31" );
85- check (" test30_comment" , pItem->getComment (), " this field for test array30 " );
86- pItem = yaml.getRoot ()->getElement (" array30" )->getElement (1 );
87- check (" test40_value" , pItem->getValue (), " two32" );
88- check (" test40_comment" , pItem->getComment (), " " );
89-
90- pItem = yaml.getRoot ()->getElement (" array40" );
91- check (" array40_length" , pItem->getLength (), 2 );
92-
93- pItem = yaml.getRoot ()->getElement (" array50" );
94- check (" array50_length" , pItem->getLength (), 1 );
95-
96- pItem = yaml.getRoot ()->getElement (" map60" )->getElement (" test70" );
97- check (" test70_value" , pItem->getValue (), " opa1" );
98-
99- pItem = yaml.getRoot ()->getElement (" map60" )->getElement (" test80" );
100- check (" test80_comment" , pItem->getValue (), " opa2" );
101-
102- std::string sTestExpectedYaml =
103- " # Some comment 1\n "
104- " test: one\n "
105- " test2: two # some comment 2\n "
106- " \n " // empty line
107- " array:\n "
108- " - one\n "
109- " - two\n "
110- " \n " // empty line
111- " array2: # some comment 3\n "
112- " - \" one#1\"\n "
113- " - \" two#2\"\n "
114- " \n " // empty line
115- " map: # some comment 4\n "
116- " test3: 1\n "
117- " test4: 2\n "
118- " \n " // empty line
119- ;
120-
121- sSaved = " " ;
122- if (yaml.saveToString (sSaved )) {
123- check (" yaml_save" , sSaved , sTestExpectedYaml );
124- }
17+ // TODO load and check yaml format
12518
12619 return 0 ;
12720}
0 commit comments