Tests for XEP-0393 formatter

This commit is contained in:
Bohdan Horbeshko 2022-03-10 11:25:45 -05:00
parent 404e4f8d3e
commit 7ddc3c4482

View file

@ -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)
}
}