KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_altium_rule_transformer.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) 2021 KiCad Developers, see AUTHORS.TXT for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
30
32
34{
36};
37
38
42BOOST_FIXTURE_TEST_SUITE( AltiumRuleTransformer, ALTIUM_RULE_TRANSFORMER_FIXTURE )
43
44
45BOOST_AUTO_TEST_CASE( AltiumRuleTokenizerEmptyInput )
46{
47 ALTIUM_RULE_TOKENIZER tokenizer( "" );
48
49 const ALTIUM_RULE_TOKEN& peek = tokenizer.Peek();
51 BOOST_CHECK_EQUAL( 0, peek.pos );
52
53 const ALTIUM_RULE_TOKEN& next = tokenizer.Next();
55 BOOST_CHECK_EQUAL( 0, next.pos );
56
57 const ALTIUM_RULE_TOKEN& peek2 = tokenizer.Peek();
59 BOOST_CHECK_EQUAL( 0, peek2.pos );
60}
61
62BOOST_AUTO_TEST_CASE( AltiumRuleTokenizerOnlySpaces )
63{
64 ALTIUM_RULE_TOKENIZER tokenizer( " " );
65
66 const ALTIUM_RULE_TOKEN& peek = tokenizer.Peek();
68 BOOST_CHECK_EQUAL( 3, peek.pos );
69
70 const ALTIUM_RULE_TOKEN& next = tokenizer.Next();
72 BOOST_CHECK_EQUAL( 3, next.pos );
73
74 const ALTIUM_RULE_TOKEN& peek2 = tokenizer.Peek();
76 BOOST_CHECK_EQUAL( 3, peek2.pos );
77}
78
79BOOST_AUTO_TEST_CASE( AltiumRuleTokenizerSingleCharIdentifier )
80{
81 ALTIUM_RULE_TOKENIZER tokenizer( "a" );
82
83 const ALTIUM_RULE_TOKEN& next = tokenizer.Next();
85 BOOST_CHECK_EQUAL( 0, next.pos );
86 BOOST_CHECK_EQUAL( "a", next.sValue );
87
88 const ALTIUM_RULE_TOKEN& peek = tokenizer.Peek();
90 BOOST_CHECK_EQUAL( 1, peek.pos );
91
92 const ALTIUM_RULE_TOKEN& next2 = tokenizer.Next();
94 BOOST_CHECK_EQUAL( 1, next2.pos );
95}
96
97
99{
100 wxString input;
101 std::vector<ALTIUM_RULE_TOKEN> exp_token;
102};
103
107static const std::vector<ALTIUM_RULE_TOKENIZER_INPUT_OUTPUT> altium_rule_tokens_property = {
108 // Empty string
109 { "",
110 {
113 }
114 },
115 // Single Token
116 { "All",
117 {
118 { ALTIUM_RULE_TOKEN_KIND::IDENT, 0, "All" },
120 }
121 },
122 { "1234",
123 {
126 }
127 },
128 { "+1234",
129 {
132 }
133 },
134 { "-1234",
135 {
138 }
139 },
140 { "'1234'",
141 {
144 }
145 },
146 { "True",
147 {
150 }
151 },
152 { "true",
153 {
156 }
157 },
158 { "False",
159 {
162 }
163 },
164 { "false",
165 {
168 }
169 },
170 { "+",
171 {
174 }
175 },
176 { "-",
177 {
180 }
181 },
182 { "*",
183 {
186 }
187 },
188 { "/",
189 {
192 }
193 },
194 { "Div",
195 {
198 }
199 },
200 { "div",
201 {
204 }
205 },
206 { "Mod",
207 {
210 }
211 },
212 { "mod",
213 {
216 }
217 },
218 { "And",
219 {
222 }
223 },
224 { "and",
225 {
228 }
229 },
230 { "&&",
231 {
234 }
235 },
236 { "Or",
237 {
240 }
241 },
242 { "or",
243 {
246 }
247 },
248 { "||",
249 {
252 }
253 },
254 { "Xor",
255 {
258 }
259 },
260 { "xor",
261 {
264 }
265 },
266 { "Not",
267 {
270 }
271 },
272 { "not",
273 {
276 }
277 },
278 { "<",
279 {
282 }
283 },
284 { "<=",
285 {
288 }
289 },
290 { ">",
291 {
294 }
295 },
296 { ">=",
297 {
300 }
301 },
302 { "<>",
303 {
306 }
307 },
308 { "=",
309 {
312 }
313 },
314 { "Between",
315 {
318 }
319 },
320 { "between",
321 {
324 }
325 },
326 { "Like",
327 {
330 }
331 },
332 { "like",
333 {
336 }
337 },
338 // Multiple tokens
339 { "ab cd ef",
340 {
345 }
346 },
347 // Complex tests
348 { "InComponent('LEDS1') or InComponent('LEDS2')",
349 {
350 { ALTIUM_RULE_TOKEN_KIND::IDENT, 0, "InComponent" },
355 { ALTIUM_RULE_TOKEN_KIND::IDENT, 24, "InComponent" },
360 }
361 }
362};
363
367BOOST_AUTO_TEST_CASE( AltiumRuleTokenizerParameterizedTest )
368{
369 for( const auto& c : altium_rule_tokens_property )
370 {
371 BOOST_TEST_CONTEXT( wxString::Format( wxT( "'%s'" ), c.input ) )
372 {
373 ALTIUM_RULE_TOKENIZER tokenizer( c.input );
374
375 for( const auto& expected : c.exp_token )
376 {
377 const ALTIUM_RULE_TOKEN& token = tokenizer.Next();
378 BOOST_CHECK( ( expected.kind == token.kind ) );
379 BOOST_CHECK_EQUAL( expected.pos, token.pos );
380 BOOST_CHECK_EQUAL( expected.iValue, token.iValue );
381 BOOST_CHECK_EQUAL( expected.fValue, token.fValue );
382 BOOST_CHECK_EQUAL( expected.sValue, token.sValue );
383 }
384 }
385 }
386}
387
388BOOST_AUTO_TEST_SUITE_END()
const ALTIUM_RULE_TOKEN & Peek() const
const ALTIUM_RULE_TOKEN & Next()
CITER next(CITER it)
Definition: ptree.cpp:126
std::vector< ALTIUM_RULE_TOKEN > exp_token
ALTIUM_RULE_TOKEN_KIND kind
BOOST_AUTO_TEST_CASE(AltiumRuleTokenizerEmptyInput)
Declares the struct as the Boost test fixture.
static const std::vector< ALTIUM_RULE_TOKENIZER_INPUT_OUTPUT > altium_rule_tokens_property
A list of valid test strings and the expected results.
BOOST_CHECK(box.ClosestPointTo(VECTOR2D(0, 0))==VECTOR2D(1, 2))
Test suite for KiCad math code.
VECTOR3I expected(15, 30, 45)
#define BOOST_TEST_CONTEXT(A)