diff options
Diffstat (limited to 'modules/gdscript/tests/scripts/runtime/features')
18 files changed, 417 insertions, 1 deletions
diff --git a/modules/gdscript/tests/scripts/runtime/features/first_class_callable_and_signal.gd b/modules/gdscript/tests/scripts/runtime/features/first_class_callable_and_signal.gd new file mode 100644 index 0000000000..f17fb9823d --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/first_class_callable_and_signal.gd @@ -0,0 +1,14 @@ +# GH-80157 + +extends Node + +func f(): + pass + +signal s() + +func test(): + print(f) + print(s) + print(get_child) + print(ready) diff --git a/modules/gdscript/tests/scripts/runtime/features/first_class_callable_and_signal.out b/modules/gdscript/tests/scripts/runtime/features/first_class_callable_and_signal.out new file mode 100644 index 0000000000..e5e9ff7043 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/first_class_callable_and_signal.out @@ -0,0 +1,5 @@ +GDTEST_OK +Node::f +Node::[signal]s +Node::get_child +Node::[signal]ready diff --git a/modules/gdscript/tests/scripts/runtime/features/for_loop_iterator_specified_types.gd b/modules/gdscript/tests/scripts/runtime/features/for_loop_iterator_specified_types.gd new file mode 100644 index 0000000000..bc899a3a6f --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/for_loop_iterator_specified_types.gd @@ -0,0 +1,40 @@ +func test(): + print("Test range.") + for e: float in range(2, 5): + var elem := e + prints(var_to_str(e), var_to_str(elem)) + + print("Test int.") + for e: float in 3: + var elem := e + prints(var_to_str(e), var_to_str(elem)) + + print("Test untyped int array.") + var a1 := [10, 20, 30] + for e: float in a1: + var elem := e + prints(var_to_str(e), var_to_str(elem)) + + print("Test typed int array.") + var a2: Array[int] = [10, 20, 30] + for e: float in a2: + var elem := e + prints(var_to_str(e), var_to_str(elem)) + + # GH-82021 + print("Test implicitly typed array literal.") + for e: float in [100, 200, 300]: + var elem := e + prints(var_to_str(e), var_to_str(elem)) + + print("Test String-keys dictionary.") + var d1 := {a = 1, b = 2, c = 3} + for k: StringName in d1: + var key := k + prints(var_to_str(k), var_to_str(key)) + + print("Test RefCounted-keys dictionary.") + var d2 := {RefCounted.new(): 1, Resource.new(): 2, ConfigFile.new(): 3} + for k: RefCounted in d2: + var key := k + prints(k.get_class(), key.get_class()) diff --git a/modules/gdscript/tests/scripts/runtime/features/for_loop_iterator_specified_types.out b/modules/gdscript/tests/scripts/runtime/features/for_loop_iterator_specified_types.out new file mode 100644 index 0000000000..eeebdc4be5 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/for_loop_iterator_specified_types.out @@ -0,0 +1,29 @@ +GDTEST_OK +Test range. +2.0 2.0 +3.0 3.0 +4.0 4.0 +Test int. +0.0 0.0 +1.0 1.0 +2.0 2.0 +Test untyped int array. +10.0 10.0 +20.0 20.0 +30.0 30.0 +Test typed int array. +10.0 10.0 +20.0 20.0 +30.0 30.0 +Test implicitly typed array literal. +100.0 100.0 +200.0 200.0 +300.0 300.0 +Test String-keys dictionary. +&"a" &"a" +&"b" &"b" +&"c" &"c" +Test RefCounted-keys dictionary. +RefCounted RefCounted +Resource Resource +ConfigFile ConfigFile diff --git a/modules/gdscript/tests/scripts/runtime/features/match_with_pattern_guards.gd b/modules/gdscript/tests/scripts/runtime/features/match_with_pattern_guards.gd new file mode 100644 index 0000000000..4cb51f8512 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/match_with_pattern_guards.gd @@ -0,0 +1,71 @@ +var global := 0 + +func test(): + var a = 0 + var b = 1 + + match a: + 0 when b == 0: + print("does not run" if true else "") + 0 when b == 1: + print("guards work") + _: + print("does not run") + + match a: + var a_bind when b == 0: + prints("a is", a_bind, "and b is 0") + var a_bind when b == 1: + prints("a is", a_bind, "and b is 1") + _: + print("does not run") + + match a: + var a_bind when a_bind < 0: + print("a is less than zero") + var a_bind when a_bind == 0: + print("a is equal to zero") + _: + print("a is more than zero") + + match [1, 2, 3]: + [1, 2, var element] when element == 0: + print("does not run") + [1, 2, var element] when element == 3: + print("3rd element is 3") + + match a: + _ when b == 0: + print("does not run") + _ when b == 1: + print("works with wildcard too.") + _: + print("does not run") + + match a: + 0, 1 when b == 0: + print("does not run") + 0, 1 when b == 1: + print("guard with multiple patterns") + _: + print("does not run") + + match a: + 0 when b == 0: + print("does not run") + 0: + print("regular pattern after guard mismatch") + + match a: + 1 when side_effect(): + print("should not run the side effect call") + 0 when side_effect(): + print("will run the side effect call, but not this") + _: + assert(global == 1) + print("side effect only ran once") + +func side_effect(): + print("side effect") + global += 1 + return false diff --git a/modules/gdscript/tests/scripts/runtime/features/match_with_pattern_guards.out b/modules/gdscript/tests/scripts/runtime/features/match_with_pattern_guards.out new file mode 100644 index 0000000000..452d1ff4bf --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/match_with_pattern_guards.out @@ -0,0 +1,10 @@ +GDTEST_OK +guards work +a is 0 and b is 1 +a is equal to zero +3rd element is 3 +works with wildcard too. +guard with multiple patterns +regular pattern after guard mismatch +side effect +side effect only ran once diff --git a/modules/gdscript/tests/scripts/runtime/features/member_info.gd b/modules/gdscript/tests/scripts/runtime/features/member_info.gd new file mode 100644 index 0000000000..805ea42455 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/member_info.gd @@ -0,0 +1,72 @@ +class_name TestMemberInfo + +class MyClass: + pass + +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 +static var test_static_var_hard_int: int + +var test_var_untyped +var test_var_weak_null = null +var test_var_weak_int = 1 +@export var test_var_weak_int_exported = 1 +var test_var_weak_variant_type = TYPE_NIL +@export var test_var_weak_variant_type_exported = TYPE_NIL +var test_var_hard_variant: Variant +var test_var_hard_int: int +var test_var_hard_variant_type: 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: MyEnum +var test_var_hard_array: Array +var test_var_hard_array_int: Array[int] +var test_var_hard_array_variant_type: Array[Variant.Type] +var test_var_hard_array_node_process_mode: Array[Node.ProcessMode] +var test_var_hard_array_my_enum: Array[MyEnum] +var test_var_hard_array_resource: Array[Resource] +var test_var_hard_array_this: Array[TestMemberInfo] +var test_var_hard_array_my_class: Array[MyClass] +var test_var_hard_resource: Resource +var test_var_hard_this: TestMemberInfo +var test_var_hard_my_class: MyClass + +static func test_static_func(): pass + +func test_func_implicit_void(): pass +func test_func_explicit_void() -> void: pass +func test_func_weak_null(): return null +func test_func_weak_int(): return 1 +func test_func_hard_variant() -> Variant: return null +func test_func_hard_int() -> int: return 1 +func test_func_args_1(_a: int, _b: Array[int], _c: int = 1, _d = 2): pass +func test_func_args_2(_a = 1, _b = _a, _c = [2], _d = 3): pass + +signal test_signal_1() +signal test_signal_2(a: Variant, b) +signal test_signal_3(a: int, b: Array[int]) +signal test_signal_4(a: Variant.Type, b: Array[Variant.Type]) +signal test_signal_5(a: MyEnum, b: Array[MyEnum]) +signal test_signal_6(a: Resource, b: Array[Resource]) +signal test_signal_7(a: TestMemberInfo, b: Array[TestMemberInfo]) +signal test_signal_8(a: MyClass, b: Array[MyClass]) + +func test(): + var script: Script = get_script() + for property in script.get_property_list(): + if str(property.name).begins_with("test_"): + print(Utils.get_property_signature(property, true)) + for property in get_property_list(): + if str(property.name).begins_with("test_"): + print(Utils.get_property_signature(property)) + for method in get_method_list(): + if str(method.name).begins_with("test_"): + print(Utils.get_method_signature(method)) + for method in get_signal_list(): + if str(method.name).begins_with("test_"): + 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 new file mode 100644 index 0000000000..3a91507da9 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/member_info.out @@ -0,0 +1,45 @@ +GDTEST_OK +static var test_static_var_untyped: Variant +static var test_static_var_weak_null: Variant +static var test_static_var_weak_int: Variant +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 +@export var test_var_weak_int_exported: int +var test_var_weak_variant_type: Variant +@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 +@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 +var test_var_hard_array_int: Array[int] +var test_var_hard_array_variant_type: Array[Variant.Type] +var test_var_hard_array_node_process_mode: Array[Node.ProcessMode] +var test_var_hard_array_my_enum: Array[TestMemberInfo.MyEnum] +var test_var_hard_array_resource: Array[Resource] +var test_var_hard_array_this: Array[TestMemberInfo] +var test_var_hard_array_my_class: Array[RefCounted] +var test_var_hard_resource: Resource +var test_var_hard_this: TestMemberInfo +var test_var_hard_my_class: RefCounted +static func test_static_func() -> void +func test_func_implicit_void() -> void +func test_func_explicit_void() -> void +func test_func_weak_null() -> Variant +func test_func_weak_int() -> Variant +func test_func_hard_variant() -> Variant +func test_func_hard_int() -> int +func test_func_args_1(_a: int, _b: Array[int], _c: int = 1, _d: Variant = 2) -> void +func test_func_args_2(_a: Variant = 1, _b: Variant = null, _c: Variant = null, _d: Variant = 3) -> void +signal test_signal_1() +signal test_signal_2(a: Variant, b: Variant) +signal test_signal_3(a: int, b: Array[int]) +signal test_signal_4(a: Variant.Type, b: Array[Variant.Type]) +signal test_signal_5(a: TestMemberInfo.MyEnum, b: Array[TestMemberInfo.MyEnum]) +signal test_signal_6(a: Resource, b: Array[Resource]) +signal test_signal_7(a: TestMemberInfo, b: Array[TestMemberInfo]) +signal test_signal_8(a: RefCounted, b: Array[RefCounted]) diff --git a/modules/gdscript/tests/scripts/runtime/features/member_info_inheritance.gd b/modules/gdscript/tests/scripts/runtime/features/member_info_inheritance.gd new file mode 100644 index 0000000000..d0cbeeab85 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/member_info_inheritance.gd @@ -0,0 +1,45 @@ +# GH-82169 + +const Utils = preload("../../utils.notest.gd") + +class A: + static var test_static_var_a1 + static var test_static_var_a2 + var test_var_a1 + var test_var_a2 + static func test_static_func_a1(): pass + static func test_static_func_a2(): pass + func test_func_a1(): pass + func test_func_a2(): pass + signal test_signal_a1() + signal test_signal_a2() + +class B extends A: + static var test_static_var_b1 + static var test_static_var_b2 + var test_var_b1 + var test_var_b2 + static func test_static_func_b1(): pass + static func test_static_func_b2(): pass + func test_func_b1(): pass + func test_func_b2(): pass + signal test_signal_b1() + signal test_signal_b2() + +func test(): + var b := B.new() + for property in (B as GDScript).get_property_list(): + if str(property.name).begins_with("test_"): + print(Utils.get_property_signature(property, true)) + print("---") + for property in b.get_property_list(): + if str(property.name).begins_with("test_"): + print(Utils.get_property_signature(property)) + print("---") + for method in b.get_method_list(): + if str(method.name).begins_with("test_"): + print(Utils.get_method_signature(method)) + print("---") + for method in b.get_signal_list(): + if str(method.name).begins_with("test_"): + print(Utils.get_method_signature(method, true)) diff --git a/modules/gdscript/tests/scripts/runtime/features/member_info_inheritance.out b/modules/gdscript/tests/scripts/runtime/features/member_info_inheritance.out new file mode 100644 index 0000000000..f294b66ef9 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/member_info_inheritance.out @@ -0,0 +1,24 @@ +GDTEST_OK +static var test_static_var_a1: Variant +static var test_static_var_a2: Variant +static var test_static_var_b1: Variant +static var test_static_var_b2: Variant +--- +var test_var_b1: Variant +var test_var_b2: Variant +var test_var_a1: Variant +var test_var_a2: Variant +--- +static func test_static_func_b1() -> void +static func test_static_func_b2() -> void +func test_func_b1() -> void +func test_func_b2() -> void +static func test_static_func_a1() -> void +static func test_static_func_a2() -> void +func test_func_a1() -> void +func test_func_a2() -> void +--- +signal test_signal_b1() +signal test_signal_b2() +signal test_signal_a1() +signal test_signal_a2() 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"] diff --git a/modules/gdscript/tests/scripts/runtime/features/object_constructor.gd b/modules/gdscript/tests/scripts/runtime/features/object_constructor.gd new file mode 100644 index 0000000000..b875efef56 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/object_constructor.gd @@ -0,0 +1,6 @@ +# GH-73213 + +func test(): + var object := Object.new() # Not `Object()`. + print(object.get_class()) + object.free() diff --git a/modules/gdscript/tests/scripts/runtime/features/object_constructor.out b/modules/gdscript/tests/scripts/runtime/features/object_constructor.out new file mode 100644 index 0000000000..3673881576 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/object_constructor.out @@ -0,0 +1,2 @@ +GDTEST_OK +Object diff --git a/modules/gdscript/tests/scripts/runtime/features/standalone-calls-do-not-write-to-nil.gd b/modules/gdscript/tests/scripts/runtime/features/standalone-calls-do-not-write-to-nil.gd index 2f55059334..fd1460a48f 100644 --- a/modules/gdscript/tests/scripts/runtime/features/standalone-calls-do-not-write-to-nil.gd +++ b/modules/gdscript/tests/scripts/runtime/features/standalone-calls-do-not-write-to-nil.gd @@ -12,6 +12,7 @@ func test(): print("end") func test_construct(v, f): + @warning_ignore("unsafe_call_argument") Vector2(v, v) # Built-in type construct. assert(not f) # Test unary operator reading from `nil`. diff --git a/modules/gdscript/tests/scripts/runtime/features/static_variables.gd b/modules/gdscript/tests/scripts/runtime/features/static_variables.gd index 8da8bb7e53..7fa76ca4b0 100644 --- a/modules/gdscript/tests/scripts/runtime/features/static_variables.gd +++ b/modules/gdscript/tests/scripts/runtime/features/static_variables.gd @@ -44,6 +44,7 @@ func test(): @warning_ignore("unsafe_method_access") var path = get_script().get_path().get_base_dir() + @warning_ignore("unsafe_call_argument") var other = load(path + "/static_variables_load.gd") prints("load.perm:", other.perm) diff --git a/modules/gdscript/tests/scripts/runtime/features/stringify.gd b/modules/gdscript/tests/scripts/runtime/features/stringify.gd index fead2df854..1e66d8f34a 100644 --- a/modules/gdscript/tests/scripts/runtime/features/stringify.gd +++ b/modules/gdscript/tests/scripts/runtime/features/stringify.gd @@ -24,7 +24,8 @@ func test(): print(StringName("hello")) print(NodePath("hello/world")) var node := Node.new() - print(RID(node)) + @warning_ignore("unsafe_call_argument") + print(RID(node)) # TODO: Why is the constructor (or implicit cast) not documented? print(node.get_name) print(node.property_list_changed) node.free() |