Compare commits

..

2 commits

2 changed files with 11 additions and 9 deletions

View file

@ -57,7 +57,7 @@ Matches a regular expression against `data`. \
Applies to **String** & **StringName**.
### *CoreValidationSingle* <u>is_not_empty</u>()
Ensures that `data` is not empty. \
Applies to **String** & **StringName** (`!= ""`), **int** (`!= 0`) and **float** (`!= 0.0`).
Applies to **String** & **StringName** (`!= ""`), **int** (`!= 0`), **float** (`!= 0.0`), **Array** (`!= []`) and **Dictionary** (`!= {}`).
### *CoreValidationSingle* <u>is_not_null</u>()
Ensures that `data` is not `null`.
### *CoreValidationSingle* <u>is_normalized</u>()

View file

@ -166,12 +166,14 @@ func evaluate() -> bool:
if !result: failures.append(core.stringify_variables("Data doesn't match regex %regex%", { "regex": rule["regex_string"] }))
CoreTypes.ValidationType.IS_NOT_EMPTY:
match(typeof(data)):
Variant.Type.TYPE_STRING: if data == "": failures.append("Data string is empty")
Variant.Type.TYPE_STRING_NAME: if data == "": failures.append("Data string name is empty")
Variant.Type.TYPE_INT: if data == 0: failures.append("Data integer is zero")
Variant.Type.TYPE_FLOAT: if data == 0.0: failures.append("Data float is zero")
# If not a String, StringName, int or float, skip
_: logger.warn("Can't determine if data is null as data is not of type String, StringName, int or float")
Variant.Type.TYPE_STRING: if data == "": failures.append("Data (String) is empty")
Variant.Type.TYPE_STRING_NAME: if data == "": failures.append("Data (StringName) is empty")
Variant.Type.TYPE_INT: if data == 0: failures.append("Data (int) is zero")
Variant.Type.TYPE_FLOAT: if data == 0.0: failures.append("Data (float) is zero")
Variant.Type.TYPE_ARRAY: if data == []: failures.append("Data (Array) is empty")
Variant.Type.TYPE_DICTIONARY: if data == {}: failures.append("Data (Dictionary) is empty")
# If not supported, skip
_: logger.warn("Can't determine if data is null as data is not of type String, StringName, int, float, Array or Dictionary")
CoreTypes.ValidationType.IS_NOT_NULL:
# ⡴⠑⡄⠀⠀⠀⠀⠀⠀⠀ ⣀⣀⣤⣤⣤⣀⡀
# ⠸⡇⠀⠿⡀⠀⠀⠀⣀⡴⢿⣿⣿⣿⣿⣿⣿⣿⣷⣦⡀
@ -221,7 +223,7 @@ func evaluate() -> bool:
# +++ types and classes +++
## Validates if [param data] matches some [enum Variant.Type].[br]
## Applies to all data types (obviously).
func matches_type(types: Array[Variant.Type]) -> CoreValidationSingle:
func matches_type(types: Array) -> CoreValidationSingle:
rules.append({ "type": CoreTypes.ValidationType.MATCHES_TYPE, "types": types })
return self
@ -289,7 +291,7 @@ func matches_regex(regex_string: String) -> CoreValidationSingle:
# +++ empty/null and booleans +++
## Ensures that [param data] is not empty.[br]
## Applies to [String] & [StringName] ([code]!= ""[/code]), [int] ([code]!= 0[/code]) and [float] ([code]!= 0.0[/code]).
## Applies to [String] & [StringName] ([code]!= ""[/code]), [int] ([code]!= 0[/code]), [float] ([code]!= 0.0[/code]), [Array] ([code]!= [][/code]) and [Dictionary] ([code]!= {}[/code]).
func is_not_empty() -> CoreValidationSingle:
rules.append({ "type": CoreTypes.ValidationType.IS_NOT_EMPTY })
return self