Skip to content

Commit

Permalink
format: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Aug 9, 2024
1 parent bbe62ee commit 49b1f24
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions format/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ import (
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/format"
"maunium.net/go/mautrix/format/mdext"
"maunium.net/go/mautrix/id"
)

func TestRenderMarkdown_PlainText(t *testing.T) {
content := format.RenderMarkdown("hello world", true, true)
assert.Equal(t, event.MessageEventContent{MsgType: event.MsgText, Body: "hello world"}, content)
assert.Equal(t, event.MessageEventContent{MsgType: event.MsgText, Body: "hello world", Mentions: &event.Mentions{}}, content)
content = format.RenderMarkdown("hello world", true, false)
assert.Equal(t, event.MessageEventContent{MsgType: event.MsgText, Body: "hello world"}, content)
assert.Equal(t, event.MessageEventContent{MsgType: event.MsgText, Body: "hello world", Mentions: &event.Mentions{}}, content)
content = format.RenderMarkdown("hello world", false, true)
assert.Equal(t, event.MessageEventContent{MsgType: event.MsgText, Body: "hello world"}, content)
assert.Equal(t, event.MessageEventContent{MsgType: event.MsgText, Body: "hello world", Mentions: &event.Mentions{}}, content)
content = format.RenderMarkdown("<b>hello world</b>", false, false)
assert.Equal(t, event.MessageEventContent{MsgType: event.MsgText, Body: "<b>hello world</b>"}, content)
assert.Equal(t, event.MessageEventContent{MsgType: event.MsgText, Body: "<b>hello world</b>", Mentions: &event.Mentions{}}, content)
content = format.RenderMarkdown(`<a href="https://matrix.to/#/@user:example.com">mention</a>`, false, false)
assert.Equal(t, event.MessageEventContent{MsgType: event.MsgText, Body: "<a href=\"https://matrix.to/#/@user:example.com\">mention</a>", Mentions: &event.Mentions{}}, content)
}

func TestRenderMarkdown_EscapeHTML(t *testing.T) {
Expand All @@ -37,6 +40,7 @@ func TestRenderMarkdown_EscapeHTML(t *testing.T) {
Body: "<b>hello world</b>",
Format: event.FormatHTML,
FormattedBody: "&lt;b&gt;hello world&lt;/b&gt;",
Mentions: &event.Mentions{},
}, content)
}

Expand All @@ -47,6 +51,7 @@ func TestRenderMarkdown_HTML(t *testing.T) {
Body: "**hello world**",
Format: event.FormatHTML,
FormattedBody: "<b>hello world</b>",
Mentions: &event.Mentions{},
}, content)

content = format.RenderMarkdown("<b>hello world</b>", true, true)
Expand All @@ -55,6 +60,18 @@ func TestRenderMarkdown_HTML(t *testing.T) {
Body: "**hello world**",
Format: event.FormatHTML,
FormattedBody: "<b>hello world</b>",
Mentions: &event.Mentions{},
}, content)

content = format.RenderMarkdown(`[mention](https://matrix.to/#/@user:example.com)`, true, false)
assert.Equal(t, event.MessageEventContent{
MsgType: event.MsgText,
Body: "mention",
Format: event.FormatHTML,
FormattedBody: `<a href="https://matrix.to/#/@user:example.com">mention</a>`,
Mentions: &event.Mentions{
UserIDs: []id.UserID{"@user:example.com"},
},
}, content)
}

Expand Down

0 comments on commit 49b1f24

Please sign in to comment.