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)) +}