24#include <boost/test/unit_test.hpp>
41 const std::string
json =
42 R
"({"/abc": "take_ours", "/def": "take_theirs", "/ghi": "take_ancestor"})";
135 R
"({"/abc": "take_ours", "/def": "not_a_kind"})" );
140 R
"({"/abc": "take_ours", "/def": "keep"})" );
145 R
"({"/abc": "take_ours", "/def": 42})" );
157 BOOST_CHECK( r.resolutions.count( wxString::FromUTF8(
"/élément" ) ) == 1 );
173MERGE_PLAN MakePlanWithConflicts(
const std::vector<KIID_PATH>& aConflictIds )
177 for(
const KIID_PATH&
id : aConflictIds )
182 plan.actions.push_back( r );
183 plan.unresolved.push_back(
id );
199 std::vector<std::size_t> conflictIdx = { 0, 1 };
200 std::map<wxString, ITEM_RES> autoMap = {
225 std::vector<std::size_t> conflictIdx = { 0, 1 };
226 std::map<wxString, ITEM_RES> autoMap = {
245 std::vector<std::size_t> conflictIdx;
246 std::map<wxString, ITEM_RES> autoMap;
267 plan.actions.push_back( a );
268 plan.actions.push_back( b );
269 plan.unresolved.push_back( idB );
271 std::vector<std::size_t> conflictIdx = { 0, 1 };
297 plan.actions.push_back( a );
298 plan.actions.push_back( b );
299 plan.actions.push_back( c );
300 plan.unresolved.push_back( idB );
301 plan.unresolved.push_back( idC );
319 const wxString longSegmentString = wxS(
"/" ) + a.
AsString() + wxS(
"/" )
322 const KIID_PATH longPath( longSegmentString );
328 plan.actions.push_back( r );
329 plan.unresolved.push_back( longPath );
334 BOOST_CHECK( entries[0].label.StartsWith( wxS(
"…" ) ) );
342 const KIID_PATH shortPath = MakePath( 2200 );
348 plan.actions.push_back( r );
349 plan.unresolved.push_back( shortPath );
377 plan.actions.push_back( a );
378 plan.actions.push_back( b );
397 plan.actions.push_back( a );
398 plan.actions.push_back( b );
410 plan.actions.push_back( a );
424 plan.actions.push_back( a );
440 plan.actions.push_back( a );
455 plan.actions.push_back( a );
475 std::vector<std::size_t> conflictIdx = { 0, 99 };
476 std::map<wxString, ITEM_RES> autoMap = {
500 std::vector<std::size_t> conflictIdx = { 99 };
501 std::map<wxString, ITEM_RES> autoMap = {
521 plan.actions.push_back( a );
522 plan.actions.push_back( b );
523 plan.actions.push_back( c );
549 std::map<KIID_PATH, BOX2I> primary = { { id, VALID_PRIMARY } };
550 std::map<KIID_PATH, BOX2I> ours = { { id, VALID_OURS } };
551 std::map<KIID_PATH, BOX2I> theirs = { { id, VALID_THEIRS } };
552 std::map<KIID_PATH, BOX2I> ancestor = { { id, VALID_ANCESTOR } };
566 std::map<KIID_PATH, BOX2I> ours = { { id, VALID_OURS } };
567 std::map<KIID_PATH, BOX2I> theirs = { { id, VALID_THEIRS } };
568 std::map<KIID_PATH, BOX2I> ancestor = { { id, VALID_ANCESTOR } };
570 auto bbox =
ResolveConflictBBox(
id, std::map<KIID_PATH, BOX2I>{}, ours, theirs, ancestor );
580 std::map<KIID_PATH, BOX2I> primary;
581 std::map<KIID_PATH, BOX2I> ours;
582 std::map<KIID_PATH, BOX2I> theirs = { { id, VALID_THEIRS } };
583 std::map<KIID_PATH, BOX2I> ancestor = { { id, VALID_ANCESTOR } };
595 std::map<KIID_PATH, BOX2I> primary;
596 std::map<KIID_PATH, BOX2I> ours;
597 std::map<KIID_PATH, BOX2I> theirs;
598 std::map<KIID_PATH, BOX2I> ancestor = { { id, VALID_ANCESTOR } };
612 std::map<KIID_PATH, BOX2I> primary = { { id,
DEGENERATE } };
613 std::map<KIID_PATH, BOX2I> ours = { { id, VALID_OURS } };
614 std::map<KIID_PATH, BOX2I> theirs;
615 std::map<KIID_PATH, BOX2I> ancestor;
626 std::map<KIID_PATH, BOX2I>
empty;
641 std::map<KIID_PATH, BOX2I> ours = { { id,
DEGENERATE } };
642 std::map<KIID_PATH, BOX2I> theirs = { { id, VALID_THEIRS } };
643 std::map<KIID_PATH, BOX2I> ancestor = { { id, VALID_ANCESTOR } };
645 auto bbox =
ResolveConflictBBox(
id, std::map<KIID_PATH, BOX2I>{}, ours, theirs, ancestor );
656 r.
id = MakePath( 4100 );
677 r.
id = MakePath( 4101 );
705 const wxString expectedCountLine =
706 wxString::Format( wxPLURAL(
"%zu property edit in this resolution.\n",
707 "%zu property edits in this resolution.\n", 0 ),
708 static_cast<std::size_t
>( 0 ) );
713 r.
id = MakePath( 4200 );
717 BOOST_CHECK_MESSAGE(
text.Length() > 30,
718 "Detail text too short for kind "
719 <<
static_cast<int>( kind ) );
737 plan.actions.push_back( action );
738 plan.unresolved.push_back(
id );
749 return std::set<wxString>{ wxS(
"Pin 1" ) };
wxString AsString() const
static void SeedGenerator(unsigned int aSeed)
Re-initialize the UUID generator with a given seed (for testing or QA purposes)
wxString AsString() const
static bool empty(const wxTextEntryBase *aCtrl)
static std::vector< PENDING_PROPERTY > plan(const EDA_ITEM &aSource, const EDA_ITEM &aTarget, const std::set< wxString > &aEnabledKeys)
Target properties to write, paired with values read off the source.
wxString BuildConflictDetailText(const ITEM_RESOLUTION &aResolution)
Build the human-readable detail text shown in the merge dialog's resolution panel for a given ITEM_RE...
void SettleLibraryMerges(MERGE_PLAN &aPlan, const std::function< bool(const KIID_PATH &)> &aCanCombine, const std::function< std::set< wxString >(const KIID_PATH &)> &aEditedNames)
Settle the MERGE_PROPS of a library merge, where an item is combined whole or not at all.
AUTO_RESOLUTION_PARSE_RESULT ParseAutoResolutionJson(const std::string &aJsonContent)
Parse a KICAD_MERGETOOL_AUTO-format JSON object mapping item IDs (KIID_PATH strings) to ITEM_RES spel...
@ BAD_VALUE
at least one entry's value wasn't a string
@ NOT_OBJECT
JSON parsed but the root was not an object.
@ INVALID_JSON
input could not be parsed as JSON
@ UNKNOWN_KIND
at least one entry's string wasn't a known ITEM_RES
@ OK
parsed cleanly; resolutions is populated
@ ENGINE_INTERNAL_KIND
at least one entry asked for an engine-internal kind (KEEP / DELETE / MERGE_PROPS); only the TAKE_* f...
ITEM_RES
Resolution kind for a whole item.
std::vector< CONFLICT_LIST_ENTRY > BuildConflictList(const MERGE_PLAN &aPlan)
std::optional< BOX2I > ResolveConflictBBox(const KIID_PATH &aId, const std::map< KIID_PATH, BOX2I > &aPrimary, const std::map< KIID_PATH, BOX2I > &aOurs, const std::map< KIID_PATH, BOX2I > &aTheirs, const std::map< KIID_PATH, BOX2I > &aAncestor)
Resolve the best bounding box for a conflicted item across the three sides of a 3-way merge.
KIID_PATH LibraryItemKiidPath(const wxString &aName)
Build a deterministic synthetic KIID_PATH from a library item name (symbol name or footprint name).
APPLY_AUTO_RESOLUTIONS_RESULT ApplyAutoResolutions(MERGE_PLAN &aPlan, const std::vector< std::size_t > &aConflictActionIndices, const std::map< wxString, ITEM_RES > &aResolutions)
Apply a parsed auto-resolution map to a MERGE_PLAN's conflicts.
std::vector< KIID_PATH > CollectUnresolvedConflicts(const MERGE_PLAN &aPlan, const std::vector< std::size_t > &aConflictActionIndices)
Return the conflict actions that still have no decision.
_OUT_STRING AsString(const std::string &aString)
std::vector< PROPERTY_RESOLUTION > props
Result of planning a 3-way merge.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_CASE(Parse_ValidObject)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_SUITE_END()
wxString result
Test unit parsing edge cases and error handling.
VECTOR2< int32_t > VECTOR2I