@@ -251,48 +251,32 @@ static void CheckText(std::u8string const &e, std::u8string const &a, bool unquo
251251 }
252252}
253253
254- static void CheckTextComponent (shared_ptr<Tag> const &e, shared_ptr<Tag> const &a) {
255- static auto getText = [](shared_ptr<Tag> const &tag) -> optional<u8string> {
256- if (auto text = tag->asString (); text) {
257- auto json = props::ParseAsJson (text->fValue );
258- if (json) {
259- if (auto found = json->find (" text" ); found != json->end () && found->is_string ()) {
260- auto str = found->get <string>();
261- return std::u8string ((char8_t const *)str.c_str (), str.size ());
262- } else {
263- return std::nullopt ;
264- }
265- } else {
266- return text->fValue ;
254+ static optional<u8string> GetTextComponentJ (Tag const *tag) {
255+ if (!tag) {
256+ return nullopt ;
257+ }
258+ if (auto str = tag->asString (); str) {
259+ if (auto j = props::ParseAsJson (str->fValue ); j) {
260+ if (auto text = j->find (" text" ); text != j->end () && text->is_string ()) {
261+ auto s = text->get <string>();
262+ u8string s8;
263+ s8.assign ((char8_t const *)s.c_str (), s.size ());
264+ return s8;
267265 }
268- } else if (auto compound = tag->asCompound (); compound) {
269- return compound->string (u8" text" );
270- } else {
271- return nullopt ;
272- }
273- };
274- auto textE = getText (e);
275- auto textA = getText (a);
276- CHECK (textE == textA);
277- }
278-
279- static void CheckItemName (CompoundTag const &expected, CompoundTag const &actual, u8string const &key) {
280- if (auto e = expected.query (key)->asString (); e) {
281- auto a = actual.query (key)->asString ();
282- CHECK ((bool )a);
283- if (!a) {
284- return ;
285266 }
286- bool unquote = key != u8" CustomName" ;
287- CheckText (e->fValue , e->fValue , unquote);
288- } else if (auto e = expected.query (key)->asCompound (); e) {
289- auto a = actual.query (key)->asCompound ();
290- CHECK ((bool )a);
291- if (!a) {
292- return ;
267+ return strings::Unquote (str->fValue );
268+ } else if (auto c = tag->asCompound (); c) {
269+ if (auto text = c->string (u8" text" ); text) {
270+ return *text;
293271 }
294- DiffCompoundTag (*e, *a);
295272 }
273+ return nullopt ;
274+ };
275+
276+ static void CheckItemNameJ (CompoundTag const &expected, CompoundTag const &actual, u8string const &key) {
277+ auto textE = GetTextComponentJ (expected.query (key));
278+ auto textA = GetTextComponentJ (actual.query (key));
279+ CHECK (textE == textA);
296280}
297281
298282static void RemoveEmpty (CompoundTag &t) {
@@ -372,7 +356,7 @@ static void CheckItemJ(CompoundTag const &itemE, CompoundTag const &itemA) {
372356 static set<u8string> const sJsonKeys = {u8" components/minecraft:custom_name" , u8" components/minecraft:item_name" };
373357 for (u8string const &key : sJsonKeys ) {
374358 blacklist.insert (key);
375- CheckItemName (itemE, itemA, key);
359+ CheckItemNameJ (itemE, itemA, key);
376360 }
377361
378362 auto itemsE = itemE.query (u8" components/minecraft:container" )->asList ();
@@ -434,9 +418,9 @@ static void CheckSignTextLinesJ(CompoundTag const &e, CompoundTag const &a) {
434418 CHECK (messagesA);
435419 CHECK (messagesE->size () == messagesA->size ());
436420 for (size_t i = 0 ; i < messagesE->size (); i++) {
437- auto lineE = messagesE->at (i);
438- auto lineA = messagesA->at (i);
439- CheckTextComponent (lineE, lineA);
421+ auto lineE = GetTextComponentJ ( messagesE->at (i). get () );
422+ auto lineA = GetTextComponentJ ( messagesA->at (i). get () );
423+ CHECK (lineE == lineA);
440424 }
441425 }
442426 auto copyE = e.copy ();
@@ -521,7 +505,7 @@ static void CheckTileEntityJ(CompoundTag const &expected, CompoundTag const &act
521505 static set<u8string> const sJsonKeys = {u8" components/minecraft:custom_name" , u8" components/minecraft:item_name" , u8" CustomName" };
522506 for (u8string const &key : sJsonKeys ) {
523507 tagBlacklist.insert (key);
524- CheckItemName (expected, actual, key);
508+ CheckItemNameJ (expected, actual, key);
525509 }
526510 for (auto const &key : {u8" back_text" , u8" front_text" }) {
527511 auto backTextE = expected.compoundTag (key);
@@ -902,7 +886,7 @@ static void CheckEntityJ(std::u8string const &id, CompoundTag const &entityE, Co
902886 blacklist.insert (u8" TreasurePosZ" );
903887 }
904888
905- CheckItemName (entityE, entityA, u8" CustomName" );
889+ CheckItemNameJ (entityE, entityA, u8" CustomName" );
906890 blacklist.insert (u8" CustomName" );
907891
908892 CheckUuidJ (entityE, entityA, u8" last_hurt_by_mob" );
0 commit comments