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 The 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, see <https://www.gnu.org/licenses/>.
18 */
19
24
26
28
33
34
38BOOST_FIXTURE_TEST_SUITE( AltiumRuleTransformer, ALTIUM_RULE_TRANSFORMER_FIXTURE )
39
40
41BOOST_AUTO_TEST_CASE( AltiumRuleTokenizerEmptyInput )
42{
43 ALTIUM_RULE_TOKENIZER tokenizer( "" );
44
45 const ALTIUM_RULE_TOKEN& peek = tokenizer.Peek();
46 BOOST_CHECK( ( ALTIUM_RULE_TOKEN_KIND::END_OF_EXPR == peek.kind ) );
47 BOOST_CHECK_EQUAL( 0, peek.pos );
48
49 const ALTIUM_RULE_TOKEN& next = tokenizer.Next();
50 BOOST_CHECK( ( ALTIUM_RULE_TOKEN_KIND::END_OF_EXPR == next.kind ) );
51 BOOST_CHECK_EQUAL( 0, next.pos );
52
53 const ALTIUM_RULE_TOKEN& peek2 = tokenizer.Peek();
54 BOOST_CHECK( ( ALTIUM_RULE_TOKEN_KIND::END_OF_EXPR == peek2.kind ) );
55 BOOST_CHECK_EQUAL( 0, peek2.pos );
56}
57
58BOOST_AUTO_TEST_CASE( AltiumRuleTokenizerOnlySpaces )
59{
60 ALTIUM_RULE_TOKENIZER tokenizer( " " );
61
62 const ALTIUM_RULE_TOKEN& peek = tokenizer.Peek();
63 BOOST_CHECK( ( ALTIUM_RULE_TOKEN_KIND::END_OF_EXPR == peek.kind ) );
64 BOOST_CHECK_EQUAL( 3, peek.pos );
65
66 const ALTIUM_RULE_TOKEN& next = tokenizer.Next();
67 BOOST_CHECK( ( ALTIUM_RULE_TOKEN_KIND::END_OF_EXPR == next.kind ) );
68 BOOST_CHECK_EQUAL( 3, next.pos );
69
70 const ALTIUM_RULE_TOKEN& peek2 = tokenizer.Peek();
71 BOOST_CHECK( ( ALTIUM_RULE_TOKEN_KIND::END_OF_EXPR == peek2.kind ) );
72 BOOST_CHECK_EQUAL( 3, peek2.pos );
73}
74
75BOOST_AUTO_TEST_CASE( AltiumRuleTokenizerSingleCharIdentifier )
76{
77 ALTIUM_RULE_TOKENIZER tokenizer( "a" );
78
79 const ALTIUM_RULE_TOKEN& next = tokenizer.Next();
80 BOOST_CHECK( ( ALTIUM_RULE_TOKEN_KIND::IDENT == next.kind ) );
81 BOOST_CHECK_EQUAL( 0, next.pos );
82 BOOST_CHECK_EQUAL( "a", next.sValue );
83
84 const ALTIUM_RULE_TOKEN& peek = tokenizer.Peek();
85 BOOST_CHECK( ( ALTIUM_RULE_TOKEN_KIND::END_OF_EXPR == peek.kind ) );
86 BOOST_CHECK_EQUAL( 1, peek.pos );
87
88 const ALTIUM_RULE_TOKEN& next2 = tokenizer.Next();
89 BOOST_CHECK( ( ALTIUM_RULE_TOKEN_KIND::END_OF_EXPR == next2.kind ) );
90 BOOST_CHECK_EQUAL( 1, next2.pos );
91}
92
93
95{
96 wxString input;
97 std::vector<ALTIUM_RULE_TOKEN> exp_token;
98};
99
103static const std::vector<ALTIUM_RULE_TOKENIZER_INPUT_OUTPUT> altium_rule_tokens_property = {
104 // Empty string
105 { "",
106 {
109 }
110 },
111 // Single Token
112 { "All",
113 {
114 { ALTIUM_RULE_TOKEN_KIND::IDENT, 0, "All" },
116 }
117 },
118 { "1234",
119 {
122 }
123 },
124 { "+1234",
125 {
128 }
129 },
130 { "-1234",
131 {
134 }
135 },
136 { "'1234'",
137 {
140 }
141 },
142 { "True",
143 {
146 }
147 },
148 { "true",
149 {
152 }
153 },
154 { "False",
155 {
158 }
159 },
160 { "false",
161 {
164 }
165 },
166 { "+",
167 {
170 }
171 },
172 { "-",
173 {
176 }
177 },
178 { "*",
179 {
182 }
183 },
184 { "/",
185 {
188 }
189 },
190 { "Div",
191 {
194 }
195 },
196 { "div",
197 {
200 }
201 },
202 { "Mod",
203 {
206 }
207 },
208 { "mod",
209 {
212 }
213 },
214 { "And",
215 {
218 }
219 },
220 { "and",
221 {
224 }
225 },
226 { "&&",
227 {
230 }
231 },
232 { "Or",
233 {
236 }
237 },
238 { "or",
239 {
242 }
243 },
244 { "||",
245 {
248 }
249 },
250 { "Xor",
251 {
254 }
255 },
256 { "xor",
257 {
260 }
261 },
262 { "Not",
263 {
266 }
267 },
268 { "not",
269 {
272 }
273 },
274 { "<",
275 {
278 }
279 },
280 { "<=",
281 {
284 }
285 },
286 { ">",
287 {
290 }
291 },
292 { ">=",
293 {
296 }
297 },
298 { "<>",
299 {
302 }
303 },
304 { "=",
305 {
308 }
309 },
310 { "Between",
311 {
314 }
315 },
316 { "between",
317 {
320 }
321 },
322 { "Like",
323 {
326 }
327 },
328 { "like",
329 {
332 }
333 },
334 // Multiple tokens
335 { "ab cd ef",
336 {
341 }
342 },
343 // Complex tests
344 { "InComponent('LEDS1') or InComponent('LEDS2')",
345 {
346 { ALTIUM_RULE_TOKEN_KIND::IDENT, 0, "InComponent" },
351 { ALTIUM_RULE_TOKEN_KIND::IDENT, 24, "InComponent" },
356 }
357 }
358};
359
363BOOST_AUTO_TEST_CASE( AltiumRuleTokenizerParameterizedTest )
364{
365 for( const auto& c : altium_rule_tokens_property )
366 {
367 BOOST_TEST_CONTEXT( wxString::Format( wxT( "'%s'" ), c.input ) )
368 {
369 ALTIUM_RULE_TOKENIZER tokenizer( c.input );
370
371 for( const auto& expected : c.exp_token )
372 {
373 const ALTIUM_RULE_TOKEN& token = tokenizer.Next();
374 BOOST_CHECK( ( expected.kind == token.kind ) );
375 BOOST_CHECK_EQUAL( expected.pos, token.pos );
376 BOOST_CHECK_EQUAL( expected.iValue, token.iValue );
377 BOOST_CHECK_EQUAL( expected.fValue, token.fValue );
378 BOOST_CHECK_EQUAL( expected.sValue, token.sValue );
379 }
380 }
381 }
382}
383
const ALTIUM_RULE_TOKEN & Peek() const
const ALTIUM_RULE_TOKEN & Next()
CITER next(CITER it)
Definition ptree.cpp:120
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_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE_END()
VECTOR3I expected(15, 30, 45)
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_CHECK_EQUAL(result, "25.4")