2023-01-14 18:57:10 +03:00
|
|
|
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-07-30 22:41:10 +03:00
|
|
|
"github.com/stretchr/testify/require"
|
2023-01-14 18:57:10 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPackAndUnpackData(t *testing.T) {
|
|
|
|
s := "string"
|
|
|
|
i := int64(4)
|
|
|
|
f := float32(4.1)
|
|
|
|
|
|
|
|
var s2 string
|
|
|
|
var i2 int64
|
|
|
|
var f2 float32
|
|
|
|
|
|
|
|
data, err := PackData(s, i, f)
|
2024-07-30 22:41:10 +03:00
|
|
|
require.NoError(t, err)
|
2023-01-14 18:57:10 +03:00
|
|
|
|
2024-07-30 22:41:10 +03:00
|
|
|
require.NoError(t, UnpackData(data, &s2, &i2, &f2))
|
|
|
|
require.NoError(t, UnpackData(data, &s2))
|
|
|
|
require.Error(t, UnpackData(data, &i2))
|
|
|
|
require.Error(t, UnpackData(data, &s2, &f2))
|
2023-01-14 18:57:10 +03:00
|
|
|
}
|