github.com/nutsdb/nutsdb@v1.0.4/utils_test.go (about) 1 // Copyright 2019 The nutsdb Author. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package nutsdb 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/assert" 21 ) 22 23 func TestMarshalInts(t *testing.T) { 24 assertions := assert.New(t) 25 data, err := MarshalInts([]int{}) 26 assertions.NoError(err, "TestMarshalInts") 27 28 ints, err := UnmarshalInts(data) 29 assertions.NoError(err, "TestMarshalInts") 30 assertions.Equal(0, len(ints), "TestMarshalInts") 31 32 data, err = MarshalInts([]int{1, 3}) 33 assertions.NoError(err, "TestMarshalInts") 34 35 ints, err = UnmarshalInts(data) 36 assertions.NoError(err, "TestMarshalInts") 37 assertions.Equal(2, len(ints), "TestMarshalInts") 38 assertions.Equal(1, ints[0], "TestMarshalInts") 39 assertions.Equal(3, ints[1], "TestMarshalInts") 40 } 41 42 func TestMatchForRange(t *testing.T) { 43 assertions := assert.New(t) 44 45 end, err := MatchForRange("*", "hello", func(key string) bool { 46 return true 47 }) 48 assertions.NoError(err, "TestMatchForRange") 49 assertions.False(end, "TestMatchForRange") 50 51 _, err = MatchForRange("[", "hello", func(key string) bool { 52 return true 53 }) 54 assertions.Error(err, "TestMatchForRange") 55 56 end, err = MatchForRange("*", "hello", func(key string) bool { 57 return false 58 }) 59 assertions.NoError(err, "TestMatchForRange") 60 assertions.True(end, "TestMatchForRange") 61 }