KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_sexpr.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) 2019 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
31// Code under test
32#include <sexpr/sexpr.h>
33
34#include "sexpr_test_utils.h"
35
40
41
42BOOST_AUTO_TEST_CASE( BasicConstruction )
43{
44 SEXPR::SEXPR_INTEGER s_int{ 1 };
45 // not sure why cast is needed, but boost doesn't like it without
46 BOOST_CHECK_PREDICATE( KI_TEST::SexprIsIntegerWithValue, ( (SEXPR::SEXPR&) s_int )( 1 ) );
47
48 SEXPR::SEXPR_DOUBLE s_double{ 3.14 };
49 BOOST_CHECK_PREDICATE( KI_TEST::SexprIsDoubleWithValue, ( (SEXPR::SEXPR&) s_double )( 3.14 ) );
50
51 SEXPR::SEXPR_STRING s_string{ "string" };
52 BOOST_CHECK_PREDICATE(
53 KI_TEST::SexprIsStringWithValue, ( (SEXPR::SEXPR&) s_string )( "string" ) );
54
55 SEXPR::SEXPR_STRING s_symbol{ "symbol" };
56 BOOST_CHECK_PREDICATE(
57 KI_TEST::SexprIsStringWithValue, ( (SEXPR::SEXPR&) s_symbol )( "symbol" ) );
58}
59
61{
63 // not sure why cast is needed, but boost doesn't like it without
64 BOOST_CHECK_PREDICATE( KI_TEST::SexprConvertsToString, ( (SEXPR::SEXPR&) s )( "1" ) );
65}
66
67BOOST_AUTO_TEST_CASE( AsStringDouble )
68{
69 SEXPR::SEXPR_DOUBLE s{ 3.14 };
70 BOOST_CHECK_PREDICATE( KI_TEST::SexprConvertsToString, ( (SEXPR::SEXPR&) s )( "3.14" ) );
71}
72
73BOOST_AUTO_TEST_CASE( AsStringSymbol )
74{
75 SEXPR::SEXPR_SYMBOL s{ "symbol" };
76 BOOST_CHECK_PREDICATE( KI_TEST::SexprConvertsToString, ( (SEXPR::SEXPR&) s )( "symbol" ) );
77}
78
79BOOST_AUTO_TEST_CASE( AsStringString )
80{
81 SEXPR::SEXPR_STRING s{ "string" };
82
83 // strings get quotes
84 BOOST_CHECK_PREDICATE( KI_TEST::SexprConvertsToString, ( (SEXPR::SEXPR&) s )( "\"string\"" ) );
85}
86
87BOOST_AUTO_TEST_CASE( AsStringList )
88{
89 SEXPR::SEXPR_LIST s_list;
90
91 s_list.AddChild( new SEXPR::SEXPR_SYMBOL{ "symbol" } );
92
93 {
94 auto* s_SubList = new SEXPR::SEXPR_LIST();
95 *s_SubList << 2 << 42.42 << "substring";
96 s_list.AddChild( s_SubList );
97 }
98
99 s_list << 1 << 3.14 << "string";
100
101 BOOST_CHECK_PREDICATE( KI_TEST::SexprIsListOfLength, ( (SEXPR::SEXPR&) s_list )( 5 ) );
102
103 // REVIEW: should there be a space at the end of the "symbol"?
104 BOOST_CHECK_PREDICATE( KI_TEST::SexprConvertsToString,
105 ( (SEXPR::SEXPR&) s_list )( "(symbol \n"
106 " (2 42.42 \"substring\") 1 3.14 \"string\")" ) );
107}
108
void AddChild(SEXPR *aChild)
Definition: sexpr.cpp:58
bool SexprIsDoubleWithValue(const SEXPR::SEXPR &aSexpr, double aVal)
Test predicate: is the s-expression a double with the given value?
bool SexprIsListOfLength(const SEXPR::SEXPR &aSexpr, size_t aExpectedLength)
Test predicate: is the s-expression a list with the given length?
bool SexprIsIntegerWithValue(const SEXPR::SEXPR &aSexpr, std::int64_t aVal)
Test predicate: is the s-expression an integer with the given value?
bool SexprIsStringWithValue(const SEXPR::SEXPR &aSexpr, const std::string &aVal)
Test predicate: is the s-expression a string with the given value?
bool SexprConvertsToString(const SEXPR::SEXPR &aSexpr, const std::string &aExpStr)
Predicate to check an SEXPR object converts to the expected string.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(BasicConstruction)
Declare the test suite.
Definition: test_sexpr.cpp:42