Refactored most of the string-string tests to reduce the amount of boilerplate.

This commit is contained in:
Azareal 2018-10-08 14:38:51 +10:00
parent f721780c0d
commit 4d75c543d2
2 changed files with 233 additions and 224 deletions

View File

@ -1017,31 +1017,31 @@ func TestWordFilters(t *testing.T) {
func TestSlugs(t *testing.T) { func TestSlugs(t *testing.T) {
var res string var res string
var msgList []MEPair var msgList = &MEPairList{nil}
common.Config.BuildSlugs = true // Flip this switch, otherwise all the tests will fail common.Config.BuildSlugs = true // Flip this switch, otherwise all the tests will fail
msgList = addMEPair(msgList, "Unknown", "unknown") msgList.Add("Unknown", "unknown")
msgList = addMEPair(msgList, "Unknown2", "unknown2") msgList.Add("Unknown2", "unknown2")
msgList = addMEPair(msgList, "Unknown ", "unknown") msgList.Add("Unknown ", "unknown")
msgList = addMEPair(msgList, "Unknown 2", "unknown-2") msgList.Add("Unknown 2", "unknown-2")
msgList = addMEPair(msgList, "Unknown 2", "unknown-2") msgList.Add("Unknown 2", "unknown-2")
msgList = addMEPair(msgList, "Admin Alice", "admin-alice") msgList.Add("Admin Alice", "admin-alice")
msgList = addMEPair(msgList, "Admin_Alice", "adminalice") msgList.Add("Admin_Alice", "adminalice")
msgList = addMEPair(msgList, "Admin_Alice-", "adminalice") msgList.Add("Admin_Alice-", "adminalice")
msgList = addMEPair(msgList, "-Admin_Alice-", "adminalice") msgList.Add("-Admin_Alice-", "adminalice")
msgList = addMEPair(msgList, "-Admin@Alice-", "adminalice") msgList.Add("-Admin@Alice-", "adminalice")
msgList = addMEPair(msgList, "-Admin😀Alice-", "adminalice") msgList.Add("-Admin😀Alice-", "adminalice")
msgList = addMEPair(msgList, "u", "u") msgList.Add("u", "u")
msgList = addMEPair(msgList, "", "untitled") msgList.Add("", "untitled")
msgList = addMEPair(msgList, " ", "untitled") msgList.Add(" ", "untitled")
msgList = addMEPair(msgList, "-", "untitled") msgList.Add("-", "untitled")
msgList = addMEPair(msgList, "--", "untitled") msgList.Add("--", "untitled")
msgList = addMEPair(msgList, "é", "é") msgList.Add("é", "é")
msgList = addMEPair(msgList, "-é-", "é") msgList.Add("-é-", "é")
msgList = addMEPair(msgList, "-你好-", "untitled") msgList.Add("-你好-", "untitled")
msgList = addMEPair(msgList, "-こにちは-", "untitled") msgList.Add("-こにちは-", "untitled")
for _, item := range msgList { for _, item := range msgList.Items {
t.Log("Testing string '" + item.Msg + "'") t.Log("Testing string '" + item.Msg + "'")
res = common.NameToSlug(item.Msg) res = common.NameToSlug(item.Msg)
if res != item.Expects { if res != item.Expects {
@ -1151,14 +1151,19 @@ type METri struct {
Expects string Expects string
} }
func addMETri(msgList []METri, args ...string) []METri { type METriList struct {
Items []METri
}
func (tlist *METriList) Add(args ...string) {
if len(args) < 2 { if len(args) < 2 {
panic("need 2 or more args") panic("need 2 or more args")
} }
if len(args) > 2 { if len(args) > 2 {
return append(msgList, METri{args[0], args[1], args[2]}) tlist.Items = append(tlist.Items, METri{args[0], args[1], args[2]})
} else {
tlist.Items = append(tlist.Items, METri{"", args[0], args[1]})
} }
return append(msgList, METri{"", args[0], args[1]})
} }
type CountTest struct { type CountTest struct {
@ -1215,91 +1220,91 @@ func TestWordCount(t *testing.T) {
} }
func TestPreparser(t *testing.T) { func TestPreparser(t *testing.T) {
var msgList []METri var msgList = &METriList{nil}
// Note: The open tag is evaluated without knowledge of the close tag for efficiency and simplicity, so the parser autofills the associated close tag when it finds an open tag without a partner // Note: The open tag is evaluated without knowledge of the close tag for efficiency and simplicity, so the parser autofills the associated close tag when it finds an open tag without a partner
msgList = addMETri(msgList, "", "") msgList.Add("", "")
msgList = addMETri(msgList, " ", "") msgList.Add(" ", "")
msgList = addMETri(msgList, " hi", "hi") msgList.Add(" hi", "hi")
msgList = addMETri(msgList, "hi ", "hi") msgList.Add("hi ", "hi")
msgList = addMETri(msgList, "hi", "hi") msgList.Add("hi", "hi")
msgList = addMETri(msgList, ":grinning:", "😀") msgList.Add(":grinning:", "😀")
msgList = addMETri(msgList, "😀", "😀") msgList.Add("😀", "😀")
msgList = addMETri(msgList, "&nbsp;", "") msgList.Add("&nbsp;", "")
msgList = addMETri(msgList, "<p>", "") msgList.Add("<p>", "")
msgList = addMETri(msgList, "</p>", "") msgList.Add("</p>", "")
msgList = addMETri(msgList, "<p></p>", "") msgList.Add("<p></p>", "")
msgList = addMETri(msgList, "<", "&lt;") msgList.Add("<", "&lt;")
msgList = addMETri(msgList, ">", "&gt;") msgList.Add(">", "&gt;")
msgList = addMETri(msgList, "<meow>", "&lt;meow&gt;") msgList.Add("<meow>", "&lt;meow&gt;")
msgList = addMETri(msgList, "&lt;", "&amp;lt;") msgList.Add("&lt;", "&amp;lt;")
msgList = addMETri(msgList, "&", "&amp;") msgList.Add("&", "&amp;")
// Note: strings.TrimSpace strips newlines, if there's nothing before or after them // Note: strings.TrimSpace strips newlines, if there's nothing before or after them
msgList = addMETri(msgList, "<br>", "") msgList.Add("<br>", "")
msgList = addMETri(msgList, "<br />", "") msgList.Add("<br />", "")
msgList = addMETri(msgList, "\\n", "\n", "") msgList.Add("\\n", "\n", "")
msgList = addMETri(msgList, "\\n\\n", "\n\n", "") msgList.Add("\\n\\n", "\n\n", "")
msgList = addMETri(msgList, "\\n\\n\\n", "\n\n\n", "") msgList.Add("\\n\\n\\n", "\n\n\n", "")
msgList = addMETri(msgList, "\\r\\n", "\r\n", "") // Windows style line ending msgList.Add("\\r\\n", "\r\n", "") // Windows style line ending
msgList = addMETri(msgList, "\\n\\r", "\n\r", "") msgList.Add("\\n\\r", "\n\r", "")
msgList = addMETri(msgList, "ho<br>ho", "ho\n\nho") msgList.Add("ho<br>ho", "ho\n\nho")
msgList = addMETri(msgList, "ho<br />ho", "ho\n\nho") msgList.Add("ho<br />ho", "ho\n\nho")
msgList = addMETri(msgList, "ho\\nho", "ho\nho", "ho\nho") msgList.Add("ho\\nho", "ho\nho", "ho\nho")
msgList = addMETri(msgList, "ho\\n\\nho", "ho\n\nho", "ho\n\nho") msgList.Add("ho\\n\\nho", "ho\n\nho", "ho\n\nho")
//msgList = addMETri(msgList, "ho\\n\\n\\n\\nho", "ho\n\n\n\nho", "ho\n\n\nho") //msgList.Add("ho\\n\\n\\n\\nho", "ho\n\n\n\nho", "ho\n\n\nho")
msgList = addMETri(msgList, "ho\\r\\nho", "ho\r\nho", "ho\nho") // Windows style line ending msgList.Add("ho\\r\\nho", "ho\r\nho", "ho\nho") // Windows style line ending
msgList = addMETri(msgList, "ho\\n\\rho", "ho\n\rho", "ho\nho") msgList.Add("ho\\n\\rho", "ho\n\rho", "ho\nho")
msgList = addMETri(msgList, "<b></b>", "<strong></strong>") msgList.Add("<b></b>", "<strong></strong>")
msgList = addMETri(msgList, "<b>hi</b>", "<strong>hi</strong>") msgList.Add("<b>hi</b>", "<strong>hi</strong>")
msgList = addMETri(msgList, "<s>hi</s>", "<del>hi</del>") msgList.Add("<s>hi</s>", "<del>hi</del>")
msgList = addMETri(msgList, "<del>hi</del>", "<del>hi</del>") msgList.Add("<del>hi</del>", "<del>hi</del>")
msgList = addMETri(msgList, "<u>hi</u>", "<u>hi</u>") msgList.Add("<u>hi</u>", "<u>hi</u>")
msgList = addMETri(msgList, "<em>hi</em>", "<em>hi</em>") msgList.Add("<em>hi</em>", "<em>hi</em>")
msgList = addMETri(msgList, "<i>hi</i>", "<em>hi</em>") msgList.Add("<i>hi</i>", "<em>hi</em>")
msgList = addMETri(msgList, "<strong>hi</strong>", "<strong>hi</strong>") msgList.Add("<strong>hi</strong>", "<strong>hi</strong>")
msgList = addMETri(msgList, "<b><i>hi</i></b>", "<strong><em>hi</em></strong>") msgList.Add("<b><i>hi</i></b>", "<strong><em>hi</em></strong>")
msgList = addMETri(msgList, "<strong><em>hi</em></strong>", "<strong><em>hi</em></strong>") msgList.Add("<strong><em>hi</em></strong>", "<strong><em>hi</em></strong>")
msgList = addMETri(msgList, "<b><i><b>hi</b></i></b>", "<strong><em><strong>hi</strong></em></strong>") msgList.Add("<b><i><b>hi</b></i></b>", "<strong><em><strong>hi</strong></em></strong>")
msgList = addMETri(msgList, "<strong><em><strong>hi</strong></em></strong>", "<strong><em><strong>hi</strong></em></strong>") msgList.Add("<strong><em><strong>hi</strong></em></strong>", "<strong><em><strong>hi</strong></em></strong>")
msgList = addMETri(msgList, "<div>hi</div>", "&lt;div&gt;hi&lt;/div&gt;") msgList.Add("<div>hi</div>", "&lt;div&gt;hi&lt;/div&gt;")
msgList = addMETri(msgList, "<span>hi</span>", "hi") // This is stripped since the editor (Trumbowyg) likes blasting useless spans msgList.Add("<span>hi</span>", "hi") // This is stripped since the editor (Trumbowyg) likes blasting useless spans
msgList = addMETri(msgList, "<span >hi</span>", "hi") msgList.Add("<span >hi</span>", "hi")
msgList = addMETri(msgList, "<span style='background-color: yellow;'>hi</span>", "hi") msgList.Add("<span style='background-color: yellow;'>hi</span>", "hi")
msgList = addMETri(msgList, "<span style='background-color: yellow;'>>hi</span>", "&gt;hi") msgList.Add("<span style='background-color: yellow;'>>hi</span>", "&gt;hi")
msgList = addMETri(msgList, "<b>hi", "<strong>hi</strong>") msgList.Add("<b>hi", "<strong>hi</strong>")
msgList = addMETri(msgList, "hi</b>", "hi&lt;/b&gt;") msgList.Add("hi</b>", "hi&lt;/b&gt;")
msgList = addMETri(msgList, "</b>", "&lt;/b&gt;") msgList.Add("</b>", "&lt;/b&gt;")
msgList = addMETri(msgList, "</del>", "&lt;/del&gt;") msgList.Add("</del>", "&lt;/del&gt;")
msgList = addMETri(msgList, "</strong>", "&lt;/strong&gt;") msgList.Add("</strong>", "&lt;/strong&gt;")
msgList = addMETri(msgList, "<b>", "<strong></strong>") msgList.Add("<b>", "<strong></strong>")
msgList = addMETri(msgList, "<span style='background-color: yellow;'>hi", "hi") msgList.Add("<span style='background-color: yellow;'>hi", "hi")
msgList = addMETri(msgList, "hi</span>", "hi") msgList.Add("hi</span>", "hi")
msgList = addMETri(msgList, "</span>", "") msgList.Add("</span>", "")
msgList = addMETri(msgList, "<span></span>", "") msgList.Add("<span></span>", "")
msgList = addMETri(msgList, "<span ></span>", "") msgList.Add("<span ></span>", "")
msgList = addMETri(msgList, "<></>", "&lt;&gt;&lt;/&gt;") msgList.Add("<></>", "&lt;&gt;&lt;/&gt;")
msgList = addMETri(msgList, "</><>", "&lt;/&gt;&lt;&gt;") msgList.Add("</><>", "&lt;/&gt;&lt;&gt;")
msgList = addMETri(msgList, "<>", "&lt;&gt;") msgList.Add("<>", "&lt;&gt;")
msgList = addMETri(msgList, "</>", "&lt;/&gt;") msgList.Add("</>", "&lt;/&gt;")
msgList = addMETri(msgList, "@", "@") msgList.Add("@", "@")
msgList = addMETri(msgList, "@Admin", "@1") msgList.Add("@Admin", "@1")
msgList = addMETri(msgList, "@Bah", "@Bah") msgList.Add("@Bah", "@Bah")
msgList = addMETri(msgList, " @Admin", "@1") msgList.Add(" @Admin", "@1")
msgList = addMETri(msgList, "\n@Admin", "@1") msgList.Add("\n@Admin", "@1")
msgList = addMETri(msgList, "@Admin\n", "@1") msgList.Add("@Admin\n", "@1")
msgList = addMETri(msgList, "@Admin\ndd", "@1\ndd") msgList.Add("@Admin\ndd", "@1\ndd")
msgList = addMETri(msgList, "d@Admin", "d@Admin") msgList.Add("d@Admin", "d@Admin")
//msgList = addMETri(msgList, "byte 0", string([]byte{0}), "") //msgList.Add("byte 0", string([]byte{0}), "")
msgList = addMETri(msgList, "byte 'a'", string([]byte{'a'}), "a") msgList.Add("byte 'a'", string([]byte{'a'}), "a")
//msgList = addMETri(msgList, "byte 255", string([]byte{255}), "") //msgList.Add("byte 255", string([]byte{255}), "")
//msgList = addMETri(msgList, "rune 0", string([]rune{0}), "") //msgList.Add("rune 0", string([]rune{0}), "")
// TODO: Do a test with invalid UTF-8 input // TODO: Do a test with invalid UTF-8 input
for _, item := range msgList { for _, item := range msgList.Items {
res := common.PreparseMessage(item.Msg) res := common.PreparseMessage(item.Msg)
if res != item.Expects { if res != item.Expects {
if item.Name != "" { if item.Name != "" {
@ -1314,28 +1319,28 @@ func TestPreparser(t *testing.T) {
} }
func TestParser(t *testing.T) { func TestParser(t *testing.T) {
var msgList []METri var msgList = &METriList{nil}
msgList = addMETri(msgList, "//github.com/Azareal/Gosora", "<a href='//github.com/Azareal/Gosora'>//github.com/Azareal/Gosora</a>") msgList.Add("//github.com/Azareal/Gosora", "<a href='//github.com/Azareal/Gosora'>//github.com/Azareal/Gosora</a>")
msgList = addMETri(msgList, "https://github.com/Azareal/Gosora", "<a href='https://github.com/Azareal/Gosora'>https://github.com/Azareal/Gosora</a>") msgList.Add("https://github.com/Azareal/Gosora", "<a href='https://github.com/Azareal/Gosora'>https://github.com/Azareal/Gosora</a>")
msgList = addMETri(msgList, "http://github.com/Azareal/Gosora", "<a href='http://github.com/Azareal/Gosora'>http://github.com/Azareal/Gosora</a>") msgList.Add("http://github.com/Azareal/Gosora", "<a href='http://github.com/Azareal/Gosora'>http://github.com/Azareal/Gosora</a>")
msgList = addMETri(msgList, "//github.com/Azareal/Gosora\n", "<a href='//github.com/Azareal/Gosora'>//github.com/Azareal/Gosora</a><br>") msgList.Add("//github.com/Azareal/Gosora\n", "<a href='//github.com/Azareal/Gosora'>//github.com/Azareal/Gosora</a><br>")
msgList = addMETri(msgList, "\n//github.com/Azareal/Gosora", "<br><a href='//github.com/Azareal/Gosora'>//github.com/Azareal/Gosora</a>") msgList.Add("\n//github.com/Azareal/Gosora", "<br><a href='//github.com/Azareal/Gosora'>//github.com/Azareal/Gosora</a>")
msgList = addMETri(msgList, "\n//github.com/Azareal/Gosora\n", "<br><a href='//github.com/Azareal/Gosora'>//github.com/Azareal/Gosora</a><br>") msgList.Add("\n//github.com/Azareal/Gosora\n", "<br><a href='//github.com/Azareal/Gosora'>//github.com/Azareal/Gosora</a><br>")
msgList = addMETri(msgList, "//github.com/Azareal/Gosora\n//github.com/Azareal/Gosora", "<a href='//github.com/Azareal/Gosora'>//github.com/Azareal/Gosora</a><br><a href='//github.com/Azareal/Gosora'>//github.com/Azareal/Gosora</a>") msgList.Add("//github.com/Azareal/Gosora\n//github.com/Azareal/Gosora", "<a href='//github.com/Azareal/Gosora'>//github.com/Azareal/Gosora</a><br><a href='//github.com/Azareal/Gosora'>//github.com/Azareal/Gosora</a>")
msgList = addMETri(msgList, "//github.com/Azareal/Gosora\n\n//github.com/Azareal/Gosora", "<a href='//github.com/Azareal/Gosora'>//github.com/Azareal/Gosora</a><br><br><a href='//github.com/Azareal/Gosora'>//github.com/Azareal/Gosora</a>") msgList.Add("//github.com/Azareal/Gosora\n\n//github.com/Azareal/Gosora", "<a href='//github.com/Azareal/Gosora'>//github.com/Azareal/Gosora</a><br><br><a href='//github.com/Azareal/Gosora'>//github.com/Azareal/Gosora</a>")
msgList = addMETri(msgList, "//"+common.Site.URL, "<a href='//"+common.Site.URL+"'>//"+common.Site.URL+"</a>") msgList.Add("//"+common.Site.URL, "<a href='//"+common.Site.URL+"'>//"+common.Site.URL+"</a>")
msgList = addMETri(msgList, "//"+common.Site.URL+"\n", "<a href='//"+common.Site.URL+"'>//"+common.Site.URL+"</a><br>") msgList.Add("//"+common.Site.URL+"\n", "<a href='//"+common.Site.URL+"'>//"+common.Site.URL+"</a><br>")
msgList = addMETri(msgList, "//"+common.Site.URL+"\n//"+common.Site.URL, "<a href='//"+common.Site.URL+"'>//"+common.Site.URL+"</a><br><a href='//"+common.Site.URL+"'>//"+common.Site.URL+"</a>") msgList.Add("//"+common.Site.URL+"\n//"+common.Site.URL, "<a href='//"+common.Site.URL+"'>//"+common.Site.URL+"</a><br><a href='//"+common.Site.URL+"'>//"+common.Site.URL+"</a>")
msgList = addMETri(msgList, "#tid-1", "<a href='/topic/1'>#tid-1</a>") msgList.Add("#tid-1", "<a href='/topic/1'>#tid-1</a>")
msgList = addMETri(msgList, "https://github.com/Azareal/Gosora/#tid-1", "<a href='https://github.com/Azareal/Gosora/#tid-1'>https://github.com/Azareal/Gosora/#tid-1</a>") msgList.Add("https://github.com/Azareal/Gosora/#tid-1", "<a href='https://github.com/Azareal/Gosora/#tid-1'>https://github.com/Azareal/Gosora/#tid-1</a>")
msgList = addMETri(msgList, "#fid-1", "<a href='/forum/1'>#fid-1</a>") msgList.Add("#fid-1", "<a href='/forum/1'>#fid-1</a>")
msgList = addMETri(msgList, "@1", "<a href='/user/admin.1' class='mention'>@Admin</a>") msgList.Add("@1", "<a href='/user/admin.1' class='mention'>@Admin</a>")
msgList = addMETri(msgList, "@0", "<span style='color: red;'>[Invalid Profile]</span>") msgList.Add("@0", "<span style='color: red;'>[Invalid Profile]</span>")
msgList = addMETri(msgList, "@-1", "<span style='color: red;'>[Invalid Profile]</span>1") msgList.Add("@-1", "<span style='color: red;'>[Invalid Profile]</span>1")
for _, item := range msgList { for _, item := range msgList.Items {
res := common.ParseMessage(item.Msg, 1, "forums") res := common.ParseMessage(item.Msg, 1, "forums")
if res != item.Expects { if res != item.Expects {
if item.Name != "" { if item.Name != "" {

View File

@ -10,8 +10,12 @@ type MEPair struct {
Expects string Expects string
} }
func addMEPair(msgList []MEPair, msg string, expects string) []MEPair { type MEPairList struct {
return append(msgList, MEPair{msg, expects}) Items []MEPair
}
func (tlist *MEPairList) Add(msg string, expects string) {
tlist.Items = append(tlist.Items, MEPair{msg, expects})
} }
func TestBBCodeRender(t *testing.T) { func TestBBCodeRender(t *testing.T) {
@ -22,47 +26,47 @@ func TestBBCodeRender(t *testing.T) {
} }
var res string var res string
var msgList []MEPair var msgList = &MEPairList{nil}
msgList = addMEPair(msgList, "", "") msgList.Add("", "")
msgList = addMEPair(msgList, " ", " ") msgList.Add(" ", " ")
msgList = addMEPair(msgList, " ", " ") msgList.Add(" ", " ")
msgList = addMEPair(msgList, " ", " ") msgList.Add(" ", " ")
msgList = addMEPair(msgList, "[b]", "<b></b>") msgList.Add("[b]", "<b></b>")
msgList = addMEPair(msgList, "[b][/b]", "<b></b>") msgList.Add("[b][/b]", "<b></b>")
msgList = addMEPair(msgList, "hi", "hi") msgList.Add("hi", "hi")
msgList = addMEPair(msgList, "😀", "😀") msgList.Add("😀", "😀")
msgList = addMEPair(msgList, "[b]😀[/b]", "<b>😀</b>") msgList.Add("[b]😀[/b]", "<b>😀</b>")
msgList = addMEPair(msgList, "[b]😀😀😀[/b]", "<b>😀😀😀</b>") msgList.Add("[b]😀😀😀[/b]", "<b>😀😀😀</b>")
msgList = addMEPair(msgList, "[b]hi[/b]", "<b>hi</b>") msgList.Add("[b]hi[/b]", "<b>hi</b>")
msgList = addMEPair(msgList, "[u]hi[/u]", "<u>hi</u>") msgList.Add("[u]hi[/u]", "<u>hi</u>")
msgList = addMEPair(msgList, "[i]hi[/i]", "<i>hi</i>") msgList.Add("[i]hi[/i]", "<i>hi</i>")
msgList = addMEPair(msgList, "[s]hi[/s]", "<s>hi</s>") msgList.Add("[s]hi[/s]", "<s>hi</s>")
msgList = addMEPair(msgList, "[c]hi[/c]", "[c]hi[/c]") msgList.Add("[c]hi[/c]", "[c]hi[/c]")
if !testing.Short() { if !testing.Short() {
//msgList = addMEPair(msgList, "[b]hi[/i]", "[b]hi[/i]") //msgList.Add("[b]hi[/i]", "[b]hi[/i]")
//msgList = addMEPair(msgList, "[/b]hi[b]", "[/b]hi[b]") //msgList.Add("[/b]hi[b]", "[/b]hi[b]")
//msgList = addMEPair(msgList, "[/b]hi[/b]", "[/b]hi[/b]") //msgList.Add("[/b]hi[/b]", "[/b]hi[/b]")
//msgList = addMEPair(msgList, "[b][b]hi[/b]", "<b>hi</b>") //msgList.Add("[b][b]hi[/b]", "<b>hi</b>")
//msgList = addMEPair(msgList, "[b][b]hi", "[b][b]hi") //msgList.Add("[b][b]hi", "[b][b]hi")
//msgList = addMEPair(msgList, "[b][b][b]hi", "[b][b][b]hi") //msgList.Add("[b][b][b]hi", "[b][b][b]hi")
//msgList = addMEPair(msgList, "[/b]hi", "[/b]hi") //msgList.Add("[/b]hi", "[/b]hi")
} }
msgList = addMEPair(msgList, "[code]hi[/code]", "<span class='codequotes'>hi</span>") msgList.Add("[code]hi[/code]", "<span class='codequotes'>hi</span>")
msgList = addMEPair(msgList, "[code][b]hi[/b][/code]", "<span class='codequotes'>[b]hi[/b]</span>") msgList.Add("[code][b]hi[/b][/code]", "<span class='codequotes'>[b]hi[/b]</span>")
msgList = addMEPair(msgList, "[code][b]hi[/code][/b]", "<span class='codequotes'>[b]hi</span>[/b]") msgList.Add("[code][b]hi[/code][/b]", "<span class='codequotes'>[b]hi</span>[/b]")
msgList = addMEPair(msgList, "[quote]hi[/quote]", "<span class='postQuote'>hi</span>") msgList.Add("[quote]hi[/quote]", "<span class='postQuote'>hi</span>")
msgList = addMEPair(msgList, "[quote][b]hi[/b][/quote]", "<span class='postQuote'><b>hi</b></span>") msgList.Add("[quote][b]hi[/b][/quote]", "<span class='postQuote'><b>hi</b></span>")
msgList = addMEPair(msgList, "[quote][b]h[/b][/quote]", "<span class='postQuote'><b>h</b></span>") msgList.Add("[quote][b]h[/b][/quote]", "<span class='postQuote'><b>h</b></span>")
msgList = addMEPair(msgList, "[quote][b][/b][/quote]", "<span class='postQuote'><b></b></span>") msgList.Add("[quote][b][/b][/quote]", "<span class='postQuote'><b></b></span>")
msgList = addMEPair(msgList, "[url][/url]", "<a href=''></a>") msgList.Add("[url][/url]", "<a href=''></a>")
msgList = addMEPair(msgList, "[url]https://github.com/Azareal/Gosora[/url]", "<a href='https://github.com/Azareal/Gosora'>https://github.com/Azareal/Gosora</a>") msgList.Add("[url]https://github.com/Azareal/Gosora[/url]", "<a href='https://github.com/Azareal/Gosora'>https://github.com/Azareal/Gosora</a>")
msgList = addMEPair(msgList, "[url]http://github.com/Azareal/Gosora[/url]", "<a href='http://github.com/Azareal/Gosora'>http://github.com/Azareal/Gosora</a>") msgList.Add("[url]http://github.com/Azareal/Gosora[/url]", "<a href='http://github.com/Azareal/Gosora'>http://github.com/Azareal/Gosora</a>")
msgList = addMEPair(msgList, "[url]//github.com/Azareal/Gosora[/url]", "<a href='//github.com/Azareal/Gosora'>//github.com/Azareal/Gosora</a>") msgList.Add("[url]//github.com/Azareal/Gosora[/url]", "<a href='//github.com/Azareal/Gosora'>//github.com/Azareal/Gosora</a>")
msgList = addMEPair(msgList, "-你好-", "-你好-") msgList.Add("-你好-", "-你好-")
msgList = addMEPair(msgList, "[i]-你好-[/i]", "<i>-你好-</i>") // TODO: More of these Unicode tests? Emoji, Chinese, etc.? msgList.Add("[i]-你好-[/i]", "<i>-你好-</i>") // TODO: More of these Unicode tests? Emoji, Chinese, etc.?
t.Log("Testing bbcodeFullParse") t.Log("Testing bbcodeFullParse")
for _, item := range msgList { for _, item := range msgList.Items {
res = bbcodeFullParse(item.Msg) res = bbcodeFullParse(item.Msg)
if res != item.Expects { if res != item.Expects {
t.Error("Testing string '" + item.Msg + "'") t.Error("Testing string '" + item.Msg + "'")
@ -211,70 +215,70 @@ func TestMarkdownRender(t *testing.T) {
} }
var res string var res string
var msgList []MEPair var msgList = &MEPairList{nil}
// TODO: Fix more of these odd cases // TODO: Fix more of these odd cases
msgList = addMEPair(msgList, "", "") msgList.Add("", "")
msgList = addMEPair(msgList, " ", " ") msgList.Add(" ", " ")
msgList = addMEPair(msgList, " ", " ") msgList.Add(" ", " ")
msgList = addMEPair(msgList, " ", " ") msgList.Add(" ", " ")
msgList = addMEPair(msgList, "\t", "\t") msgList.Add("\t", "\t")
msgList = addMEPair(msgList, "\n", "\n") msgList.Add("\n", "\n")
msgList = addMEPair(msgList, "*", "*") msgList.Add("*", "*")
//msgList = addMEPair(msgList, "**", "<i></i>") //msgList.Add("**", "<i></i>")
msgList = addMEPair(msgList, "h", "h") msgList.Add("h", "h")
msgList = addMEPair(msgList, "hi", "hi") msgList.Add("hi", "hi")
msgList = addMEPair(msgList, "**h**", "<b>h</b>") msgList.Add("**h**", "<b>h</b>")
msgList = addMEPair(msgList, "**hi**", "<b>hi</b>") msgList.Add("**hi**", "<b>hi</b>")
msgList = addMEPair(msgList, "_h_", "<u>h</u>") msgList.Add("_h_", "<u>h</u>")
msgList = addMEPair(msgList, "_hi_", "<u>hi</u>") msgList.Add("_hi_", "<u>hi</u>")
msgList = addMEPair(msgList, "*h*", "<i>h</i>") msgList.Add("*h*", "<i>h</i>")
msgList = addMEPair(msgList, "*hi*", "<i>hi</i>") msgList.Add("*hi*", "<i>hi</i>")
msgList = addMEPair(msgList, "~h~", "<s>h</s>") msgList.Add("~h~", "<s>h</s>")
msgList = addMEPair(msgList, "~hi~", "<s>hi</s>") msgList.Add("~hi~", "<s>hi</s>")
msgList = addMEPair(msgList, "*hi**", "<i>hi</i>*") msgList.Add("*hi**", "<i>hi</i>*")
msgList = addMEPair(msgList, "**hi***", "<b>hi</b>*") msgList.Add("**hi***", "<b>hi</b>*")
//msgList = addMEPair(msgList, "**hi*", "*<i>hi</i>") //msgList.Add("**hi*", "*<i>hi</i>")
msgList = addMEPair(msgList, "***hi***", "<b><i>hi</i></b>") msgList.Add("***hi***", "<b><i>hi</i></b>")
msgList = addMEPair(msgList, "***h***", "<b><i>h</i></b>") msgList.Add("***h***", "<b><i>h</i></b>")
msgList = addMEPair(msgList, "\\***h**\\*", "*<b>h</b>*") msgList.Add("\\***h**\\*", "*<b>h</b>*")
msgList = addMEPair(msgList, "\\*\\**h*\\*\\*", "**<i>h</i>**") msgList.Add("\\*\\**h*\\*\\*", "**<i>h</i>**")
msgList = addMEPair(msgList, "\\*hi\\*", "*hi*") msgList.Add("\\*hi\\*", "*hi*")
msgList = addMEPair(msgList, "d\\*hi\\*", "d*hi*") msgList.Add("d\\*hi\\*", "d*hi*")
msgList = addMEPair(msgList, "\\*hi\\*d", "*hi*d") msgList.Add("\\*hi\\*d", "*hi*d")
msgList = addMEPair(msgList, "d\\*hi\\*d", "d*hi*d") msgList.Add("d\\*hi\\*d", "d*hi*d")
msgList = addMEPair(msgList, "\\", "\\") msgList.Add("\\", "\\")
msgList = addMEPair(msgList, "\\\\", "\\\\") msgList.Add("\\\\", "\\\\")
msgList = addMEPair(msgList, "\\d", "\\d") msgList.Add("\\d", "\\d")
msgList = addMEPair(msgList, "\\\\d", "\\\\d") msgList.Add("\\\\d", "\\\\d")
msgList = addMEPair(msgList, "\\\\\\d", "\\\\\\d") msgList.Add("\\\\\\d", "\\\\\\d")
msgList = addMEPair(msgList, "d\\", "d\\") msgList.Add("d\\", "d\\")
msgList = addMEPair(msgList, "\\d\\", "\\d\\") msgList.Add("\\d\\", "\\d\\")
msgList = addMEPair(msgList, "*_hi_*", "<i><u>hi</u></i>") msgList.Add("*_hi_*", "<i><u>hi</u></i>")
msgList = addMEPair(msgList, "*~hi~*", "<i><s>hi</s></i>") msgList.Add("*~hi~*", "<i><s>hi</s></i>")
//msgList = addMEPair(msgList, "~*hi*~", "<s><i>hi</i></s>") //msgList.Add("~*hi*~", "<s><i>hi</i></s>")
//msgList = addMEPair(msgList, "~ *hi* ~", "<s> <i>hi</i> </s>") //msgList.Add("~ *hi* ~", "<s> <i>hi</i> </s>")
msgList = addMEPair(msgList, "_~hi~_", "<u><s>hi</s></u>") msgList.Add("_~hi~_", "<u><s>hi</s></u>")
msgList = addMEPair(msgList, "***~hi~***", "<b><i><s>hi</s></i></b>") msgList.Add("***~hi~***", "<b><i><s>hi</s></i></b>")
msgList = addMEPair(msgList, "**", "**") msgList.Add("**", "**")
msgList = addMEPair(msgList, "***", "***") msgList.Add("***", "***")
msgList = addMEPair(msgList, "****", "****") msgList.Add("****", "****")
msgList = addMEPair(msgList, "*****", "*****") msgList.Add("*****", "*****")
msgList = addMEPair(msgList, "******", "******") msgList.Add("******", "******")
msgList = addMEPair(msgList, "*******", "*******") msgList.Add("*******", "*******")
msgList = addMEPair(msgList, "~~", "~~") msgList.Add("~~", "~~")
msgList = addMEPair(msgList, "~~~", "~~~") msgList.Add("~~~", "~~~")
msgList = addMEPair(msgList, "~~~~", "~~~~") msgList.Add("~~~~", "~~~~")
msgList = addMEPair(msgList, "~~~~~", "~~~~~") msgList.Add("~~~~~", "~~~~~")
msgList = addMEPair(msgList, "__", "__") msgList.Add("__", "__")
msgList = addMEPair(msgList, "___", "___") msgList.Add("___", "___")
msgList = addMEPair(msgList, "_ _", "<u> </u>") msgList.Add("_ _", "<u> </u>")
msgList = addMEPair(msgList, "* *", "<i> </i>") msgList.Add("* *", "<i> </i>")
msgList = addMEPair(msgList, "** **", "<b> </b>") msgList.Add("** **", "<b> </b>")
msgList = addMEPair(msgList, "*** ***", "<b><i> </i></b>") msgList.Add("*** ***", "<b><i> </i></b>")
msgList = addMEPair(msgList, "-你好-", "-你好-") msgList.Add("-你好-", "-你好-")
msgList = addMEPair(msgList, "*-你好-*", "<i>-你好-</i>") // TODO: More of these Unicode tests? Emoji, Chinese, etc.? msgList.Add("*-你好-*", "<i>-你好-</i>") // TODO: More of these Unicode tests? Emoji, Chinese, etc.?
for _, item := range msgList { for _, item := range msgList.Items {
res = markdownParse(item.Msg) res = markdownParse(item.Msg)
if res != item.Expects { if res != item.Expects {
t.Error("Testing string '" + item.Msg + "'") t.Error("Testing string '" + item.Msg + "'")
@ -284,7 +288,7 @@ func TestMarkdownRender(t *testing.T) {
} }
} }
/*for _, item := range msgList { /*for _, item := range msgList.Items {
res = markdownParse("\n" + item.Msg) res = markdownParse("\n" + item.Msg)
if res != "\n"+item.Expects { if res != "\n"+item.Expects {
t.Error("Testing string '\n" + item.Msg + "'") t.Error("Testing string '\n" + item.Msg + "'")
@ -294,7 +298,7 @@ func TestMarkdownRender(t *testing.T) {
} }
} }
for _, item := range msgList { for _, item := range msgList.Items {
res = markdownParse("\t" + item.Msg) res = markdownParse("\t" + item.Msg)
if res != "\t"+item.Expects { if res != "\t"+item.Expects {
t.Error("Testing string '\t" + item.Msg + "'") t.Error("Testing string '\t" + item.Msg + "'")
@ -304,7 +308,7 @@ func TestMarkdownRender(t *testing.T) {
} }
}*/ }*/
for _, item := range msgList { for _, item := range msgList.Items {
res = markdownParse("d" + item.Msg) res = markdownParse("d" + item.Msg)
if res != "d"+item.Expects { if res != "d"+item.Expects {
t.Error("Testing string 'd" + item.Msg + "'") t.Error("Testing string 'd" + item.Msg + "'")