mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-09-12 05:06:28 +00:00
60 lines
964 B
Go
60 lines
964 B
Go
package session
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/diamondburned/arikawa/gateway"
|
|
)
|
|
|
|
func TestReflect(t *testing.T) {
|
|
var results = make(chan string)
|
|
|
|
h, err := reflectFn(func(m *gateway.MessageCreateEvent) {
|
|
results <- m.Content
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
const result = "Hime Arikawa"
|
|
var msg = &gateway.MessageCreateEvent{
|
|
Content: result,
|
|
}
|
|
|
|
var msgV = reflect.ValueOf(msg)
|
|
var msgT = msgV.Type()
|
|
|
|
if h.not(msgT) {
|
|
t.Fatal("Event type mismatch")
|
|
}
|
|
|
|
go h.call(msgV)
|
|
|
|
if results := <-results; results != result {
|
|
t.Fatal("Unexpected results:", results)
|
|
}
|
|
}
|
|
|
|
func BenchmarkReflect(b *testing.B) {
|
|
h, err := reflectFn(func(m *gateway.MessageCreateEvent) {})
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
|
|
var msg = &gateway.MessageCreateEvent{}
|
|
|
|
b.ResetTimer()
|
|
|
|
for n := 0; n < b.N; n++ {
|
|
var msgV = reflect.ValueOf(msg)
|
|
var msgT = msgV.Type()
|
|
|
|
if h.not(msgT) {
|
|
b.Fatal("Event type mismatch")
|
|
}
|
|
|
|
h.call(msgV)
|
|
}
|
|
}
|