yt-gen-app/lib/lib_test.go

47 lines
1017 B
Go

package lib
import (
"testing"
"git.ymnuktech.ru/ymnuk/yt-gen-app/lib/templ"
"git.ymnuktech.ru/ymnuk/yt-gen-app/structs"
)
func TestFieldType(t *testing.T) {
if templ.FieldDBName(&structs.Field{Name: "Field"}) != "field" {
t.Fail()
}
if templ.FieldDBName(&structs.Field{Name: "Field_NAME"}) != "field_name" {
t.Fail()
}
if templ.FieldDBName(&structs.Field{Name: "fIELD_nAMe"}) != "field_name" {
t.Fail()
}
}
func TestDBModelAttrib(t *testing.T) {
str := templ.FieldDescript(&structs.Field{
Name: "Field_naME1",
Type: "int",
Description: "Hello world",
}, false)
if str != "`gorm:\"column:field_name1;type:INT;comment:Hello world\"`" {
t.Fail()
}
}
func TestVarNameUpper(t *testing.T) {
if str := templ.FieldNamePrepare("tile_server"); str != "TileServer" {
t.Error("Field name not equal")
return
}
}
func TestVarNameLower(t *testing.T) {
if str := templ.FieldNameLowerPrepare("TileServer"); str != "tile_server" {
t.Error("Field name not equal")
return
}
}