29#include <pegtl/contrib/analyze.hpp>
42 BOOST_REQUIRE( tao::pegtl::analyze< LIBRARY_TABLE_GRAMMAR::LIB_TABLE_FILE >( 1 ) == 0 );
49 tl::expected<LIBRARY_TABLE_IR, LIBRARY_PARSE_ERROR>
result = parser.
ParseBuffer(
"" );
56 std::vector<std::string> cases = {
62 p.append(
"libraries/" );
66 for(
const std::string&
path : cases )
83 wxString expected_error;
85 bool check_formatted =
true;
88 std::vector<TESTCASE> cases = {
89 { .filename =
"sym-lib-table", .expected_rows = 224 },
90 { .filename =
"fp-lib-table", .expected_rows = 146 },
91 { .filename =
"nested-symbols", .expected_rows = 6 },
92 { .filename =
"nested-disabled", .expected_rows = 4 },
93 { .filename =
"nested-hidden", .expected_rows = 4 },
94 { .filename =
"cycle", .expected_rows = 2 },
95 { .filename =
"sym-hand-edited", .expected_rows = 2, .check_formatted =
false },
96 { .filename =
"corrupted", .expected_error =
"Syntax error at line 6, column 9" },
97 { .filename =
"truncated", .expected_error =
"Syntax error at line 11, column 1" }
101 fn.AppendDir(
"libraries" );
103 for(
const auto& [filename, expected_error, expected_rows, check_formatted] : cases )
107 fn.SetName( filename );
112 BOOST_REQUIRE_MESSAGE(
table.Rows().size() == expected_rows,
113 wxString::Format(
"Expected %zu rows but got %zu",
114 expected_rows,
table.Rows().size() ) );
116 BOOST_REQUIRE_MESSAGE(
table.ErrorDescription() == expected_error,
117 wxString::Format(
"Expected error '%s' but got '%s'",
118 expected_error,
table.ErrorDescription() ) );
121 if( !
table.IsOk() || !check_formatted )
125 inFp.open( fn.GetFullPath().fn_str() );
128 std::stringstream inBuf;
129 inBuf << inFp.rdbuf();
130 std::string inData = inBuf.str();
133 table.Format( &formatter );
135 KICAD_FORMAT::FORMAT_MODE::LIBRARY_TABLE );
137 if( formatter.
GetString().compare( inData ) != 0 )
168 fn.AppendDir(
"libraries" );
171 fn.SetName(
"nested-disabled" );
174 BOOST_REQUIRE_MESSAGE( disabledTable.
Rows().size() == 4,
175 wxString::Format(
"Expected 4 rows but got %zu",
176 disabledTable.
Rows().size() ) );
179 bool foundDisabledRow =
false;
185 BOOST_REQUIRE_MESSAGE( row.Disabled(),
186 "Nested table row should have disabled flag set" );
187 foundDisabledRow =
true;
191 BOOST_REQUIRE_MESSAGE( foundDisabledRow,
192 "Disabled nested table row not found in parsed table" );
195 fn.SetName(
"nested-hidden" );
198 BOOST_REQUIRE_MESSAGE( hiddenTable.
Rows().size() == 4,
199 wxString::Format(
"Expected 4 rows but got %zu",
200 hiddenTable.
Rows().size() ) );
202 bool foundHiddenRow =
false;
208 BOOST_REQUIRE_MESSAGE( row.Hidden(),
209 "Nested table row should have hidden flag set" );
210 foundHiddenRow =
true;
214 BOOST_REQUIRE_MESSAGE( foundHiddenRow,
215 "Hidden nested table row not found in parsed table" );
std::vector< LIBRARY_TABLE_ROW * > Rows(LIBRARY_TABLE_TYPE aType, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH, bool aIncludeInvalid=false) const
Returns a flattened list of libraries of the given type.
void LoadGlobalTables(std::initializer_list< LIBRARY_TABLE_TYPE > aTablesToLoad={})
(Re)loads the global library tables in the given list, or all tables if no list is given
tl::expected< LIBRARY_TABLE_IR, LIBRARY_PARSE_ERROR > ParseBuffer(const std::string &aBuffer)
tl::expected< LIBRARY_TABLE_IR, LIBRARY_PARSE_ERROR > Parse(const std::filesystem::path &aPath)
static const wxString TABLE_TYPE_NAME
const std::vector< LIBRARY_TABLE_ROW > & Rows() const
std::string GetTestDataRootDir()
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(Grammar)
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
wxString result
Test unit parsing edge cases and error handling.