2023-06-26 15:35:24 +03:00
|
|
|
package lib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-07-26 16:19:28 +03:00
|
|
|
"git.ymnuktech.ru/ymnuk/yt-gen-app/lib/templ"
|
2023-06-26 15:35:24 +03:00
|
|
|
"git.ymnuktech.ru/ymnuk/yt-gen-app/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFieldType(t *testing.T) {
|
2023-07-26 16:19:28 +03:00
|
|
|
if templ.FieldDBName(&structs.Field{Name: "Field"}) != "field" {
|
2023-06-26 15:35:24 +03:00
|
|
|
t.Fail()
|
|
|
|
}
|
2023-07-26 16:19:28 +03:00
|
|
|
if templ.FieldDBName(&structs.Field{Name: "Field_NAME"}) != "field_name" {
|
2023-06-26 15:35:24 +03:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
2023-07-26 16:19:28 +03:00
|
|
|
if templ.FieldDBName(&structs.Field{Name: "fIELD_nAMe"}) != "field_name" {
|
2023-06-26 15:35:24 +03:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDBModelAttrib(t *testing.T) {
|
2023-07-26 16:19:28 +03:00
|
|
|
str := templ.FieldDescript(&structs.Field{
|
2023-06-26 15:35:24 +03:00
|
|
|
Name: "Field_naME1",
|
|
|
|
Type: "int",
|
|
|
|
Description: "Hello world",
|
2023-08-10 16:01:02 +03:00
|
|
|
}, false)
|
2023-06-26 15:35:24 +03:00
|
|
|
if str != "`gorm:\"column:field_name1;type:INT;comment:Hello world\"`" {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
2023-07-18 14:33:58 +03:00
|
|
|
|
|
|
|
func TestVarNameUpper(t *testing.T) {
|
2023-07-26 16:19:28 +03:00
|
|
|
if str := templ.FieldNamePrepare("tile_server"); str != "TileServer" {
|
2023-07-18 14:33:58 +03:00
|
|
|
t.Error("Field name not equal")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestVarNameLower(t *testing.T) {
|
2023-07-26 16:19:28 +03:00
|
|
|
if str := templ.FieldNameLowerPrepare("TileServer"); str != "tile_server" {
|
2023-07-18 14:33:58 +03:00
|
|
|
t.Error("Field name not equal")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|