diff options
Diffstat (limited to 'modules/gdscript/tests')
34 files changed, 919 insertions, 34 deletions
diff --git a/modules/gdscript/tests/gdscript_test_runner.h b/modules/gdscript/tests/gdscript_test_runner.h index 60b48c6a57..b1190604ad 100644 --- a/modules/gdscript/tests/gdscript_test_runner.h +++ b/modules/gdscript/tests/gdscript_test_runner.h @@ -32,6 +32,7 @@ #define GDSCRIPT_TEST_RUNNER_H #include "../gdscript.h" + #include "core/error/error_macros.h" #include "core/string/print_string.h" #include "core/string/ustring.h" diff --git a/modules/gdscript/tests/gdscript_test_runner_suite.h b/modules/gdscript/tests/gdscript_test_runner_suite.h index e27b6218f1..5fd7d942d2 100644 --- a/modules/gdscript/tests/gdscript_test_runner_suite.h +++ b/modules/gdscript/tests/gdscript_test_runner_suite.h @@ -32,6 +32,7 @@ #define GDSCRIPT_TEST_RUNNER_SUITE_H #include "gdscript_test_runner.h" + #include "tests/test_macros.h" namespace GDScriptTests { diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_var_export_annotation.gd b/modules/gdscript/tests/scripts/analyzer/errors/static_var_export_annotation.gd new file mode 100644 index 0000000000..66697cbb29 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/static_var_export_annotation.gd @@ -0,0 +1,8 @@ +# GH-77098 p.3 + +@static_unload + +@export static var a: int + +func test(): + pass diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_var_export_annotation.out b/modules/gdscript/tests/scripts/analyzer/errors/static_var_export_annotation.out new file mode 100644 index 0000000000..4111aa07af --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/static_var_export_annotation.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Annotation "@export" cannot be applied to a static variable. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/virtual_method_not_implemented.gd b/modules/gdscript/tests/scripts/analyzer/errors/virtual_method_not_implemented.gd new file mode 100644 index 0000000000..c34d927035 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/virtual_method_not_implemented.gd @@ -0,0 +1,2 @@ +func test(): + _get_property_list() diff --git a/modules/gdscript/tests/scripts/analyzer/errors/virtual_method_not_implemented.out b/modules/gdscript/tests/scripts/analyzer/errors/virtual_method_not_implemented.out new file mode 100644 index 0000000000..ce2f49a5e5 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/virtual_method_not_implemented.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot call virtual function "_get_property_list()" because it hasn't been defined. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/virtual_super_not_implemented.gd b/modules/gdscript/tests/scripts/analyzer/errors/virtual_super_not_implemented.gd new file mode 100644 index 0000000000..57dfffdbee --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/virtual_super_not_implemented.gd @@ -0,0 +1,5 @@ +func _init(): + super() + +func test(): + pass diff --git a/modules/gdscript/tests/scripts/analyzer/errors/virtual_super_not_implemented.out b/modules/gdscript/tests/scripts/analyzer/errors/virtual_super_not_implemented.out new file mode 100644 index 0000000000..e68759223c --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/virtual_super_not_implemented.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot call the parent class' virtual function "_init()" because it hasn't been defined. diff --git a/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.gd b/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.gd new file mode 100644 index 0000000000..73d0f9096c --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.gd @@ -0,0 +1,347 @@ +extends Resource + +signal foo + +func test(): + var x + # TYPE_NIL + x = null + prints("TYPE_NIL") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_BOOL + x = true + prints("TYPE_BOOL") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_INT + x = 1 + prints("TYPE_INT") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_FLOAT + x = 1.1 + prints("TYPE_FLOAT") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_STRING + x = "foo" + prints("TYPE_STRING") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_VECTOR2 + x = Vector2(1, 1) + prints("TYPE_VECTOR2") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_VECTOR2I + x = Vector2i(1, 1) + prints("TYPE_VECTOR2I") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_RECT2 + x = Rect2(1, 1, 1, 1) + prints("TYPE_RECT2") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_RECT2I + x = Rect2i(1, 1, 1, 1) + prints("TYPE_RECT2I") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_VECTOR3 + x = Vector3(1, 1, 1) + prints("TYPE_VECTOR3") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_VECTOR3I + x = Vector3i(1, 1, 1) + prints("TYPE_VECTOR3I") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_TRANSFORM2D + x = Transform2D.IDENTITY + prints("TYPE_TRANSFORM2D") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_VECTOR4 + x = Vector4(1, 1, 1, 1) + prints("TYPE_VECTOR4") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_VECTOR4I + x = Vector4i(1, 1, 1, 1) + prints("TYPE_VECTOR4I") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_PLANE + x = Plane.PLANE_XY + prints("TYPE_PLANE") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_QUATERNION + x = Quaternion.IDENTITY + prints("TYPE_QUATERNION") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_AABB + x = AABB(Vector3.ONE, Vector3.ONE) + prints("TYPE_AABB") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_BASIS + x = Basis.IDENTITY + prints("TYPE_BASIS") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_TRANSFORM3D + x = Transform3D.IDENTITY + prints("TYPE_TRANSFORM3D") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_PROJECTION + x = Projection.IDENTITY + prints("TYPE_PROJECTION") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_COLOR + x = Color.WHITE + prints("TYPE_COLOR") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_STRING_NAME + x = &"name" + prints("TYPE_STRING_NAME") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_NODE_PATH + x = ^"path" + prints("TYPE_NODE_PATH") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_RID + x = get_rid() + prints("TYPE_RID") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_OBJECT + x = self + prints("TYPE_OBJECT") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_CALLABLE + x = test + prints("TYPE_CALLABLE") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_SIGNAL + x = foo + prints("TYPE_SIGNAL") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_DICTIONARY + x = { a = 1} + prints("TYPE_DICTIONARY") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_ARRAY + x = [1] + prints("TYPE_ARRAY") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_PACKED_BYTE_ARRAY + x = PackedByteArray([1]) + prints("TYPE_PACKED_BYTE_ARRAY") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_PACKED_INT32_ARRAY + x = PackedInt32Array([1]) + prints("TYPE_PACKED_INT32_ARRAY") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_PACKED_INT64_ARRAY + x = PackedInt64Array([1]) + prints("TYPE_PACKED_INT64_ARRAY") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_PACKED_FLOAT32_ARRAY + x = PackedFloat32Array([1]) + prints("TYPE_PACKED_FLOAT32_ARRAY") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_PACKED_FLOAT64_ARRAY + x = PackedFloat64Array([1]) + prints("TYPE_PACKED_FLOAT64_ARRAY") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_PACKED_STRING_ARRAY + x = PackedStringArray(["1"]) + prints("TYPE_PACKED_STRING_ARRAY") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_PACKED_VECTOR2_ARRAY + x = PackedVector2Array([Vector2.ONE]) + prints("TYPE_PACKED_VECTOR2_ARRAY") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_PACKED_VECTOR3_ARRAY + x = PackedVector3Array([Vector3.ONE]) + prints("TYPE_PACKED_VECTOR3_ARRAY") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) + + # TYPE_PACKED_COLOR_ARRAY + x = PackedColorArray([Color.WHITE]) + prints("TYPE_PACKED_COLOR_ARRAY") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) diff --git a/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.out b/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.out new file mode 100644 index 0000000000..e2945c910a --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.out @@ -0,0 +1,229 @@ +GDTEST_OK +TYPE_NIL +true +false +false +false +true +TYPE_BOOL +false +false +true +true +true +TYPE_INT +false +false +true +true +true +TYPE_FLOAT +false +false +true +true +true +TYPE_STRING +false +false +true +true +true +TYPE_VECTOR2 +false +false +true +true +true +TYPE_VECTOR2I +false +false +true +true +true +TYPE_RECT2 +false +false +true +true +true +TYPE_RECT2I +false +false +true +true +true +TYPE_VECTOR3 +false +false +true +true +true +TYPE_VECTOR3I +false +false +true +true +true +TYPE_TRANSFORM2D +true +false +false +false +true +TYPE_VECTOR4 +false +false +true +true +true +TYPE_VECTOR4I +false +false +true +true +true +TYPE_PLANE +false +false +true +true +true +TYPE_QUATERNION +true +false +false +false +true +TYPE_AABB +false +false +true +true +true +TYPE_BASIS +true +false +false +false +true +TYPE_TRANSFORM3D +true +false +false +false +true +TYPE_PROJECTION +true +false +false +false +true +TYPE_COLOR +false +false +true +true +true +TYPE_STRING_NAME +false +false +true +true +true +TYPE_NODE_PATH +false +false +true +true +true +TYPE_RID +true +false +false +false +true +TYPE_OBJECT +false +false +true +true +true +TYPE_CALLABLE +false +false +true +true +true +TYPE_SIGNAL +false +false +true +true +true +TYPE_DICTIONARY +false +false +true +true +true +TYPE_ARRAY +false +false +true +true +true +TYPE_PACKED_BYTE_ARRAY +false +false +true +true +true +TYPE_PACKED_INT32_ARRAY +false +false +true +true +true +TYPE_PACKED_INT64_ARRAY +false +false +true +true +true +TYPE_PACKED_FLOAT32_ARRAY +false +false +true +true +true +TYPE_PACKED_FLOAT64_ARRAY +false +false +true +true +true +TYPE_PACKED_STRING_ARRAY +false +false +true +true +true +TYPE_PACKED_VECTOR2_ARRAY +false +false +true +true +true +TYPE_PACKED_VECTOR3_ARRAY +false +false +true +true +true +TYPE_PACKED_COLOR_ARRAY +false +false +true +true +true diff --git a/modules/gdscript/tests/scripts/analyzer/features/virtual_method_implemented.gd b/modules/gdscript/tests/scripts/analyzer/features/virtual_method_implemented.gd new file mode 100644 index 0000000000..1aacd1d11c --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/virtual_method_implemented.gd @@ -0,0 +1,11 @@ +class TestOne: + func _get_property_list(): + return {} + +class TestTwo extends TestOne: + func _init(): + var _x = _get_property_list() + +func test(): + var x = TestTwo.new() + var _x = x._get_property_list() diff --git a/modules/gdscript/tests/scripts/analyzer/features/virtual_method_implemented.out b/modules/gdscript/tests/scripts/analyzer/features/virtual_method_implemented.out new file mode 100644 index 0000000000..d73c5eb7cd --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/virtual_method_implemented.out @@ -0,0 +1 @@ +GDTEST_OK diff --git a/modules/gdscript/tests/scripts/analyzer/features/virtual_super_implemented.gd b/modules/gdscript/tests/scripts/analyzer/features/virtual_super_implemented.gd new file mode 100644 index 0000000000..c447003619 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/virtual_super_implemented.gd @@ -0,0 +1,10 @@ +class TestOne: + func _init(): + pass + +class TestTwo extends TestOne: + func _init(): + super() + +func test(): + pass diff --git a/modules/gdscript/tests/scripts/analyzer/features/virtual_super_implemented.out b/modules/gdscript/tests/scripts/analyzer/features/virtual_super_implemented.out new file mode 100644 index 0000000000..d73c5eb7cd --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/virtual_super_implemented.out @@ -0,0 +1 @@ +GDTEST_OK diff --git a/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators.gd b/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators.gd index 71a03fbc0d..f322783776 100644 --- a/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators.gd +++ b/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators.gd @@ -1,3 +1,3 @@ func test(): # Number separators may not be placed right next to each other. - var __ = 1__23 + var _num = 1__23 diff --git a/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators.out b/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators.out index 71a3c2fd6a..b308994ae2 100644 --- a/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators.out +++ b/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators.out @@ -1,2 +1,2 @@ GDTEST_PARSER_ERROR -Only one underscore can be used as a numeric separator. +Multiple underscores cannot be adjacent in a numeric literal. diff --git a/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators_after_decimal.gd b/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators_after_decimal.gd new file mode 100644 index 0000000000..3140999aa9 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators_after_decimal.gd @@ -0,0 +1,3 @@ +func test(): + # Number separators may not be placed right next to each other. + var _num = 123.45__67 diff --git a/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators_after_decimal.out b/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators_after_decimal.out new file mode 100644 index 0000000000..b308994ae2 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators_after_decimal.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +Multiple underscores cannot be adjacent in a numeric literal. diff --git a/modules/gdscript/tests/scripts/parser/features/number_literals_with_sign.gd b/modules/gdscript/tests/scripts/parser/features/number_literals_with_sign.gd new file mode 100644 index 0000000000..cf7fb1518c --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/number_literals_with_sign.gd @@ -0,0 +1,17 @@ +func test(): + print(-9223372036854775808 == (1 << 63)) + print(-2) + print(- 2) + print(---2) + print(3 - 2) + print(3-2) + print(3---2) + print(-3 - 2) + print(-3 - -2) + print(-(3 - 2)-2) + print([1, 2, 3][0]-1) + var t = 1 + print(t-1) + print(-0xFF) + print(1--0xFF) + print(floor(PI-1)) diff --git a/modules/gdscript/tests/scripts/parser/features/number_literals_with_sign.out b/modules/gdscript/tests/scripts/parser/features/number_literals_with_sign.out new file mode 100644 index 0000000000..c5958365ec --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/number_literals_with_sign.out @@ -0,0 +1,16 @@ +GDTEST_OK +true +-2 +-2 +-2 +1 +1 +1 +-5 +-1 +-3 +0 +0 +-255 +256 +2 diff --git a/modules/gdscript/tests/scripts/parser/features/number_separators.gd b/modules/gdscript/tests/scripts/parser/features/number_separators.gd index f5f5661cae..a534c4fde1 100644 --- a/modules/gdscript/tests/scripts/parser/features/number_separators.gd +++ b/modules/gdscript/tests/scripts/parser/features/number_separators.gd @@ -1,12 +1,26 @@ func test(): # `_` can be used as a separator for numbers in GDScript. # It can be placed anywhere in the number, except at the beginning. - # Currently, GDScript in the `master` branch only allows using one separator - # per number. - # Results are assigned to variables to avoid warnings. - var __ = 1_23 - __ = 123_ # Trailing number separators are OK. - __ = 12_3 - __ = 123_456 - __ = 0x1234_5678 - __ = 0b1001_0101 + print(1_23) + print(12_3) + print(1_2_3) + print(123_) # Trailing number separators are OK. + print(123_456) + print(123_45_6_) + print("---") + print(0x1234_00ff) + print(0x1234_00_f_f_) + print(0b1001_0101) + print(0b1001_01_0_1_) + print("---") + print(-1_234.456_7) + print(-1_23_4_.4_56_7_) + print(-1_234.) + print(-1_23_4_.) + print(.456_7) + print(.4_56_7_) + print("---") + print(-1_234.5e000_3) + print(-1_23_4_.5e0_00_3_) + print(-1_234.5e+000_3) + print(-1_23_4_.5e+0_00_3_) diff --git a/modules/gdscript/tests/scripts/parser/features/number_separators.out b/modules/gdscript/tests/scripts/parser/features/number_separators.out index d73c5eb7cd..b0d2fd94fe 100644 --- a/modules/gdscript/tests/scripts/parser/features/number_separators.out +++ b/modules/gdscript/tests/scripts/parser/features/number_separators.out @@ -1 +1,24 @@ GDTEST_OK +123 +123 +123 +123 +123456 +123456 +--- +305398015 +305398015 +149 +149 +--- +-1234.4567 +-1234.4567 +-1234 +-1234 +0.4567 +0.4567 +--- +-1234500 +-1234500 +-1234500 +-1234500 diff --git a/modules/gdscript/tests/scripts/runtime/features/ctor_as_callable.gd b/modules/gdscript/tests/scripts/runtime/features/ctor_as_callable.gd new file mode 100644 index 0000000000..515efbc9ce --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/ctor_as_callable.gd @@ -0,0 +1,10 @@ +# https://github.com/godotengine/godot/issues/70319 + +class InnerClass: + pass + +func test(): + var inner_ctor : Callable = InnerClass.new + print(inner_ctor) + var native_ctor : Callable = Node.new + print(native_ctor) diff --git a/modules/gdscript/tests/scripts/runtime/features/ctor_as_callable.out b/modules/gdscript/tests/scripts/runtime/features/ctor_as_callable.out new file mode 100644 index 0000000000..527e3e8f84 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/ctor_as_callable.out @@ -0,0 +1,3 @@ +GDTEST_OK +GDScript::new +GDScriptNativeClass::new diff --git a/modules/gdscript/tests/scripts/runtime/features/static_access_via_instance.gd b/modules/gdscript/tests/scripts/runtime/features/static_access_via_instance.gd new file mode 100644 index 0000000000..77d01cf00c --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/static_access_via_instance.gd @@ -0,0 +1,58 @@ +# GH-77098 p.4 + +@static_unload + +class A: + class InnerClass: + pass + + enum NamedEnum { VALUE = 111 } + enum { UNNAMED_ENUM_VALUE = 222 } + const CONSTANT = 333 + static var static_var := 1 + + static func static_func() -> int: + return 444 + +class B extends A: + func test_self(): + print(self.InnerClass is GDScript) + print(self.NamedEnum) + print(self.NamedEnum.VALUE) + print(self.UNNAMED_ENUM_VALUE) + print(self.CONSTANT) + @warning_ignore("static_called_on_instance") + print(self.static_func()) + + prints("test_self before:", self.static_var) + self.static_var = 2 + prints("test_self after:", self.static_var) + +func test(): + var hard := B.new() + hard.test_self() + + print(hard.InnerClass is GDScript) + print(hard.NamedEnum) + print(hard.NamedEnum.VALUE) + print(hard.UNNAMED_ENUM_VALUE) + print(hard.CONSTANT) + @warning_ignore("static_called_on_instance") + print(hard.static_func()) + + prints("hard before:", hard.static_var) + hard.static_var = 3 + prints("hard after:", hard.static_var) + + var weak: Variant = B.new() + print(weak.InnerClass is GDScript) + print(weak.NamedEnum) + print(weak.NamedEnum.VALUE) + print(weak.UNNAMED_ENUM_VALUE) + print(weak.CONSTANT) + @warning_ignore("unsafe_method_access") + print(weak.static_func()) + + prints("weak before:", weak.static_var) + weak.static_var = 4 + prints("weak after:", weak.static_var) diff --git a/modules/gdscript/tests/scripts/runtime/features/static_access_via_instance.out b/modules/gdscript/tests/scripts/runtime/features/static_access_via_instance.out new file mode 100644 index 0000000000..7d7ad04df4 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/static_access_via_instance.out @@ -0,0 +1,25 @@ +GDTEST_OK +true +{ "VALUE": 111 } +111 +222 +333 +444 +test_self before: 1 +test_self after: 2 +true +{ "VALUE": 111 } +111 +222 +333 +444 +hard before: 2 +hard after: 3 +true +{ "VALUE": 111 } +111 +222 +333 +444 +weak before: 3 +weak after: 4 diff --git a/modules/gdscript/tests/scripts/runtime/features/static_func_as_callable.gd b/modules/gdscript/tests/scripts/runtime/features/static_func_as_callable.gd new file mode 100644 index 0000000000..65635daa36 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/static_func_as_callable.gd @@ -0,0 +1,17 @@ +# GH-41919 + +class_name TestStaticFuncAsCallable + +class InnerClass: + static func inner_my_func(): + print("inner_my_func") + +static func my_func(): + print("my_func") + +var a: Callable = TestStaticFuncAsCallable.my_func +var b: Callable = InnerClass.inner_my_func + +func test(): + a.call() + b.call() diff --git a/modules/gdscript/tests/scripts/runtime/features/static_func_as_callable.out b/modules/gdscript/tests/scripts/runtime/features/static_func_as_callable.out new file mode 100644 index 0000000000..360bb9f322 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/static_func_as_callable.out @@ -0,0 +1,3 @@ +GDTEST_OK +my_func +inner_my_func diff --git a/modules/gdscript/tests/scripts/runtime/features/static_variables.gd b/modules/gdscript/tests/scripts/runtime/features/static_variables.gd index e193312381..8da8bb7e53 100644 --- a/modules/gdscript/tests/scripts/runtime/features/static_variables.gd +++ b/modules/gdscript/tests/scripts/runtime/features/static_variables.gd @@ -33,24 +33,24 @@ func test(): prints("perm:", perm) prints("prop:", prop) - print("other.perm:", StaticVariablesOther.perm) - print("other.prop:", StaticVariablesOther.prop) + prints("other.perm:", StaticVariablesOther.perm) + prints("other.prop:", StaticVariablesOther.prop) StaticVariablesOther.perm = 2 StaticVariablesOther.prop = "foo" - print("other.perm:", StaticVariablesOther.perm) - print("other.prop:", StaticVariablesOther.prop) + prints("other.perm:", StaticVariablesOther.perm) + prints("other.prop:", StaticVariablesOther.prop) @warning_ignore("unsafe_method_access") var path = get_script().get_path().get_base_dir() - var other = load(path + "/static_variables_load.gd") + var other = load(path + "/static_variables_load.gd") - print("load.perm:", other.perm) - print("load.prop:", other.prop) + prints("load.perm:", other.perm) + prints("load.prop:", other.prop) other.perm = 3 other.prop = "bar" - print("load.perm:", other.perm) - print("load.prop:", other.prop) + prints("load.perm:", other.perm) + prints("load.prop:", other.prop) diff --git a/modules/gdscript/tests/scripts/runtime/features/static_variables.out b/modules/gdscript/tests/scripts/runtime/features/static_variables.out index d2491aef5e..650e1d9578 100644 --- a/modules/gdscript/tests/scripts/runtime/features/static_variables.out +++ b/modules/gdscript/tests/scripts/runtime/features/static_variables.out @@ -3,14 +3,14 @@ Inner._static_init inner InnerInner._static_init inner inner data: data perm: 0 -prop: prefix Hello! suffix +prop: Hello! suffix perm: 1 prop: prefix World! suffix -other.perm:0 -other.prop:prefix Hello! suffix -other.perm:2 -other.prop:prefix foo suffix -load.perm:0 -load.prop:prefix Hello! suffix -load.perm:3 -load.prop:prefix bar suffix +other.perm: 0 +other.prop: Hello! suffix +other.perm: 2 +other.prop: prefix foo suffix +load.perm: 0 +load.prop: Hello! suffix +load.perm: 3 +load.prop: prefix bar suffix diff --git a/modules/gdscript/tests/scripts/runtime/features/static_variables_2.gd b/modules/gdscript/tests/scripts/runtime/features/static_variables_2.gd new file mode 100644 index 0000000000..7a75d119ed --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/static_variables_2.gd @@ -0,0 +1,56 @@ +@static_unload + +class A: + static var x: int = 1 + + static var y: int = 42: + set(_value): + print("The setter is NOT called on initialization.") # GH-77098 p.1 + + static func _static_init() -> void: + prints("A _static_init begin:", x) + x = -1 + prints("A _static_init end:", x) + + static func sf(p_x: int) -> void: + x = p_x + prints("sf:", x) + + # GH-77331 + func f(p_x: int) -> void: + x = p_x + prints("f:", x) + +class B extends A: + static func _static_init() -> void: + prints("B _static_init begin:", x) + x = -2 + prints("B _static_init end:", x) + + static func sg(p_x: int) -> void: + x = p_x + prints("sg:", x) + + func g(p_x: int) -> void: + x = p_x + prints("g:", x) + + func h(p_x: int) -> void: + print("h: call f(%d)" % p_x) + f(p_x) + +func test(): + prints(A.x, B.x) + A.x = 1 # GH-77098 p.2 + prints(A.x, B.x) + B.x = 2 + prints(A.x, B.x) + + A.sf(3) + B.sf(4) + B.sg(5) + + var b := B.new() + b.f(6) + b.g(7) + b.h(8) diff --git a/modules/gdscript/tests/scripts/runtime/features/static_variables_2.out b/modules/gdscript/tests/scripts/runtime/features/static_variables_2.out new file mode 100644 index 0000000000..b833911d95 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/static_variables_2.out @@ -0,0 +1,15 @@ +GDTEST_OK +A _static_init begin: 1 +A _static_init end: -1 +B _static_init begin: -1 +B _static_init end: -2 +-2 -2 +1 1 +2 2 +sf: 3 +sf: 4 +sg: 5 +f: 6 +g: 7 +h: call f(8) +f: 8 diff --git a/modules/gdscript/tests/test_gdscript.cpp b/modules/gdscript/tests/test_gdscript.cpp index ad38312abe..0446a7aad6 100644 --- a/modules/gdscript/tests/test_gdscript.cpp +++ b/modules/gdscript/tests/test_gdscript.cpp @@ -30,6 +30,11 @@ #include "test_gdscript.h" +#include "../gdscript_analyzer.h" +#include "../gdscript_compiler.h" +#include "../gdscript_parser.h" +#include "../gdscript_tokenizer.h" + #include "core/config/project_settings.h" #include "core/io/file_access.h" #include "core/io/file_access_pack.h" @@ -38,11 +43,6 @@ #include "core/string/string_builder.h" #include "scene/resources/packed_scene.h" -#include "modules/gdscript/gdscript_analyzer.h" -#include "modules/gdscript/gdscript_compiler.h" -#include "modules/gdscript/gdscript_parser.h" -#include "modules/gdscript/gdscript_tokenizer.h" - #ifdef TOOLS_ENABLED #include "editor/editor_settings.h" #endif diff --git a/modules/gdscript/tests/test_gdscript.h b/modules/gdscript/tests/test_gdscript.h index d719e3d94a..b39dfe2b5a 100644 --- a/modules/gdscript/tests/test_gdscript.h +++ b/modules/gdscript/tests/test_gdscript.h @@ -32,6 +32,7 @@ #define TEST_GDSCRIPT_H #include "gdscript_test_runner.h" + #include "tests/test_macros.h" namespace GDScriptTests { |
