代码拉取完成,页面将自动刷新
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package trino
import "testing"
func TestSerial(t *testing.T) {
scenarios := []struct {
name string
value interface{}
expectedError bool
expectedSerial string
}{
{
name: "basic string",
value: "hello world",
expectedSerial: `'hello world'`,
},
{
name: "single quoted string",
value: "hello world's",
expectedSerial: `'hello world''s'`,
},
{
name: "double quoted string",
value: `hello "world"`,
expectedSerial: `'hello "world"'`,
},
{
name: "int8",
value: int8(100),
expectedSerial: "100",
},
{
name: "int16",
value: int16(100),
expectedSerial: "100",
},
{
name: "int32",
value: int32(100),
expectedSerial: "100",
},
{
name: "int",
value: int(100),
expectedSerial: "100",
},
{
name: "int64",
value: int64(100),
expectedSerial: "100",
},
{
name: "uint8",
value: uint8(100),
expectedError: true,
},
{
name: "uint16",
value: uint16(100),
expectedSerial: "100",
},
{
name: "uint32",
value: uint32(100),
expectedSerial: "100",
},
{
name: "uint",
value: uint(100),
expectedSerial: "100",
},
{
name: "uint64",
value: uint64(100),
expectedSerial: "100",
},
{
name: "byte",
value: byte('a'),
expectedError: true,
},
{
name: "valid Numeric",
value: Numeric("10"),
expectedSerial: "10",
},
{
name: "invalid Numeric",
value: Numeric("not-a-number"),
expectedError: true,
},
{
name: "bool true",
value: true,
expectedSerial: "true",
},
{
name: "bool false",
value: false,
expectedSerial: "false",
},
{
name: "nil",
value: nil,
expectedError: true,
},
{
name: "slice typed nil",
value: []interface{}(nil),
expectedError: true,
},
{
name: "valid slice",
value: []interface{}{1, 2},
expectedSerial: "ARRAY[1, 2]",
},
{
name: "valid empty",
value: []interface{}{},
expectedSerial: "ARRAY[]",
},
{
name: "invalid slice contents",
value: []interface{}{1, byte('a')},
expectedError: true,
},
}
for i := range scenarios {
scenario := scenarios[i]
t.Run(scenario.name, func(t *testing.T) {
s, err := Serial(scenario.value)
if err != nil {
if scenario.expectedError {
return
}
t.Fatal(err)
}
if scenario.expectedError {
t.Fatal("missing an expected error")
}
if scenario.expectedSerial != s {
t.Fatalf("mismatched serial, got %q expected %q", s, scenario.expectedSerial)
}
})
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。