import options, unittest, uuids from langutils import sameContents import ../../../main/nim/personal_measure_apipkg/db_util type TestModel = object id*: int name*: string uuid*: UUID nullableBool: Option[bool] ValBox = object id*: int val*: string suite "db_util": let testModel1 = TestModel( id: 1, name: "Test", uuid: parseUUID("db62c4a8-0091-42de-980c-edce4312aabb"), nullableBool: none[bool]()) test "modelName(type)": check modelName(TestModel) == "TestModel" test "modelName(object)": check modelName(testModel1) == "TestModel" test "identNameToDb": check: identNameToDb("TestModel") == "test_model" identNameToDb("Test_This") == "test_this" identNameToDb("getApiTrigger") == "get_api_trigger" identNameToDb("_HOLD_THIS_") == "_hold_this_" identNameToDb("__camelCAse") == "__camel_case" test "dbNameToIdent": check: dbNameToIdent("test_model") == "testModel" dbNameToIdent("test_this") == "testThis" dbNameToIdent("get_api_trigger") == "getApiTrigger" dbNameToIdent("_hold_this_") == "HoldThis" dbNameToIdent("__camel_case") == "CamelCase" test "tableName(type)": check: tableName(TestModel) == "test_models" tableName(ValBox) == "val_boxs" # NOTE lack of support currently for other pluralizations test "tableName(type)": check: tableName(testModel1) == "test_models" tableName(ValBox(id: 1, val: "test")) == "val_boxs" # NOTE lack of support currently for other pluralizations test "dbFormat(string)": check: dbFormat("123") == "123" dbFormat("this is a string") == "this is a string" dbFormat("should preserve\t all \n characters \\") == "should preserve\t all \n characters \\" test "dbFormat(seq[T])": let names = @["Bob", "Sam", "Jones"] let ages = @[35, 42, 18] check: dbFormat(names) == "{Bob,Sam,Jones}" dbFormat(ages) == "{35,42,18}" test "parseDbArray": check: sameContents(parseDbArray("{1,2,3}"), @["1", "2", "3"]) sameContents(parseDbArray("{\"1,2\",3}"), @["1,2", "3"]) sameContents(parseDbArray("{test,\"this\"}"), @["test", "this"]) sameContents(parseDbArray("{test,\"th,is\"}"), @["test", "th,is"]) sameContents(parseDbArray("{test,\"th,\\\"is\"}"), @["test", "th,\"is"]) sameContents(parseDbArray("{test,\"th,\\\"is\",\"what?\"}"), @["test", "th,\"is", "what?"]) sameContents(parseDbArray("{\"find,st\\\"uff\",ov\\\"er, there, \"\", \"what?\"}"), @["find,st\"uff", "ov\"er", "there", "", "what?"]) test "columnNamesForModel": check: sameContents(columnNamesForModel(TestModel), @["id", "name", "uuid", "nullable_bool"]) sameContents(columnNamesForModel(ValBox), @["id", "val"]) #[ TODO - Tests needed test "dbFormat(DateTime)": check false test "rowToModel" check false ]#