You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.8 KiB
Go
74 lines
1.8 KiB
Go
package handler
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestParseDefeatedLog(t *testing.T) {
|
|
tests := []struct {
|
|
msg string
|
|
matched bool
|
|
}{
|
|
{"Defeated Forest Wolf, gained 1 XP and 5 gold", true},
|
|
{"Encountered Forest Wolf", false},
|
|
{"Died fighting Forest Wolf", false},
|
|
{"Defeated a Forest Wolf", true},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
matched, _ := parseDefeatedLog(tt.msg)
|
|
if matched != tt.matched {
|
|
t.Errorf("parseDefeatedLog(%q) = %v, want %v", tt.msg, matched, tt.matched)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestParseGainsLog(t *testing.T) {
|
|
tests := []struct {
|
|
msg string
|
|
wantXP int64
|
|
wantGold int64
|
|
wantOK bool
|
|
}{
|
|
{"Defeated Forest Wolf, gained 1 XP and 5 gold", 1, 5, true},
|
|
{"Defeated Skeleton King, gained 3 XP and 10 gold", 3, 10, true},
|
|
{"Encountered Forest Wolf", 0, 0, false},
|
|
{"Died fighting Forest Wolf", 0, 0, false},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
xp, gold, ok := parseGainsLog(tt.msg)
|
|
if ok != tt.wantOK || xp != tt.wantXP || gold != tt.wantGold {
|
|
t.Errorf("parseGainsLog(%q) = (%d, %d, %v), want (%d, %d, %v)",
|
|
tt.msg, xp, gold, ok, tt.wantXP, tt.wantGold, tt.wantOK)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestIsLevelUpLog(t *testing.T) {
|
|
if !isLevelUpLog("Leveled up to 5!") {
|
|
t.Error("expected true for level-up log")
|
|
}
|
|
if isLevelUpLog("Defeated a wolf") {
|
|
t.Error("expected false for non-level-up log")
|
|
}
|
|
}
|
|
|
|
func TestIsDeathLog(t *testing.T) {
|
|
if !isDeathLog("Died fighting Forest Wolf") {
|
|
t.Error("expected true for death log")
|
|
}
|
|
if isDeathLog("Defeated Forest Wolf") {
|
|
t.Error("expected false for non-death log")
|
|
}
|
|
}
|
|
|
|
func TestIsPotionLog(t *testing.T) {
|
|
if !isPotionLog("Used healing potion, restored 30 HP") {
|
|
t.Error("expected true for potion log")
|
|
}
|
|
if isPotionLog("Defeated Forest Wolf") {
|
|
t.Error("expected false for non-potion log")
|
|
}
|
|
}
|