2020-12-23 03:30:08 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-03-24 14:22:00 +02:00
|
|
|
"github.com/0ranki/matrix-skype/database"
|
|
|
|
"github.com/0ranki/matrix-skype/types"
|
2020-12-23 03:30:08 +02:00
|
|
|
"maunium.net/go/mautrix/event"
|
|
|
|
"maunium.net/go/mautrix/format"
|
|
|
|
"reflect"
|
|
|
|
"regexp"
|
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFormatter_ParseSkype(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
bridge *Bridge
|
|
|
|
matrixHTMLParser *format.HTMLParser
|
|
|
|
waReplString map[*regexp.Regexp]string
|
|
|
|
waReplFunc map[*regexp.Regexp]func(string) string
|
|
|
|
waReplFuncText map[*regexp.Regexp]func(string) string
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
content *event.MessageEventContent
|
|
|
|
}
|
|
|
|
type expect struct {
|
|
|
|
content *event.MessageEventContent
|
|
|
|
}
|
|
|
|
testUser := &User{
|
|
|
|
User: &database.User{
|
|
|
|
MXID: "mxtestid",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
testBridge := &Bridge{
|
|
|
|
usersLock: *new(sync.Mutex),
|
|
|
|
usersByJID: map[types.SkypeID]*User{"test": testUser},
|
|
|
|
}
|
|
|
|
testFormatter := &Formatter{
|
|
|
|
bridge: testBridge,
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
expect expect
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"simple message",
|
|
|
|
args{
|
|
|
|
&event.MessageEventContent{
|
|
|
|
Body: "This is a very simple message.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect{
|
|
|
|
&event.MessageEventContent{
|
|
|
|
Body: "This is a very simple message.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"simple punctuation test",
|
|
|
|
args{
|
|
|
|
&event.MessageEventContent{
|
|
|
|
Body: "It's the inclusion of "simple" punctuation that causes most of the problems.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect{
|
|
|
|
&event.MessageEventContent{
|
|
|
|
Body: "It's the inclusion of \"simple\" punctuation that causes most of the problems.",
|
|
|
|
Format: event.FormatHTML,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"full punctuation test",
|
|
|
|
args{
|
|
|
|
&event.MessageEventContent{
|
|
|
|
Body: "&<>"'", // use a few different encodings
|
|
|
|
Format: event.FormatHTML,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect{
|
|
|
|
&event.MessageEventContent{
|
|
|
|
Body: "&<>\"'",
|
|
|
|
Format: event.FormatHTML,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2021-01-15 09:07:12 +02:00
|
|
|
testFormatter.ParseSkype(tt.args.content, "")
|
2020-12-23 03:30:08 +02:00
|
|
|
if !reflect.DeepEqual(tt.args.content, tt.expect.content) {
|
|
|
|
t.Errorf("content = %v, wanted %v", tt.args.content, tt.expect.content)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|