test(structure-hashx): add hashx range test

This commit is contained in:
bandl 2021-11-15 23:58:27 +08:00
parent 594f8acf32
commit 60cf8f5eb1
1 changed files with 24 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package hashx
import (
"fmt"
"reflect"
"regexp"
"testing"
"unsafe"
@ -87,3 +88,26 @@ func string2bytes(s string) []byte {
}
return *(*[]byte)(unsafe.Pointer(&result))
}
func TestHashX_Range(t *testing.T) {
reComp := regexp.MustCompile("a.+")
require.True(t, reComp.MatchString("abbs"))
h := NewHashXSingle()
h.Set("abbs", "abbs")
h.Set("ppp", "ppp")
h.Set("accs", "accs")
result := h.Range(0, 3, "")
require.Len(t, result, 3)
result = h.Range(0, -1, "")
require.Len(t, result, 3)
result = h.Range(0, -1, "a.+")
require.Len(t, result, 2)
result = h.Range(1, -1, "a.+")
require.Len(t, result, 1)
}