2017-07-28 00:11:37 +02:00
|
|
|
package values
|
2017-07-06 05:25:03 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2017-07-21 22:26:04 +02:00
|
|
|
type testDrop struct{ proxy interface{} }
|
2017-07-06 05:25:03 +02:00
|
|
|
|
2017-07-21 22:26:04 +02:00
|
|
|
func (d testDrop) ToLiquid() interface{} { return d.proxy }
|
2017-07-06 05:25:03 +02:00
|
|
|
|
|
|
|
func TestToLiquid(t *testing.T) {
|
|
|
|
require.Equal(t, 2, ToLiquid(2))
|
2017-07-21 22:26:04 +02:00
|
|
|
require.Equal(t, 3, ToLiquid(testDrop{3}))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestValue_drop(t *testing.T) {
|
|
|
|
dv := ValueOf(testDrop{"seafood"})
|
|
|
|
require.Equal(t, "seafood", dv.Interface())
|
|
|
|
require.Equal(t, true, dv.Contains(ValueOf("foo")))
|
|
|
|
require.Equal(t, true, dv.Contains(ValueOf(testDrop{"foo"})))
|
|
|
|
require.Equal(t, 7, dv.PropertyValue(ValueOf("size")).Interface())
|
2017-07-06 05:25:03 +02:00
|
|
|
}
|
2017-08-03 15:11:14 +02:00
|
|
|
|
|
|
|
func TestDrop_Resolve_race(t *testing.T) {
|
|
|
|
d := ValueOf(testDrop{1})
|
|
|
|
values := make(chan int, 2)
|
|
|
|
for i := 0; i < 2; i++ {
|
|
|
|
go func() { values <- d.Int() }()
|
|
|
|
}
|
|
|
|
for i := 0; i < 2; i++ {
|
|
|
|
require.Equal(t, 1, <-values)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkDrop_Resolve_1(b *testing.B) {
|
|
|
|
d := ValueOf(testDrop{1})
|
|
|
|
for n := 0; n < b.N; n++ {
|
|
|
|
_ = d.Int()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkDrop_Resolve_2(b *testing.B) {
|
|
|
|
for n := 0; n < b.N; n++ {
|
|
|
|
d := ValueOf(testDrop{1})
|
|
|
|
_ = d.Int()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkDrop_Resolve_3(b *testing.B) {
|
|
|
|
for n := 0; n < b.N; n++ {
|
|
|
|
d := ValueOf(testDrop{1})
|
|
|
|
values := make(chan int, 10)
|
|
|
|
for i := cap(values); i > 0; i-- {
|
|
|
|
values <- d.Int()
|
|
|
|
}
|
|
|
|
for i := cap(values); i > 0; i-- {
|
2021-06-16 12:42:31 +02:00
|
|
|
//lint:ignore S1005 TODO look up how else to read the values
|
2017-08-03 15:11:14 +02:00
|
|
|
_ = <-values
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|