Skip to content

Commit d0971b6

Browse files
committed
redesing unit_test_yaml_parser_quotes to test_yaml_parser_quotes
1 parent 83c1057 commit d0971b6

4 files changed

Lines changed: 140 additions & 103 deletions

File tree

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
MIT License
3+
4+
Copyright (c) 2019-2025 wsjcpp
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
24+
Official Source Code: https://github.com/wsjcpp/wsjcpp-yaml
25+
*/
26+
27+
#include <iostream>
28+
#include <wsjcpp_yaml.h>
29+
30+
int main() {
31+
std::string sTestYaml =
32+
"# Some comment 1\n"
33+
"param1: \"value1\" # v1\n"
34+
"param2: \" #$!!!value2\" # val 2\n"
35+
"\" param3 olala\" : val 3 # val 3*** \n"
36+
"param4: ' #$!!!value4' # val 4\n"
37+
"'param5 aha': ' #$!!!value5' # val 5\n"
38+
"url: \"https://github.com/wsjcpp/wsjcpp-yaml\"\n"
39+
"issues: https://github.com/wsjcpp/wsjcpp-yaml/issues\n"
40+
"empty: \"\"\n"
41+
"array:\n"
42+
" - \"https://github.com/wsjcpp/wsjcpp-core:v0.0.1\"\n"
43+
;
44+
45+
WsjcppYaml yaml;
46+
std::string sError;
47+
if (!yaml.loadFromString("parse_quotes", sTestYaml, sError)) {
48+
std::cerr << "Error parsing: " << sError << std::endl;
49+
return -1;
50+
}
51+
52+
int ret = 0;
53+
54+
// TODO: .findLine(0)
55+
56+
if (yaml.getRoot()->getElement("param1")->getValue() != "value1") {
57+
std::cerr << "Check failed: param1" << std::endl;
58+
ret = -1;
59+
}
60+
61+
if (yaml.getRoot()->getElement("param1")->getComment() != "v1") {
62+
std::cerr << "Check failed: param1-comment" << std::endl;
63+
ret = -1;
64+
}
65+
66+
if (yaml.getRoot()->getElement("param2")->getValue() != " #$!!!value2") {
67+
std::cerr << "Check failed: param2" << std::endl;
68+
ret = -1;
69+
}
70+
71+
if (yaml.getRoot()->getElement("param2")->getComment() != "val 2") {
72+
std::cerr << "Check failed: param2-comment" << std::endl;
73+
ret = -1;
74+
}
75+
76+
if (yaml.getRoot()->getElement(" param3 olala")->getValue() != "val 3") {
77+
std::cerr << "Check failed: param3 olala" << std::endl;
78+
ret = -1;
79+
}
80+
81+
if (yaml.getRoot()->getElement(" param3 olala")->getComment() != "val 3***") {
82+
std::cerr << "Check failed: param3 olala comment" << std::endl;
83+
ret = -1;
84+
}
85+
86+
if (yaml.getRoot()->getElement("param4")->getValue() != " #$!!!value4") {
87+
std::cerr << "Check failed: param4 val" << std::endl;
88+
ret = -1;
89+
}
90+
91+
if (yaml.getRoot()->getElement("param4")->getComment() != "val 4") {
92+
std::cerr << "Check failed: param4 val" << std::endl;
93+
ret = -1;
94+
}
95+
96+
if (yaml.getRoot()->getElement("url")->getValue() != "https://github.com/wsjcpp/wsjcpp-yaml") {
97+
std::cerr << "Check failed: param4 url-value" << std::endl;
98+
ret = -1;
99+
}
100+
101+
if (yaml.getRoot()->getElement("issues")->getValue() != "https://github.com/wsjcpp/wsjcpp-yaml/issues") {
102+
std::cerr << "Check failed: param4 issues-value" << std::endl;
103+
ret = -1;
104+
}
105+
106+
if (yaml.getRoot()->getElement("empty")->getValue() != "") {
107+
std::cerr << "Check failed: param4 empty-value" << std::endl;
108+
ret = -1;
109+
}
110+
111+
if (yaml.getRoot()->getElement("array")->getElement(0)->getValue() != "https://github.com/wsjcpp/wsjcpp-core:v0.0.1") {
112+
std::cerr << "Check failed: array-element0-value" << std::endl;
113+
ret = -1;
114+
}
115+
116+
std::string sSaved = "";
117+
if (!yaml.saveToString(sSaved, sError)) {
118+
std::cerr << "Error save: " << sError << std::endl;
119+
return -1;
120+
}
121+
std::string sExpected =
122+
"# Some comment 1\n"
123+
"param1: \"value1\" # v1\n"
124+
"param2: \" #$!!!value2\" # val 2\n"
125+
"\" param3 olala\": val 3 # val 3***\n"
126+
"param4: ' #$!!!value4' # val 4\n"
127+
"'param5 aha': ' #$!!!value5' # val 5\n"
128+
"url: \"https://github.com/wsjcpp/wsjcpp-yaml\"\n"
129+
"issues: https://github.com/wsjcpp/wsjcpp-yaml/issues\n"
130+
"empty: \"\"\n"
131+
"array:\n"
132+
" - \"https://github.com/wsjcpp/wsjcpp-core:v0.0.1\"\n"
133+
;
134+
if (sSaved != sExpected) {
135+
std::cerr << "Check failed: not equal" << std::endl;
136+
ret = -1;
137+
}
138+
139+
return ret;
140+
}

unit-tests.wsjcpp/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ list (APPEND WSJCPP_SOURCES "${CMAKE_SOURCE_DIR}/../src/wsjcpp_yaml.h")
3636
list (APPEND WSJCPP_INCLUDE_DIRS "src")
3737
list (APPEND WSJCPP_SOURCES "${CMAKE_SOURCE_DIR}/../unit-tests.wsjcpp/src/unit_test_yaml_parser_simple_array.cpp")
3838
list (APPEND WSJCPP_SOURCES "${CMAKE_SOURCE_DIR}/../unit-tests.wsjcpp/src/unit_test_yaml_parser_simple_map.cpp")
39-
list (APPEND WSJCPP_SOURCES "${CMAKE_SOURCE_DIR}/../unit-tests.wsjcpp/src/unit_test_yaml_parser_quotes.cpp")
4039
list (APPEND WSJCPP_SOURCES "${CMAKE_SOURCE_DIR}/../unit-tests.wsjcpp/src/unit_test_read_yaml.cpp")
4140
list (APPEND WSJCPP_SOURCES "${CMAKE_SOURCE_DIR}/../unit-tests.wsjcpp/src/unit_test_cursor.cpp")
4241
list (APPEND WSJCPP_SOURCES "${CMAKE_SOURCE_DIR}/../unit-tests.wsjcpp/src/unit_test_append_elements.cpp")

unit-tests.wsjcpp/src/unit_test_yaml_parser_quotes.cpp

Lines changed: 0 additions & 100 deletions
This file was deleted.

wsjcpp.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ unit-tests:
4242
description: Test Parse Array
4343
- name: YamlParserSimpleMap
4444
description: Test Parse Map
45-
- name: YamlParserQuotes
46-
description: YamlParserQuotes
4745
- name: "ReadYaml"
4846
description: ""
4947
- name: "Cursor"

0 commit comments

Comments
 (0)