wp-go/cache/reload/reload_test.go

48 lines
912 B
Go
Raw Normal View History

2023-10-24 08:05:33 +00:00
package reload
import (
"fmt"
"testing"
)
func TestFlushMapVal(t *testing.T) {
t.Run("t1", func(t *testing.T) {
c := 0
v := GetAnyValMapBy("key", 2, struct{}{}, func(a struct{}) (int, bool) {
c++
return 33, true
2023-10-24 08:05:33 +00:00
})
fmt.Println(v)
DeleteMapVal("key", 2)
2023-10-24 08:05:33 +00:00
v = GetAnyValMapBy("key", 2, struct{}{}, func(a struct{}) (int, bool) {
2023-10-24 08:05:33 +00:00
fmt.Println("xxxxx")
return 33, true
2023-10-24 08:05:33 +00:00
})
fmt.Println(v)
FlushAnyVal("key")
v = GetAnyValMapBy[int, int, struct{}]("key", 2, struct{}{}, func(a struct{}) (int, bool) {
2023-10-24 08:05:33 +00:00
fmt.Println("yyyy")
return 33, true
2023-10-24 08:05:33 +00:00
})
fmt.Println(v)
})
}
func TestGetAnyMapFnBys(t *testing.T) {
var i int
t.Run("t1", func(t *testing.T) {
v := BuildMapFnWithConfirm[int]("name", func(a int) (int, bool) {
2023-10-24 08:05:33 +00:00
i++
return a + 1, true
2023-10-24 08:05:33 +00:00
})
vv := v(1, 2)
vvv := v(2, 3)
fmt.Println(vv, vvv)
v(1, 2)
DeleteMapVal("name", 2)
2023-10-24 08:05:33 +00:00
v(2, 3)
fmt.Println(i)
})
}