test(value): add test value

This commit is contained in:
bandl 2021-09-25 16:22:33 +08:00
parent bcacc83df6
commit eb53a976e2
1 changed files with 32 additions and 0 deletions

View File

@ -84,3 +84,35 @@ func TestValue_InferValue(t *testing.T) {
require.NoError(t, err)
require.Equal(t, f, -1.2)
}
func TestValue_ChangeValue(t *testing.T) {
value := NewValue()
oldLen := value.GetLength()
chanageLen := value.ChangeValueLength(func() {
value.SetString("小葵花课堂开课了")
})
require.Equal(t, chanageLen, int64(value.GetLength()-oldLen))
lens := value.ChangeValueLength(func() {
value.SetInt(100)
})
require.Equal(t, lens, int64(-16))
lengs := value.ChangeValueLength(func() {
value.SetFloat64(9.99)
})
require.Equal(t, lengs, int64(0))
value = NewValue()
lengs = value.ChangeValueLength(func() {
value.SetFloat64(10.99)
})
require.Equal(t, lengs, int64(0))
value = NewValue()
value.SetString("909awdawdawd")
lengs = value.ChangeValueLength(func() {
value.SetString("9akjwbddddddddddddddddddddddddddddddddddddddddddddd")
})
require.Equal(t, lengs, int64(39))
}