diff options
author | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2022-03-12 04:27:15 +0300 |
---|---|---|
committer | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2022-03-12 04:27:15 +0300 |
commit | c6556eb6b86d4267bb35b7a27c34a0046668e3b9 (patch) | |
tree | dce73e18ffa5c46c03f877d8700f72bf1551cfdf /telegram/formatter/formatter_test.go | |
parent | ae8152ad87b32c827fa681285717b7b6ae3176fd (diff) |
Clasp directives to the following span as required by XEP-0393
Diffstat (limited to 'telegram/formatter/formatter_test.go')
-rw-r--r-- | telegram/formatter/formatter_test.go | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/telegram/formatter/formatter_test.go b/telegram/formatter/formatter_test.go index c988b10..e4bdd23 100644 --- a/telegram/formatter/formatter_test.go +++ b/telegram/formatter/formatter_test.go @@ -392,3 +392,83 @@ func TestFormattingXEP0393Strikethrough(t *testing.T) { t.Errorf("Wrong strikethrough formatting: %v", markup) } } + +func TestClaspLeft(t *testing.T) { + text := "a b c" + entities := []*client.TextEntity{ + &client.TextEntity{ + Offset: 1, + Length: 2, + }, + } + entities = ClaspDirectives(text, entities) + if !(len(entities) == 1 && + entities[0].Offset == 2 && entities[0].Length == 1) { + t.Errorf("Wrong claspleft: %#v", entities) + } +} + +func TestClaspBoth(t *testing.T) { + text := "a b c" + entities := []*client.TextEntity{ + &client.TextEntity{ + Offset: 1, + Length: 3, + }, + } + entities = ClaspDirectives(text, entities) + if !(len(entities) == 1 && + entities[0].Offset == 2 && entities[0].Length == 1) { + t.Errorf("Wrong claspboth: %#v", entities) + } +} + +func TestClaspNotNeeded(t *testing.T) { + text := " abc " + entities := []*client.TextEntity{ + &client.TextEntity{ + Offset: 1, + Length: 3, + }, + } + entities = ClaspDirectives(text, entities) + if !(len(entities) == 1 && + entities[0].Offset == 1 && entities[0].Length == 3) { + t.Errorf("Wrong claspnotneeded: %#v", entities) + } +} + +func TestClaspNested(t *testing.T) { + text := "a b c" + entities := []*client.TextEntity{ + &client.TextEntity{ + Offset: 1, + Length: 3, + }, + &client.TextEntity{ + Offset: 2, + Length: 2, + }, + } + entities = ClaspDirectives(text, entities) + if !(len(entities) == 2 && + entities[0].Offset == 2 && entities[0].Length == 1 && + entities[1].Offset == 2 && entities[1].Length == 1) { + t.Errorf("Wrong claspnested: %#v", entities) + } +} + +func TestClaspEmoji(t *testing.T) { + text := "a 🐖 c" + entities := []*client.TextEntity{ + &client.TextEntity{ + Offset: 1, + Length: 4, + }, + } + entities = ClaspDirectives(text, entities) + if !(len(entities) == 1 && + entities[0].Offset == 2 && entities[0].Length == 2) { + t.Errorf("Wrong claspemoji: %#v", entities) + } +} |