78 lines
2.5 KiB
Go
78 lines
2.5 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func LexerTestWrapper(message string, expected string) string {
|
|
lexer := Lexer{}
|
|
return Parse(lexer.Process(message)).String()
|
|
}
|
|
|
|
func LexerTestWrapperFail(expected string, result string) {
|
|
fmt.Println("Expected :", expected)
|
|
fmt.Println("Got : ", result)
|
|
}
|
|
|
|
func TestLinkNoTag(t *testing.T) {
|
|
var message string = "** https://pleroma.social/announcements/feed.xml"
|
|
var expected string = "https://pleroma.social/announcements/feed.xml"
|
|
result := LexerTestWrapper(message, expected)
|
|
if result != expected {
|
|
LexerTestWrapperFail(expected, result)
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestLinkTag(t *testing.T) {
|
|
var message string = "** https://pleroma.social/announcements/feed.xml :software: :social:"
|
|
var expected string = "https://pleroma.social/announcements/feed.xml software social"
|
|
result := LexerTestWrapper(message, expected)
|
|
if result != expected {
|
|
LexerTestWrapperFail(expected, result)
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestLinkDescTag(t *testing.T) {
|
|
var message string = "** [[https://pleroma.social/announcements/feed.xml][Pleroma Social]] :software:"
|
|
var expected string = "https://pleroma.social/announcements/feed.xml software # Pleroma Social"
|
|
var result string = LexerTestWrapper(message, expected)
|
|
if result != expected {
|
|
LexerTestWrapperFail(expected, result)
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestLinkDescManyTagsSpaces(t *testing.T) {
|
|
var message string = "** [[https://pleroma.social/announcements/feed.xml][Pleroma Social]] :software: :social: :cofe:"
|
|
var expected string = "https://pleroma.social/announcements/feed.xml software social cofe # Pleroma Social"
|
|
var result string = LexerTestWrapper(message, expected)
|
|
if result != expected {
|
|
LexerTestWrapperFail(expected, result)
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
|
|
func TestLinkDescNoTag(t *testing.T) {
|
|
var message string = "** [[https://pleroma.social/announcements/feed.xml][Pleroma Social]]"
|
|
var expected string = "https://pleroma.social/announcements/feed.xml # Pleroma Social"
|
|
var result string = LexerTestWrapper(message, expected)
|
|
if result != expected {
|
|
LexerTestWrapperFail(expected, result)
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestLinkDescWithSymbols(t *testing.T) {
|
|
var message string = "** [[https://pleroma.social/announcements/feed.xml][Pleroma Social [*Very Cool*]]] :software:"
|
|
var expected string = "https://pleroma.social/announcements/feed.xml software # Pleroma Social [*Very Cool*]"
|
|
var result string = LexerTestWrapper(message, expected)
|
|
if result != expected {
|
|
LexerTestWrapperFail(expected, result)
|
|
t.Fail()
|
|
}
|
|
}
|