1 Star 0 Fork 0

github_repo/trino-golang-client

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
serial_test.go 3.52 KB
一键复制 编辑 原始数据 按行查看 历史
painsOnline 提交于 2022-01-06 17:51 +08:00 . Add files via upload
// 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)
}
})
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/github_repo/trino-golang-client.git
git@gitee.com:github_repo/trino-golang-client.git
github_repo
trino-golang-client
trino-golang-client
main

搜索帮助