Fix fix_formatted_text test.
This commit is contained in:
parent
73f945bd8b
commit
31a4608463
@ -6,6 +6,8 @@
|
||||
//
|
||||
#include "td/telegram/MessageEntity.h"
|
||||
|
||||
#include "td/telegram/UserId.h"
|
||||
|
||||
#include "td/utils/algorithm.h"
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/format.h"
|
||||
@ -832,6 +834,7 @@ TEST(MessageEntities, fix_formatted_text) {
|
||||
}
|
||||
|
||||
str = "aba \r\n caba ";
|
||||
td::UserId user_id(static_cast<td::int64>(1));
|
||||
for (td::int32 length = 1; length <= 3; length++) {
|
||||
for (td::int32 offset = 0; static_cast<size_t>(offset + length) <= str.size(); offset++) {
|
||||
for (auto type : {td::MessageEntity::Type::Bold, td::MessageEntity::Type::Url, td::MessageEntity::Type::TextUrl,
|
||||
@ -855,12 +858,22 @@ TEST(MessageEntities, fix_formatted_text) {
|
||||
|
||||
td::vector<td::MessageEntity> entities;
|
||||
entities.emplace_back(type, offset, length);
|
||||
if (type == td::MessageEntity::Type::TextUrl) {
|
||||
entities.back().argument = "t.me";
|
||||
} else if (type == td::MessageEntity::Type::MentionName) {
|
||||
entities.back().user_id = user_id;
|
||||
}
|
||||
td::vector<td::MessageEntity> fixed_entities;
|
||||
if (fixed_length > 0) {
|
||||
for (auto i = 0; i < length; i++) {
|
||||
if (!td::is_space(str[offset + i]) || type == td::MessageEntity::Type::TextUrl ||
|
||||
type == td::MessageEntity::Type::MentionName) {
|
||||
fixed_entities.emplace_back(type, fixed_offset, fixed_length);
|
||||
if (type == td::MessageEntity::Type::TextUrl) {
|
||||
fixed_entities.back().argument = "t.me";
|
||||
} else if (type == td::MessageEntity::Type::MentionName) {
|
||||
fixed_entities.back().user_id = user_id;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -905,9 +918,11 @@ TEST(MessageEntities, fix_formatted_text) {
|
||||
for (td::int32 offset2 = 0; offset2 <= 8 - length2; offset2++) {
|
||||
if (offset != offset2) {
|
||||
td::vector<td::MessageEntity> entities;
|
||||
entities.emplace_back(td::MessageEntity::Type::TextUrl, offset, length);
|
||||
entities.emplace_back(td::MessageEntity::Type::TextUrl, offset2, length2);
|
||||
entities.emplace_back(td::MessageEntity::Type::TextUrl, offset, length, "t.me");
|
||||
entities.emplace_back(td::MessageEntity::Type::TextUrl, offset2, length2, "t.me");
|
||||
entities.emplace_back(td::MessageEntity::Type::TextUrl, offset2 + length2, 1);
|
||||
td::vector<td::MessageEntity> fixed_entities = entities;
|
||||
fixed_entities.pop_back();
|
||||
std::sort(fixed_entities.begin(), fixed_entities.end());
|
||||
if (fixed_entities[0].offset + fixed_entities[0].length > fixed_entities[1].offset) {
|
||||
fixed_entities.pop_back();
|
||||
|
Loading…
Reference in New Issue
Block a user