Add more compatibility to is_not_empty()
This commit is contained in:
parent
458b1fc6e0
commit
48380cd8c3
2 changed files with 10 additions and 8 deletions
|
@ -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>()
|
||||
|
|
|
@ -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:
|
||||
# ⡴⠑⡄⠀⠀⠀⠀⠀⠀⠀ ⣀⣀⣤⣤⣤⣀⡀
|
||||
# ⠸⡇⠀⠿⡀⠀⠀⠀⣀⡴⢿⣿⣿⣿⣿⣿⣿⣿⣷⣦⡀
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue