diff --git a/shard.yml b/shard.yml index 2a1198f..94e085c 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: private-parlor-xt -version: 1.2.0 +version: 1.2.1 authors: - Charybdis diff --git a/spec/format/format_spec.cr b/spec/format/format_spec.cr index ed04ff7..2982714 100644 --- a/spec/format/format_spec.cr +++ b/spec/format/format_spec.cr @@ -187,7 +187,7 @@ module PrivateParlorXT chat: Tourmaline::Chat.new(tourmaline_user.id, "private"), from: tourmaline_user, caption: "Preformatted Text ~~Admin", - entities: [ + caption_entities: [ Tourmaline::MessageEntity.new( type: "bold", offset: 0, @@ -251,13 +251,14 @@ module PrivateParlorXT tourmaline_user = Tourmaline::User.new(80300, false, "beispiel") + # Test that captions of captioned types are properly formatted message = Tourmaline::Message.new( message_id: 11, date: Time.utc, chat: Tourmaline::Chat.new(tourmaline_user.id, "private"), from: tourmaline_user, caption: "Text with entities and backlinks >>>/foo/", - entities: [ + caption_entities: [ Tourmaline::MessageEntity.new( type: "bold", offset: 0, @@ -292,6 +293,42 @@ module PrivateParlorXT entities[0].type.should(eq("underline")) entities[1].type.should(eq("text_link")) entities[1].length.should(eq(8)) # >>>/foo/ + + # Test that text messages are properly formatted + message = Tourmaline::Message.new( + message_id: 11, + date: Time.utc, + chat: Tourmaline::Chat.new(tourmaline_user.id, "private"), + from: tourmaline_user, + text: "Text with entities and backlinks >>>/foo/", + entities: [ + Tourmaline::MessageEntity.new( + type: "bold", + offset: 0, + length: 4, + ), + Tourmaline::MessageEntity.new( + type: "underline", + offset: 4, + length: 13, + ), + Tourmaline::MessageEntity.new( + type: "text_link", + offset: 0, + length: 25, + url: "www.google.com" + ), + ], + ) + + text, entities = Format.text_and_entities(message, user, format_services) + + text.should(eq(expected)) + entities.size.should(eq(2)) + + entities[0].type.should(eq("underline")) + entities[1].type.should(eq("text_link")) + entities[1].length.should(eq(8)) # >>>/foo/ end it "returns formatted text and updated entities with pseudonym" do @@ -308,13 +345,14 @@ module PrivateParlorXT tourmaline_user = Tourmaline::User.new(60200, false, "beispiel") + # Test that captions of captioned types are properly formatted message = Tourmaline::Message.new( message_id: 11, date: Time.utc, chat: Tourmaline::Chat.new(tourmaline_user.id, "private"), from: tourmaline_user, - text: "Text with entities and backlinks >>>/foo/", - entities: [ + caption: "Text with entities and backlinks >>>/foo/", + caption_entities: [ Tourmaline::MessageEntity.new( type: "bold", offset: 0, @@ -352,6 +390,44 @@ module PrivateParlorXT entities[2].type.should(eq("underline")) entities[3].type.should(eq("text_link")) entities[3].length.should(eq(8)) # >>>/foo/ + + # Test that text messages are properly formatted + message = Tourmaline::Message.new( + message_id: 11, + date: Time.utc, + chat: Tourmaline::Chat.new(tourmaline_user.id, "private"), + from: tourmaline_user, + text: "Text with entities and backlinks >>>/foo/", + entities: [ + Tourmaline::MessageEntity.new( + type: "bold", + offset: 0, + length: 4, + ), + Tourmaline::MessageEntity.new( + type: "underline", + offset: 4, + length: 13, + ), + Tourmaline::MessageEntity.new( + type: "text_link", + offset: 0, + length: 25, + url: "www.google.com" + ), + ], + ) + + text, entities = Format.text_and_entities(message, user, format_services) + + text.should(eq(expected)) + entities.size.should(eq(4)) + + entities[0].type.should(eq("bold")) + entities[1].type.should(eq("code")) + entities[2].type.should(eq("underline")) + entities[3].type.should(eq("text_link")) + entities[3].length.should(eq(8)) # >>>/foo/ end end @@ -401,7 +477,7 @@ module PrivateParlorXT chat: Tourmaline::Chat.new(tourmaline_user.id, "private"), from: tourmaline_user, caption: "Text with entities and backlinks >>>/foo/", - entities: [ + caption_entities: [ Tourmaline::MessageEntity.new( type: "bold", offset: 0, @@ -464,7 +540,7 @@ module PrivateParlorXT chat: Tourmaline::Chat.new(bot_user.id, "private"), from: bot_user, caption: message_text, - entities: message_entities, + caption_entities: message_entities, ) user = MockUser.new(9000) @@ -512,7 +588,7 @@ module PrivateParlorXT chat: Tourmaline::Chat.new(bot_user.id, "private"), from: bot_user, caption: message_text, - entities: message_entities, + caption_entities: message_entities, ) message.preformatted = true @@ -562,7 +638,7 @@ module PrivateParlorXT chat: Tourmaline::Chat.new(bot_user.id, "private"), from: bot_user, caption: message_text, - entities: message_entities, + caption_entities: message_entities, ) user = MockUser.new(9000) @@ -610,7 +686,7 @@ module PrivateParlorXT chat: Tourmaline::Chat.new(bot_user.id, "private"), from: bot_user, caption: message_text, - entities: message_entities, + caption_entities: message_entities, ) user = MockUser.new(9000, tripcode: "User#SecurePassword") @@ -667,7 +743,7 @@ module PrivateParlorXT chat: Tourmaline::Chat.new(bot_user.id, "private"), from: bot_user, caption: message_text, - entities: message_entities, + caption_entities: message_entities, ) user = MockUser.new(9000, tripcode: "🦤🦆🕊️#DoDuDo") diff --git a/src/private-parlor-xt/format.cr b/src/private-parlor-xt/format.cr index 218a9a2..8f32855 100644 --- a/src/private-parlor-xt/format.cr +++ b/src/private-parlor-xt/format.cr @@ -74,7 +74,7 @@ module PrivateParlorXT return nil, [] of Tourmaline::MessageEntity end - text, entities = format_text(text, message.entities, message.preformatted?, services) + text, entities = format_text(text, entities, message.preformatted?, services) text, entities = prepend_pseudonym(text, entities, user, message, services)