aboutsummaryrefslogtreecommitdiff
path: root/telegram
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2022-03-10 19:25:45 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2022-03-10 19:25:45 +0300
commit7ddc3c448278191f19d616cf3b730bdbe8dc63cd (patch)
tree5584382d8d75d2522e34f9fd43c0f69b10466707 /telegram
parent404e4f8d3ebfc43407aa40c827be4f78b06ab568 (diff)
Tests for XEP-0393 formatter
Diffstat (limited to 'telegram')
-rw-r--r--telegram/formatter/formatter_test.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/telegram/formatter/formatter_test.go b/telegram/formatter/formatter_test.go
index 63337d6..8453851 100644
--- a/telegram/formatter/formatter_test.go
+++ b/telegram/formatter/formatter_test.go
@@ -206,3 +206,66 @@ func TestSortEmpty(t *testing.T) {
t.Errorf("Empty entities set sorting error: %#v", entities)
}
}
+
+func TestNoFormattingXEP0393(t *testing.T) {
+ markup := Format("abc\ndef", []*client.TextEntity{}, EntityToXEP0393)
+ if markup != "abc\ndef" {
+ t.Errorf("No formatting expected, but: %v", markup)
+ }
+}
+
+func TestFormattingXEP0393Simple(t *testing.T) {
+ markup := Format("👙🐧🐖", []*client.TextEntity{
+ &client.TextEntity{
+ Offset: 2,
+ Length: 4,
+ Type: &client.TextEntityTypeBold{},
+ },
+ }, EntityToXEP0393)
+ if markup != "👙*🐧🐖*" {
+ t.Errorf("Wrong simple formatting: %v", markup)
+ }
+}
+
+func TestFormattingXEP0393Adjacent(t *testing.T) {
+ markup := Format("a👙🐧🐖", []*client.TextEntity{
+ &client.TextEntity{
+ Offset: 3,
+ Length: 2,
+ Type: &client.TextEntityTypeItalic{},
+ },
+ &client.TextEntity{
+ Offset: 5,
+ Length: 2,
+ Type: &client.TextEntityTypeTextUrl{
+ Url: "https://narayana.im/",
+ },
+ },
+ }, EntityToXEP0393)
+ if markup != "a👙_🐧_🐖 <https://narayana.im/>" {
+ t.Errorf("Wrong adjacent formatting: %v", markup)
+ }
+}
+
+func TestFormattingXEP0393AdjacentAndNested(t *testing.T) {
+ markup := Format("👙🐧🐖", []*client.TextEntity{
+ &client.TextEntity{
+ Offset: 0,
+ Length: 4,
+ Type: &client.TextEntityTypePre{},
+ },
+ &client.TextEntity{
+ Offset: 0,
+ Length: 2,
+ Type: &client.TextEntityTypeBold{},
+ },
+ &client.TextEntity{
+ Offset: 4,
+ Length: 2,
+ Type: &client.TextEntityTypeItalic{},
+ },
+ }, EntityToXEP0393)
+ if markup != "\n```\n*👙*🐧\n```\n_🐖_" {
+ t.Errorf("Wrong adjacent&nested formatting: %v", markup)
+ }
+}