Skip to content

Commit

Permalink
add tests, make ptrs
Browse files Browse the repository at this point in the history
  • Loading branch information
pnxenopoulos committed Sep 2, 2023
1 parent 121d689 commit 04c8b22
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
14 changes: 7 additions & 7 deletions awpy/parser/parse_demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ type GameRound struct {
WinningTeam *string `json:"winningTeam"`
LosingTeam *string `json:"losingTeam"`
Reason string `json:"roundEndReason"`
MVPName string `json:"mvpName"`
MVPSteamID int64 `json:"mvpSteamID"`
MVPReason string `json:"mvpReason"`
MVPName *string `json:"mvpName"`
MVPSteamID *int64 `json:"mvpSteamID"`
MVPReason *string `json:"mvpReason"`
CTFreezeTimeEndEqVal int64 `json:"ctFreezeTimeEndEqVal"`
CTRoundStartEqVal int64 `json:"ctRoundStartEqVal"`
CTRoundMoneySpend int64 `json:"ctRoundSpendMoney"`
Expand Down Expand Up @@ -568,7 +568,7 @@ func convertRoundMVPReason(r events.RoundMVPReason) string {
case events.MVPReasonBombPlanted:
return "MVPReasonBombPlanted"
default:
return unknown
return "Unknown"
}
}

Expand Down Expand Up @@ -1486,9 +1486,9 @@ func registerRoundEndHandler(demoParser *dem.Parser, currentGame *Game, currentR
func registerRoundMVPHandler(demoParser *dem.Parser, currentRound *GameRound) {
(*demoParser).RegisterEventHandler(func(e events.RoundMVPAnnouncement) {
if e.Player != nil {
currentRound.MVPName = e.Player.Name
currentRound.MVPSteamID = int64(e.Player.SteamID64)
currentRound.MVPReason = convertRoundMVPReason(e.Reason)
currentRound.MVPName = *e.Player.Name
currentRound.MVPSteamID = *int64(e.Player.SteamID64)
currentRound.MVPReason = *convertRoundMVPReason(e.Reason)
}
})
}
Expand Down
14 changes: 14 additions & 0 deletions awpy/parser/parse_demo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,22 @@ import (
"testing"

common "github.com/markus-wa/demoinfocs-golang/v3/pkg/demoinfocs/common"
events "github.com/markus-wa/demoinfocs-golang/v3/pkg/demoinfocs/events"
)

func TestConvertRoundMVPReason(t *testing.T) {
t.Parallel()
enumReasons := [events.MVPReasonMostEliminations, events.MVPReasonBombDefused, events.MVPReasonBombPlanted]

Check failure on line 12 in awpy/parser/parse_demo_test.go

View workflow job for this annotation

GitHub Actions / build

unexpected comma; expecting ] (typecheck)
textReasons := []string{"MVPReasonMostEliminations", "MVPReasonBombDefused", "MVPReasonBombPlanted"}
for index, reason := enumReasons {

Check failure on line 14 in awpy/parser/parse_demo_test.go

View workflow job for this annotation

GitHub Actions / build

expected boolean or range expression, found assignment (missing parentheses around composite literal?) (typecheck)
is := convertRoundMVPReason(reason)
want := textReasons[index]
if is != want {
t.Errorf("Round MVP reason value of %v should convert to %v, got %v", reason, want, is)
}
}
}

func TestConvertRank(t *testing.T) {
t.Parallel()
var rankInt int
Expand Down

0 comments on commit 04c8b22

Please sign in to comment.