mirror of
https://github.com/bbernhard/signal-cli-rest-api.git
synced 2026-01-26 19:03:33 +00:00
parent
08cd2bd12c
commit
d6488d6c8e
@ -141,12 +141,14 @@ func (l *TextstyleParser) Parse() (string, []string) {
|
||||
l.next()
|
||||
if prevChar == EscapeCharacter {
|
||||
prevChar = c
|
||||
l.fullString += "**"
|
||||
continue
|
||||
}
|
||||
l.handleToken(BoldBegin, Bold)
|
||||
} else { //Italic
|
||||
if prevChar == EscapeCharacter {
|
||||
prevChar = c
|
||||
l.fullString += "*"
|
||||
continue
|
||||
}
|
||||
l.handleToken(ItalicBegin, Italic)
|
||||
@ -155,18 +157,21 @@ func (l *TextstyleParser) Parse() (string, []string) {
|
||||
l.next()
|
||||
if prevChar == EscapeCharacter {
|
||||
prevChar = c
|
||||
l.fullString += "||"
|
||||
continue
|
||||
}
|
||||
l.handleToken(SpoilerBegin, Spoiler)
|
||||
} else if c == '~' {
|
||||
if prevChar == EscapeCharacter {
|
||||
prevChar = c
|
||||
l.fullString += "~"
|
||||
continue
|
||||
}
|
||||
l.handleToken(StrikethroughBegin, Strikethrough)
|
||||
} else if c == '`' {
|
||||
if prevChar == EscapeCharacter {
|
||||
prevChar = c
|
||||
l.fullString += "`"
|
||||
continue
|
||||
}
|
||||
l.handleToken(MonoSpaceBegin, Monospace)
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
package utils
|
||||
|
||||
import "testing"
|
||||
import "reflect"
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func expectMessageEqual(t *testing.T, message1 string, message2 string) {
|
||||
if message1 != message2 {
|
||||
@ -123,27 +125,35 @@ func TestBoldTextInsideSpoiler(t *testing.T) {
|
||||
func TestEscapeAsterisks(t *testing.T) {
|
||||
textstyleParser := NewTextstyleParser("\\*escaped text\\*")
|
||||
message, signalCliFormatStrings := textstyleParser.Parse()
|
||||
expectMessageEqual(t, message, "escaped text")
|
||||
expectMessageEqual(t, message, "*escaped text*")
|
||||
expectFormatStringsEqual(t, signalCliFormatStrings, []string{})
|
||||
}
|
||||
|
||||
func TestEscapeAsterisks1(t *testing.T) {
|
||||
textstyleParser := NewTextstyleParser("\\**escaped text\\**")
|
||||
message, signalCliFormatStrings := textstyleParser.Parse()
|
||||
expectMessageEqual(t, message, "escaped text")
|
||||
expectMessageEqual(t, message, "**escaped text**")
|
||||
expectFormatStringsEqual(t, signalCliFormatStrings, []string{})
|
||||
}
|
||||
|
||||
func TestEscapeBackticks(t *testing.T) {
|
||||
textstyleParser := NewTextstyleParser("\\`escaped text\\`")
|
||||
message, signalCliFormatStrings := textstyleParser.Parse()
|
||||
expectMessageEqual(t, message, "escaped text")
|
||||
expectMessageEqual(t, message, "`escaped text`")
|
||||
expectFormatStringsEqual(t, signalCliFormatStrings, []string{})
|
||||
}
|
||||
|
||||
func TestEscapeTilde(t *testing.T) {
|
||||
textstyleParser := NewTextstyleParser("\\~escaped text\\~")
|
||||
message, signalCliFormatStrings := textstyleParser.Parse()
|
||||
expectMessageEqual(t, message, "escaped text")
|
||||
expectMessageEqual(t, message, "~escaped text~")
|
||||
expectFormatStringsEqual(t, signalCliFormatStrings, []string{})
|
||||
}
|
||||
|
||||
func TestEscapeNew(t *testing.T) {
|
||||
textstyleParser := NewTextstyleParser("Test \\** \\* \\~ Escape")
|
||||
message, signalCliFormatStrings := textstyleParser.Parse()
|
||||
expectMessageEqual(t, message, "Test ** * ~ Escape")
|
||||
expectFormatStringsEqual(t, signalCliFormatStrings, []string{})
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user