summaryrefslogtreecommitdiffstats
path: root/modules/gdscript/tests/scripts/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdscript/tests/scripts/runtime')
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/member_info.gd65
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/member_info.out6
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/metatypes.gd36
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/metatypes.notest.gd1
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/metatypes.out13
5 files changed, 59 insertions, 62 deletions
diff --git a/modules/gdscript/tests/scripts/runtime/features/member_info.gd b/modules/gdscript/tests/scripts/runtime/features/member_info.gd
index 50f840cef3..805ea42455 100644
--- a/modules/gdscript/tests/scripts/runtime/features/member_info.gd
+++ b/modules/gdscript/tests/scripts/runtime/features/member_info.gd
@@ -5,6 +5,8 @@ class MyClass:
enum MyEnum {}
+const Utils = preload("../../utils.notest.gd")
+
static var test_static_var_untyped
static var test_static_var_weak_null = null
static var test_static_var_weak_int = 1
@@ -58,68 +60,13 @@ func test():
var script: Script = get_script()
for property in script.get_property_list():
if str(property.name).begins_with("test_"):
- if not (property.usage & PROPERTY_USAGE_SCRIPT_VARIABLE):
- print("Error: Missing `PROPERTY_USAGE_SCRIPT_VARIABLE` flag.")
- print("static var ", property.name, ": ", get_type(property))
+ print(Utils.get_property_signature(property, true))
for property in get_property_list():
if str(property.name).begins_with("test_"):
- if not (property.usage & PROPERTY_USAGE_SCRIPT_VARIABLE):
- print("Error: Missing `PROPERTY_USAGE_SCRIPT_VARIABLE` flag.")
- print("var ", property.name, ": ", get_type(property))
+ print(Utils.get_property_signature(property))
for method in get_method_list():
if str(method.name).begins_with("test_"):
- print(get_signature(method))
+ print(Utils.get_method_signature(method))
for method in get_signal_list():
if str(method.name).begins_with("test_"):
- print(get_signature(method, true))
-
-func get_type(property: Dictionary, is_return: bool = false) -> String:
- match property.type:
- TYPE_NIL:
- if property.usage & PROPERTY_USAGE_NIL_IS_VARIANT:
- return "Variant"
- return "void" if is_return else "null"
- TYPE_BOOL:
- return "bool"
- TYPE_INT:
- if property.usage & PROPERTY_USAGE_CLASS_IS_ENUM:
- return property.class_name
- return "int"
- TYPE_STRING:
- return "String"
- TYPE_DICTIONARY:
- return "Dictionary"
- TYPE_ARRAY:
- if property.hint == PROPERTY_HINT_ARRAY_TYPE:
- return "Array[%s]" % property.hint_string
- return "Array"
- TYPE_OBJECT:
- if not str(property.class_name).is_empty():
- return property.class_name
- return "Object"
- return "<error>"
-
-func get_signature(method: Dictionary, is_signal: bool = false) -> String:
- var result: String = ""
- if method.flags & METHOD_FLAG_STATIC:
- result += "static "
- result += ("signal " if is_signal else "func ") + method.name + "("
-
- var args: Array[Dictionary] = method.args
- var default_args: Array = method.default_args
- var mandatory_argc: int = args.size() - default_args.size()
- for i in args.size():
- if i > 0:
- result += ", "
- var arg: Dictionary = args[i]
- result += arg.name + ": " + get_type(arg)
- if i >= mandatory_argc:
- result += " = " + var_to_str(default_args[i - mandatory_argc])
-
- result += ")"
- if is_signal:
- if get_type(method.return, true) != "void":
- print("Error: Signal return type must be `void`.")
- else:
- result += " -> " + get_type(method.return, true)
- return result
+ print(Utils.get_method_signature(method, true))
diff --git a/modules/gdscript/tests/scripts/runtime/features/member_info.out b/modules/gdscript/tests/scripts/runtime/features/member_info.out
index 7c826ac05a..3a91507da9 100644
--- a/modules/gdscript/tests/scripts/runtime/features/member_info.out
+++ b/modules/gdscript/tests/scripts/runtime/features/member_info.out
@@ -6,13 +6,13 @@ static var test_static_var_hard_int: int
var test_var_untyped: Variant
var test_var_weak_null: Variant
var test_var_weak_int: Variant
-var test_var_weak_int_exported: int
+@export var test_var_weak_int_exported: int
var test_var_weak_variant_type: Variant
-var test_var_weak_variant_type_exported: Variant.Type
+@export var test_var_weak_variant_type_exported: Variant.Type
var test_var_hard_variant: Variant
var test_var_hard_int: int
var test_var_hard_variant_type: Variant.Type
-var test_var_hard_variant_type_exported: Variant.Type
+@export var test_var_hard_variant_type_exported: Variant.Type
var test_var_hard_node_process_mode: Node.ProcessMode
var test_var_hard_my_enum: TestMemberInfo.MyEnum
var test_var_hard_array: Array
diff --git a/modules/gdscript/tests/scripts/runtime/features/metatypes.gd b/modules/gdscript/tests/scripts/runtime/features/metatypes.gd
new file mode 100644
index 0000000000..6c5df32ffe
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/metatypes.gd
@@ -0,0 +1,36 @@
+class MyClass:
+ const TEST = 10
+
+enum MyEnum {A, B, C}
+
+const Utils = preload("../../utils.notest.gd")
+const Other = preload("./metatypes.notest.gd")
+
+var test_native := JSON
+var test_script := Other
+var test_class := MyClass
+var test_enum := MyEnum
+
+func check_gdscript_native_class(value: Variant) -> void:
+ print(var_to_str(value).get_slice(",", 0).trim_prefix("Object("))
+
+func check_gdscript(value: GDScript) -> void:
+ print(value.get_class())
+
+func check_enum(value: Dictionary) -> void:
+ print(value)
+
+func test():
+ for property in get_property_list():
+ if str(property.name).begins_with("test_"):
+ print(Utils.get_property_signature(property))
+
+ check_gdscript_native_class(test_native)
+ check_gdscript(test_script)
+ check_gdscript(test_class)
+ check_enum(test_enum)
+
+ print(test_native.stringify([]))
+ print(test_script.TEST)
+ print(test_class.TEST)
+ print(test_enum.keys())
diff --git a/modules/gdscript/tests/scripts/runtime/features/metatypes.notest.gd b/modules/gdscript/tests/scripts/runtime/features/metatypes.notest.gd
new file mode 100644
index 0000000000..e6a591b927
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/metatypes.notest.gd
@@ -0,0 +1 @@
+const TEST = 100
diff --git a/modules/gdscript/tests/scripts/runtime/features/metatypes.out b/modules/gdscript/tests/scripts/runtime/features/metatypes.out
new file mode 100644
index 0000000000..352d1caa59
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/metatypes.out
@@ -0,0 +1,13 @@
+GDTEST_OK
+var test_native: GDScriptNativeClass
+var test_script: GDScript
+var test_class: GDScript
+var test_enum: Dictionary
+GDScriptNativeClass
+GDScript
+GDScript
+{ "A": 0, "B": 1, "C": 2 }
+[]
+100
+10
+["A", "B", "C"]