From eb53a976e2e03a88ea226c6bd5275a03bca043bb Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Sat, 25 Sep 2021 16:22:33 +0800 Subject: [PATCH] test(value): add test value --- pkg/structure/value_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/pkg/structure/value_test.go b/pkg/structure/value_test.go index 4e660e6..71558b1 100644 --- a/pkg/structure/value_test.go +++ b/pkg/structure/value_test.go @@ -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)) +}