fix parser tests

expand parser tests
This commit is contained in:
Azareal 2021-02-18 23:02:54 +10:00
parent f2adb7dfac
commit 2176147dec
2 changed files with 15 additions and 2 deletions

View File

@ -633,7 +633,7 @@ func ParseMessage2(msg string, sectionID int, sectionType string, settings *Pars
case 'h', 'f', 'g', '/':
//fmt.Println("s3")
fch := msg[i+1]
if len(msg) > i+5 && fch == 't' && msg[i+2] == 't' && msg[i+3] == 'p' {
if fch == 't' && len(msg) > i+5 && msg[i+2] == 't' && msg[i+3] == 'p' {
if len(msg) > i+6 && msg[i+4] == 's' && msg[i+5] == ':' && msg[i+6] == '/' {
// Do nothing
} else if msg[i+4] == ':' && msg[i+5] == '/' {

View File

@ -192,9 +192,21 @@ func TestParser(t *testing.T) {
l.Add("git:// ", "<red>[Invalid URL]</red> ")
l.Add("ssh:// ", "ssh:// ")
l.Add("//t", "<a rel='ugc'href='//t'>t</a>")
l.Add("// t", "// t")
l.Add("http:// t", "<red>[Invalid URL]</red> t")
l.Add("g", "g")
l.Add("g/", "//") // todo: fix this
l.Add("/g", "/g")
l.Add("/gg", "/gg")
l.Add("/g/", "/g/")
l.Add("hi", "hi")
l.Add("hit", "hit")
l.Add("hit:", "hit:")
l.Add("hit:/", "<a rel='ugc'href='hit:///'>/</a>") // todo: fix this
l.Add("hit://", "<a rel='ugc'href='hit://'></a>") // todo: fix this
l.Add("hit://t", "<a rel='ugc'href='hit://t'>t</a>") // todo: fix this
l.Add("h", "h")
l.Add("ht", "ht")
l.Add("htt", "htt")
@ -242,7 +254,7 @@ func TestParser(t *testing.T) {
//l.Add("//"+url+"//"+url, eurl+""+eurl)
//l.Add("//"+url+"|//"+url, eurl+"|"+eurl)
l.Add("//"+url+"|//"+url, "<red>[Invalid URL]</red>|//"+url)
l.Add("//"+url+"//"+url, "<a rel='ugc'href='//" + url + "//"+url+ "'>" + url +"//"+url+ "</a>")
l.Add("//"+url+"//"+url, "<a rel='ugc'href='//"+url+"//"+url+"'>"+url+"//"+url+"</a>")
l.Add("//"+url+"\n\n//"+url, eurl+"<br><br>"+eurl)
pre2 := c.Config.SslSchema
@ -376,6 +388,7 @@ func TestParser(t *testing.T) {
l.Add("@-1", "<red>[Invalid Profile]</red>1")
// TODO: Fix this hack and make the results a bit more reproducible, push the tests further in the process.
c.GuestUser.Perms.AutoLink = true
for _, item := range l.Items {
if res := c.ParseMessage(item.Msg, 1, "forums", nil, nil); res != item.Expects {
if item.Name != "" {