Skip to content

Commit

Permalink
Fix bug in text formatting for captioned types; update tests; bump ve…
Browse files Browse the repository at this point in the history
…rsion
  • Loading branch information
Charibdys committed May 25, 2024
1 parent ac56aa8 commit e4d4892
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 12 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: private-parlor-xt
version: 1.2.0
version: 1.2.1

authors:
- Charybdis
Expand Down
96 changes: 86 additions & 10 deletions spec/format/format_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion src/private-parlor-xt/format.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit e4d4892

Please sign in to comment.