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 (C) 2018 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
27
28// Code under test
29#include <markup_parser.h>
30
34BOOST_AUTO_TEST_SUITE( MarkupParser )
35
36void 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
57{
58 std::string Input;
59 std::string ExpectedResult;
60};
61
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
std::unique_ptr< NODE > Parse()
STL namespace.
std::string Input
std::string ExpectedResult
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
void nodeToString(std::unique_ptr< MARKUP::NODE > &aNode, std::string &aStringToPopulate)
Declare the test suite.
BOOST_AUTO_TEST_CASE(Parse)
Test the #Parse method.