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👙_🐧_🐖 " { + 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) + } +}