1 Star 0 Fork 0

lchjczw/swag

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
schema_test.go 2.02 KB
一键复制 编辑 原始数据 按行查看 历史
Bogdan U 提交于 2019-07-11 06:32 . chore: improve test coverage (#448)
package swag
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestValidDataType(t *testing.T) {
assert.NoError(t, CheckSchemaType("string"))
assert.NoError(t, CheckSchemaType("number"))
assert.NoError(t, CheckSchemaType("integer"))
assert.NoError(t, CheckSchemaType("boolean"))
assert.NoError(t, CheckSchemaType("array"))
assert.NoError(t, CheckSchemaType("object"))
assert.Error(t, CheckSchemaType("oops"))
}
func TestTransToValidSchemeType(t *testing.T) {
assert.Equal(t, TransToValidSchemeType("uint"), "integer")
assert.Equal(t, TransToValidSchemeType("uint32"), "integer")
assert.Equal(t, TransToValidSchemeType("uint64"), "integer")
assert.Equal(t, TransToValidSchemeType("float32"), "number")
assert.Equal(t, TransToValidSchemeType("bool"), "boolean")
assert.Equal(t, TransToValidSchemeType("string"), "string")
// should accept any type, due to user defined types
TransToValidSchemeType("oops")
}
func TestIsGolangPrimitiveType(t *testing.T) {
assert.Equal(t, IsGolangPrimitiveType("uint"), true)
assert.Equal(t, IsGolangPrimitiveType("int"), true)
assert.Equal(t, IsGolangPrimitiveType("uint8"), true)
assert.Equal(t, IsGolangPrimitiveType("uint16"), true)
assert.Equal(t, IsGolangPrimitiveType("int16"), true)
assert.Equal(t, IsGolangPrimitiveType("byte"), true)
assert.Equal(t, IsGolangPrimitiveType("uint32"), true)
assert.Equal(t, IsGolangPrimitiveType("int32"), true)
assert.Equal(t, IsGolangPrimitiveType("rune"), true)
assert.Equal(t, IsGolangPrimitiveType("uint64"), true)
assert.Equal(t, IsGolangPrimitiveType("int64"), true)
assert.Equal(t, IsGolangPrimitiveType("float32"), true)
assert.Equal(t, IsGolangPrimitiveType("float64"), true)
assert.Equal(t, IsGolangPrimitiveType("bool"), true)
assert.Equal(t, IsGolangPrimitiveType("string"), true)
assert.Equal(t, IsGolangPrimitiveType("oops"), false)
}
func TestIsNumericType(t *testing.T) {
assert.Equal(t, IsNumericType("integer"), true)
assert.Equal(t, IsNumericType("number"), true)
assert.Equal(t, IsNumericType("string"), false)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lchjczw/swag.git
git@gitee.com:lchjczw/swag.git
lchjczw
swag
swag
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385