From 60cf8f5eb1565cfbbc96197a597d19902850cb32 Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Mon, 15 Nov 2021 23:58:27 +0800 Subject: [PATCH] test(structure-hashx): add hashx range test --- pkg/structure/hashx/hashx_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pkg/structure/hashx/hashx_test.go b/pkg/structure/hashx/hashx_test.go index 8aa5eac..5913b13 100644 --- a/pkg/structure/hashx/hashx_test.go +++ b/pkg/structure/hashx/hashx_test.go @@ -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) +}