2020-05-06 06:15:25 +00:00
|
|
|
package infer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-10-28 22:39:59 +00:00
|
|
|
"github.com/diamondburned/arikawa/v2/discord"
|
2020-05-06 06:15:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type hasID struct {
|
2020-07-21 20:27:59 +00:00
|
|
|
ChannelID discord.ChannelID
|
2020-05-06 06:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type embedsID struct {
|
|
|
|
*hasID
|
|
|
|
*embedsID
|
|
|
|
}
|
|
|
|
|
|
|
|
type hasChannelInName struct {
|
2020-07-21 20:27:59 +00:00
|
|
|
ID discord.ChannelID
|
2020-05-06 06:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestReflectChannelID(t *testing.T) {
|
|
|
|
var s = &hasID{
|
|
|
|
ChannelID: 69420,
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("hasID", func(t *testing.T) {
|
|
|
|
if id := ChannelID(s); id != 69420 {
|
|
|
|
t.Fatal("unexpected channelID:", id)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("embedsID", func(t *testing.T) {
|
|
|
|
var e = &embedsID{
|
|
|
|
hasID: s,
|
|
|
|
}
|
|
|
|
|
|
|
|
if id := ChannelID(e); id != 69420 {
|
|
|
|
t.Fatal("unexpected channelID:", id)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("hasChannelInName", func(t *testing.T) {
|
|
|
|
var s = &hasChannelInName{
|
|
|
|
ID: 69420,
|
|
|
|
}
|
|
|
|
|
|
|
|
if id := ChannelID(s); id != 69420 {
|
|
|
|
t.Fatal("unexpected channelID:", id)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkReflectChannelID_1Level(b *testing.B) {
|
|
|
|
var s = &hasID{
|
|
|
|
ChannelID: 69420,
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
2020-05-11 01:45:42 +00:00
|
|
|
if id := ChannelID(s); id != s.ChannelID {
|
|
|
|
b.Fatal("Unexpected ChannelID:", id)
|
|
|
|
}
|
2020-05-06 06:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkReflectChannelID_5Level(b *testing.B) {
|
|
|
|
var s = &embedsID{
|
|
|
|
nil,
|
|
|
|
&embedsID{
|
|
|
|
nil,
|
|
|
|
&embedsID{
|
|
|
|
nil,
|
|
|
|
&embedsID{
|
|
|
|
hasID: &hasID{
|
|
|
|
ChannelID: 69420,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
2020-05-11 01:45:42 +00:00
|
|
|
if id := ChannelID(s); id != 69420 {
|
|
|
|
b.Fatal("Unexpected ChannelID:", id)
|
|
|
|
}
|
2020-05-06 06:15:25 +00:00
|
|
|
}
|
|
|
|
}
|