246 lines
5.7 KiB
Go
246 lines
5.7 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func Test_topicPart_String(t *testing.T) {
|
|
assert.Equal(t, "\x02\x031Now:\x03 testing\x02", (&topicPart{
|
|
PrefixColor: "1",
|
|
Prefix: "Now",
|
|
Text: "testing",
|
|
}).String())
|
|
assert.Equal(t, "\x02\x031Now:\x03 testing\x02", (&topicPart{
|
|
PrefixColor: "1",
|
|
Prefix: "Now",
|
|
Text: "testing",
|
|
Matches: []topicMatchInfo{},
|
|
}).String())
|
|
assert.Equal(t, "\x02\x031Now:\x03 a -:- b\x02", (&topicPart{
|
|
PrefixColor: "1",
|
|
Prefix: "Now",
|
|
Text: "testing",
|
|
Matches: []topicMatchInfo{
|
|
topicMatchInfo{
|
|
HomeTeam: "a",
|
|
AwayTeam: "b",
|
|
},
|
|
},
|
|
}).String())
|
|
assert.Equal(t, "\x02\x031Now:\x03 a 0:1 b\x02", (&topicPart{
|
|
PrefixColor: "1",
|
|
Prefix: "Now",
|
|
Text: "testing",
|
|
Matches: []topicMatchInfo{
|
|
topicMatchInfo{
|
|
HomeTeam: "a",
|
|
AwayTeam: "b",
|
|
Current: &topicScoreInfo{
|
|
HomeScore: 0,
|
|
AwayScore: 1,
|
|
},
|
|
},
|
|
},
|
|
}).String())
|
|
assert.EqualValues(t, "\x02\x031Now:\x03 a 0:1 b (0:0)\x02", (&topicPart{
|
|
PrefixColor: "1",
|
|
Prefix: "Now",
|
|
Text: "testing",
|
|
Matches: []topicMatchInfo{
|
|
topicMatchInfo{
|
|
HomeTeam: "a",
|
|
AwayTeam: "b",
|
|
Current: &topicScoreInfo{
|
|
HomeScore: 0,
|
|
AwayScore: 1,
|
|
},
|
|
Additional: "(0:0)",
|
|
},
|
|
},
|
|
}).String())
|
|
assert.EqualValues(t, "\x02\x031Now:\x03 a 0:1 b (0:0) + c 0:0 d\x02", (&topicPart{
|
|
PrefixColor: "1",
|
|
Prefix: "Now",
|
|
Text: "testing",
|
|
Matches: []topicMatchInfo{
|
|
topicMatchInfo{
|
|
HomeTeam: "a",
|
|
AwayTeam: "b",
|
|
Current: &topicScoreInfo{
|
|
HomeScore: 0,
|
|
AwayScore: 1,
|
|
},
|
|
Additional: "(0:0)",
|
|
},
|
|
topicMatchInfo{
|
|
HomeTeam: "c",
|
|
AwayTeam: "d",
|
|
Current: &topicScoreInfo{
|
|
HomeScore: 0,
|
|
AwayScore: 0,
|
|
},
|
|
},
|
|
},
|
|
}).String())
|
|
assert.EqualValues(t, "\x02\x031Now:\x03 a 0:1 b (0:0) + c 2:2 d (1:1)\x02", (&topicPart{
|
|
PrefixColor: "1",
|
|
Prefix: "Now",
|
|
Text: "testing",
|
|
Matches: []topicMatchInfo{
|
|
topicMatchInfo{
|
|
HomeTeam: "a",
|
|
AwayTeam: "b",
|
|
Current: &topicScoreInfo{
|
|
HomeScore: 0,
|
|
AwayScore: 1,
|
|
},
|
|
Additional: "(0:0)",
|
|
},
|
|
topicMatchInfo{
|
|
HomeTeam: "c",
|
|
AwayTeam: "d",
|
|
Current: &topicScoreInfo{
|
|
HomeScore: 2,
|
|
AwayScore: 2,
|
|
},
|
|
Additional: "(1:1)",
|
|
},
|
|
},
|
|
}).String())
|
|
}
|
|
|
|
func Test_parseTopic(t *testing.T) {
|
|
var topic topicPart
|
|
var err error
|
|
|
|
topic, err = parseTopicPart("Incompatible text")
|
|
assert.Equal(t, errIncompatibleTopicPart, err)
|
|
|
|
topic, err = parseTopicPart("\x02\x033Last:\x03 No match\x02")
|
|
if assert.Nil(t, err) {
|
|
assert.EqualValues(t, topicPart{
|
|
PrefixColor: "3",
|
|
Prefix: "Last",
|
|
Text: "No match",
|
|
}, topic)
|
|
}
|
|
|
|
topic, err = parseTopicPart("\x02\x033Last:\x03 a -:- b\x02")
|
|
if assert.Nil(t, err) {
|
|
assert.EqualValues(t, topicPart{
|
|
PrefixColor: "3",
|
|
Prefix: "Last",
|
|
Text: "a -:- b",
|
|
Matches: []topicMatchInfo{
|
|
topicMatchInfo{
|
|
HomeTeam: "a",
|
|
AwayTeam: "b",
|
|
},
|
|
},
|
|
}, topic)
|
|
}
|
|
|
|
topic, err = parseTopicPart(" \x02\x0313Last:\x03 needs to be replaced by the bot\x02 ")
|
|
if assert.Nil(t, err) {
|
|
assert.EqualValues(t, topicPart{
|
|
PrefixColor: "13",
|
|
Prefix: "Last",
|
|
Text: "needs to be replaced by the bot",
|
|
}, topic)
|
|
}
|
|
|
|
topic, err = parseTopicPart("\x02\x033Last:\x03 a 0:0 b (0:0)\x02")
|
|
if assert.Nil(t, err) {
|
|
assert.EqualValues(t, topicPart{
|
|
PrefixColor: "3",
|
|
Prefix: "Last",
|
|
Text: "a 0:0 b (0:0)",
|
|
Matches: []topicMatchInfo{
|
|
topicMatchInfo{
|
|
HomeTeam: "a",
|
|
AwayTeam: "b",
|
|
Current: &topicScoreInfo{
|
|
HomeScore: 0,
|
|
AwayScore: 0,
|
|
},
|
|
Additional: "(0:0)",
|
|
},
|
|
},
|
|
}, topic)
|
|
}
|
|
}
|
|
|
|
func Test_topicPart_Matches_AdditionalScoreInfo(t *testing.T) {
|
|
topic, err := parseTopicPart("\x02\x033Last:\x03 a 0:0 b [aBx] (0:0) (abcd)\x02")
|
|
if assert.Nil(t, err) && assert.Len(t, topic.Matches, 1) {
|
|
info := topic.Matches[0].AdditionalScoreInfo()
|
|
if assert.NotNil(t, info) {
|
|
assert.EqualValues(t, &topicAdditionalScoreInfo{
|
|
Pre: "[aBx]",
|
|
Post: "(abcd)",
|
|
PenScore: "",
|
|
HalfScore: "0:0",
|
|
IsAET: false,
|
|
}, info)
|
|
}
|
|
}
|
|
|
|
topic, err = parseTopicPart("\x02\x033Last:\x03 a 0:0 b (0:0)\x02")
|
|
if assert.Nil(t, err) && assert.Len(t, topic.Matches, 1) {
|
|
info := topic.Matches[0].AdditionalScoreInfo()
|
|
if assert.NotNil(t, info) {
|
|
assert.EqualValues(t, &topicAdditionalScoreInfo{
|
|
Pre: "",
|
|
Post: "",
|
|
PenScore: "",
|
|
HalfScore: "0:0",
|
|
IsAET: false,
|
|
}, info)
|
|
}
|
|
}
|
|
|
|
topic, err = parseTopicPart("\x02\x033Last:\x03 a 0:0 b [P5:4] (0:0)\x02")
|
|
if assert.Nil(t, err) && assert.Len(t, topic.Matches, 1) {
|
|
info := topic.Matches[0].AdditionalScoreInfo()
|
|
if assert.NotNil(t, info) {
|
|
assert.EqualValues(t, &topicAdditionalScoreInfo{
|
|
Pre: "",
|
|
Post: "",
|
|
PenScore: "5:4",
|
|
HalfScore: "0:0",
|
|
IsAET: true,
|
|
}, info)
|
|
}
|
|
}
|
|
|
|
topic, err = parseTopicPart("\x02\x033Last:\x03 a 0:0 b [P 5:4] (0:0)\x02")
|
|
if assert.Nil(t, err) && assert.Len(t, topic.Matches, 1) {
|
|
info := topic.Matches[0].AdditionalScoreInfo()
|
|
if assert.NotNil(t, info) {
|
|
assert.EqualValues(t, &topicAdditionalScoreInfo{
|
|
Pre: "",
|
|
Post: "",
|
|
PenScore: "5:4",
|
|
HalfScore: "0:0",
|
|
IsAET: true,
|
|
}, info)
|
|
}
|
|
}
|
|
|
|
topic, err = parseTopicPart("\x02\x033Last:\x03 a 0:0 b [AET] (0:0)\x02")
|
|
if assert.Nil(t, err) && assert.Len(t, topic.Matches, 1) {
|
|
info := topic.Matches[0].AdditionalScoreInfo()
|
|
if assert.NotNil(t, info) {
|
|
assert.EqualValues(t, &topicAdditionalScoreInfo{
|
|
Pre: "",
|
|
Post: "",
|
|
PenScore: "",
|
|
HalfScore: "0:0",
|
|
IsAET: true,
|
|
}, info)
|
|
}
|
|
}
|
|
}
|