KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_markup_parser.cpp
Go to the documentation of this file.
1
/*
2
* This program source code file is part of KiCad, a free EDA CAD application.
3
*
4
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5
*
6
* This program is free software: you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License as published by the
8
* Free Software Foundation, either version 3 of the License, or (at your
9
* option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License along
17
* with this program. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
25
26
#include <
qa_utils/wx_utils/unit_test_utils.h
>
27
28
// Code under test
29
#include <
markup_parser.h
>
30
34
BOOST_AUTO_TEST_SUITE
( MarkupParser )
35
36
void
nodeToString
(
std
::
unique_ptr
<
MARKUP
::NODE>& aNode,
std
::
string
& aStringToPopulate )
37
{
38
aStringToPopulate +=
" {"
;
39
40
if
( aNode->isOverbar() )
41
aStringToPopulate +=
"OVER"
;
42
if
( aNode->isSubscript() )
43
aStringToPopulate +=
"SUB"
;
44
if
( aNode->isSuperscript() )
45
aStringToPopulate +=
"SUP"
;
46
47
if
( aNode->has_content() )
48
aStringToPopulate +=
"'"
+ aNode->string() +
"'"
;
49
50
for
(
auto
& c : aNode->children )
51
nodeToString
( c, aStringToPopulate );
52
53
aStringToPopulate +=
"} "
;
54
}
55
56
struct
PARSE_CASE
57
{
58
std::string
Input
;
59
std::string
ExpectedResult
;
60
};
61
65
BOOST_AUTO_TEST_CASE
( Parse )
66
{
67
68
std::vector<PARSE_CASE> cases =
69
{
70
{
71
"A normal string"
,
72
" { {'A normal string'} } "
73
},
74
{
75
"_{A subscript String}"
,
76
" { {SUB {'A subscript String'} } } "
77
},
78
{
79
"^{A superscript String}"
,
80
" { {SUP {'A superscript String'} } } "
81
},
82
{
83
"~{An overbar String}"
,
84
" { {OVER {'An overbar String'} } } "
85
},
86
{
87
"~{An incomplete markup"
,
88
" { {'~{An incomplete markup'} } "
89
},
90
{
91
"A string ~{overbar}"
,
92
" { {'A string '} {OVER {'overbar'} } } "
93
},
94
{
95
"A string ~{incomplete markup"
,
96
" { {'A string ~{incomplete markup'} } "
97
},
98
{
99
"A string ~{overbar} ~{incomplete markup"
,
100
" { {'A string '} {OVER {'overbar'} } {' ~{incomplete markup'} } "
101
},
102
{
"A string ~{incomplete markup ~{overbar}"
,
103
" { {'A string ~{incomplete markup '} {OVER {'overbar'} } } "
104
}
105
};
106
107
for
(
auto
& c : cases )
108
{
109
BOOST_TEST_INFO_SCOPE( c.Input );
110
MARKUP::MARKUP_PARSER
parser( c.Input );
111
112
std::unique_ptr<MARKUP::NODE> rootNode = parser.
Parse
();
113
BOOST_REQUIRE
( rootNode );
114
115
std::string
result
;
116
nodeToString
( rootNode,
result
);
117
118
BOOST_CHECK_EQUAL
(
result
, c.ExpectedResult );
119
120
// Uncomment for testing / generating test cases:
121
// printf( "%s\n", result.c_str() );
122
}
123
124
}
125
126
127
BOOST_AUTO_TEST_SUITE_END
()
MARKUP::MARKUP_PARSER
Definition
markup_parser.h:104
MARKUP::MARKUP_PARSER::Parse
std::unique_ptr< NODE > Parse()
Definition
markup_parser.cpp:29
unique_ptr
STL class.
markup_parser.h
MARKUP
Definition
markup_parser.h:33
std
STL namespace.
PARSE_CASE
Definition
test_markup_parser.cpp:57
PARSE_CASE::Input
std::string Input
Definition
test_markup_parser.cpp:58
PARSE_CASE::ExpectedResult
std::string ExpectedResult
Definition
test_markup_parser.cpp:59
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
nodeToString
void nodeToString(std::unique_ptr< MARKUP::NODE > &aNode, std::string &aStringToPopulate)
Declare the test suite.
Definition
test_markup_parser.cpp:36
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(Parse)
Test the #Parse method.
Definition
test_markup_parser.cpp:65
result
wxString result
Test unit parsing edge cases and error handling.
Definition
test_text_eval_numeric_compat.cpp:602
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
unit_test_utils.h
src
qa
tests
common
test_markup_parser.cpp
Generated on Sun Sep 21 2025 01:05:32 for KiCad PCB EDA Suite by
1.13.2