test: add MyINFO parsing test cases
This commit is contained in:
parent
0a53963ec0
commit
11564b8c32
18
UserInfo.go
18
UserInfo.go
@ -62,24 +62,6 @@ func init() {
|
|||||||
|
|
||||||
rx_myinfo = regexp.MustCompile(HEAD + `([^<]*)<(.+?) V:([^,]+),M:(.),H:([0-9]+)/([0-9]+)/([0-9]+),S:([0-9]+)>` + FOOT)
|
rx_myinfo = regexp.MustCompile(HEAD + `([^<]*)<(.+?) V:([^,]+),M:(.),H:([0-9]+)/([0-9]+)/([0-9]+),S:([0-9]+)>` + FOOT)
|
||||||
rx_myinfo_notag = regexp.MustCompile(HEAD + `([^$]*)` + FOOT) // Fallback for no tag
|
rx_myinfo_notag = regexp.MustCompile(HEAD + `([^$]*)` + FOOT) // Fallback for no tag
|
||||||
|
|
||||||
/*
|
|
||||||
sample := ""
|
|
||||||
// sample = "$ALL Betty description<ApexDC++ V:1.4.3,M:P,H:9/0/2,S:1>$ $0.01\x01$xyz@xyz.com$53054999578$"
|
|
||||||
// sample = "$ALL ivysaur80 $P$10A$$0$"
|
|
||||||
// sample = "$ALL SHINY_IVYSAUR <ncdc V:1.19.1-12-g5561,M:P,H:1/0/0,S:10>$ $0.005Q$$0$"
|
|
||||||
// sample = "$ALL mappu desccccc<HexChat V:2.12.1,M:P,H:1/0/0,S:0>$ $p$$0$"
|
|
||||||
|
|
||||||
u := UserInfo{}
|
|
||||||
err := u.fromMyINFO(sample)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err.Error())
|
|
||||||
} else {
|
|
||||||
fmt.Printf("%+v\n", u)
|
|
||||||
}
|
|
||||||
|
|
||||||
panic("")
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUserInfo(username string) *UserInfo {
|
func NewUserInfo(username string) *UserInfo {
|
||||||
|
88
UserInfo_test.go
Normal file
88
UserInfo_test.go
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
package libnmdc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
type myInfoTestPair struct {
|
||||||
|
in string
|
||||||
|
expect UserInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMyINFOParse(t *testing.T) {
|
||||||
|
|
||||||
|
cases := []myInfoTestPair{
|
||||||
|
|
||||||
|
myInfoTestPair{
|
||||||
|
in: "$ALL Bxxxy description<ApexDC++ V:1.4.3,M:P,H:9/0/2,S:1>$ $0.01\x01$xyz@example.com$53054999578$",
|
||||||
|
expect: UserInfo{
|
||||||
|
Nick: "Bxxxy",
|
||||||
|
Description: "description",
|
||||||
|
ClientTag: "ApexDC++",
|
||||||
|
ClientVersion: "1.4.3",
|
||||||
|
Email: "xyz@example.com",
|
||||||
|
ShareSize: 53054999578,
|
||||||
|
ConnectionMode: CONNECTIONMODE_PASSIVE,
|
||||||
|
Flag: FLAG_NORMAL,
|
||||||
|
Slots: 1,
|
||||||
|
Speed: "0.0",
|
||||||
|
HubsUnregistered: 9,
|
||||||
|
HubsRegistered: 0,
|
||||||
|
HubsOperator: 2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
myInfoTestPair{
|
||||||
|
in: "$ALL ixxxxxxx0 $P$10A$$0$",
|
||||||
|
expect: UserInfo{
|
||||||
|
Nick: "ixxxxxxx0",
|
||||||
|
ClientVersion: "0", // Auto-inserted by the parser for short-format MyINFO strings
|
||||||
|
ConnectionMode: CONNECTIONMODE_PASSIVE,
|
||||||
|
Flag: UserFlag(rune('A')),
|
||||||
|
Speed: "1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
myInfoTestPair{
|
||||||
|
in: "$ALL SXXXX_XXXXXXR <ncdc V:1.19.1-12-g5561,M:P,H:1/0/0,S:10>$ $0.005Q$$0$",
|
||||||
|
expect: UserInfo{
|
||||||
|
Nick: "SXXXX_XXXXXXR",
|
||||||
|
ClientTag: "ncdc",
|
||||||
|
ClientVersion: "1.19.1-12-g5561",
|
||||||
|
ConnectionMode: CONNECTIONMODE_PASSIVE,
|
||||||
|
Flag: UserFlag(rune('Q')),
|
||||||
|
Slots: 10,
|
||||||
|
Speed: "0.00",
|
||||||
|
HubsUnregistered: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
myInfoTestPair{
|
||||||
|
in: "$ALL mxxxu desccccc<HexChat V:2.12.1,M:P,H:1/0/0,S:0>$ $p$$0$",
|
||||||
|
expect: UserInfo{
|
||||||
|
Nick: "mxxxu",
|
||||||
|
Description: "desccccc",
|
||||||
|
ClientTag: "HexChat",
|
||||||
|
ClientVersion: "2.12.1",
|
||||||
|
ConnectionMode: CONNECTIONMODE_PASSIVE,
|
||||||
|
Flag: UserFlag(rune('p')),
|
||||||
|
HubsUnregistered: 1,
|
||||||
|
Slots: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range cases {
|
||||||
|
|
||||||
|
got := UserInfo{}
|
||||||
|
err := got.fromMyINFO(v.in)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("MyINFO parse warning (%s)", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if got != v.expect {
|
||||||
|
t.Errorf("MyINFO parse failure\nExpected:\n%+v\nGot:\n%+v\n", v.expect, got)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user