forked from markus-wa/demoinfocs-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples_test.go
50 lines (43 loc) · 952 Bytes
/
examples_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package demoinfocs_test
import (
"fmt"
"os"
"testing"
dem "github.com/markus-wa/demoinfocs-golang"
"github.com/markus-wa/demoinfocs-golang/events"
)
/*
This will print all kills of a demo in the format '[[killer]] <[[weapon]] [(HS)] [(WB)]> [[victim]]'
*/
//noinspection GoUnhandledErrorResult
func ExampleParser() {
f, err := os.Open("test/cs-demos/default.dem")
if err != nil {
panic(err)
}
defer f.Close()
p := dem.NewParser(f)
// Register handler on kill events
p.RegisterEventHandler(func(e events.Kill) {
var hs string
if e.IsHeadshot {
hs = " (HS)"
}
var wallBang string
if e.PenetratedObjects > 0 {
wallBang = " (WB)"
}
fmt.Printf("%s <%v%s%s> %s\n", e.Killer, e.Weapon, hs, wallBang, e.Victim)
})
// Parse to end
err = p.ParseToEnd()
if err != nil {
panic(err)
}
}
func TestExamplesWithoutOutput(t *testing.T) {
if testing.Short() {
t.Skip("skipping long running test")
}
ExampleParser()
}