From b5d37fdbb11af7f39505cb452363d0d95bb22f93 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Sat, 11 May 2024 02:40:26 +0200 Subject: [PATCH] Update to 48380cd8c33172e3aeee310e14e9ee622b31d551 --- src/classes/validationsingle.gd | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/classes/validationsingle.gd b/src/classes/validationsingle.gd index 49a4d0c..5bc337b 100644 --- a/src/classes/validationsingle.gd +++ b/src/classes/validationsingle.gd @@ -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