diff options
Diffstat (limited to 'modules/gdscript/tests')
11 files changed, 63 insertions, 0 deletions
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/gdscript_duplicate.gd b/modules/gdscript/tests/scripts/analyzer/errors/gdscript_duplicate.gd new file mode 100644 index 0000000000..966d2b0aa2 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/gdscript_duplicate.gd @@ -0,0 +1,5 @@ +const TestClass = preload("gdscript_duplicate_class.notest.gd") + +func test(): + # (TestClass as GDScript).duplicate() exists + TestClass.duplicate() diff --git a/modules/gdscript/tests/scripts/analyzer/errors/gdscript_duplicate.out b/modules/gdscript/tests/scripts/analyzer/errors/gdscript_duplicate.out new file mode 100644 index 0000000000..b2c7fec86e --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/gdscript_duplicate.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot call non-static function "duplicate()" on a class directly. Make an instance instead. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/gdscript_duplicate_class.notest.gd b/modules/gdscript/tests/scripts/analyzer/errors/gdscript_duplicate_class.notest.gd new file mode 100644 index 0000000000..61510e14cd --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/gdscript_duplicate_class.notest.gd @@ -0,0 +1 @@ +extends Node diff --git a/modules/gdscript/tests/scripts/analyzer/features/gdscript_duplicate.gd b/modules/gdscript/tests/scripts/analyzer/features/gdscript_duplicate.gd new file mode 100644 index 0000000000..030daf502c --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/gdscript_duplicate.gd @@ -0,0 +1,6 @@ +const TestClass = preload("gdscript_duplicate_class.notest.gd") + +func test(): + # TestClass.duplicate() fails + @warning_ignore("return_value_discarded") + (TestClass as GDScript).duplicate() diff --git a/modules/gdscript/tests/scripts/analyzer/features/gdscript_duplicate.out b/modules/gdscript/tests/scripts/analyzer/features/gdscript_duplicate.out new file mode 100644 index 0000000000..d73c5eb7cd --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/gdscript_duplicate.out @@ -0,0 +1 @@ +GDTEST_OK diff --git a/modules/gdscript/tests/scripts/analyzer/features/gdscript_duplicate_class.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/gdscript_duplicate_class.notest.gd new file mode 100644 index 0000000000..61510e14cd --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/gdscript_duplicate_class.notest.gd @@ -0,0 +1 @@ +extends Node diff --git a/modules/gdscript/tests/scripts/parser/features/super_class_check.gd b/modules/gdscript/tests/scripts/parser/features/super_class_check.gd new file mode 100644 index 0000000000..edfc45a8d8 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/super_class_check.gd @@ -0,0 +1,13 @@ +# https://github.com/godotengine/godot/issues/71994 + +func test(): + pass + +class A extends RefCounted: + pass + +class B extends A: + # Parsing `duplicate()` here would throw this error: + # Parse Error: The function signature doesn't match the parent. Parent signature is "duplicate(bool = default) -> Resource". + func duplicate(): + pass diff --git a/modules/gdscript/tests/scripts/parser/features/super_class_check.out b/modules/gdscript/tests/scripts/parser/features/super_class_check.out new file mode 100644 index 0000000000..d73c5eb7cd --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/super_class_check.out @@ -0,0 +1 @@ +GDTEST_OK diff --git a/modules/gdscript/tests/scripts/runtime/features/static_duplicate.gd b/modules/gdscript/tests/scripts/runtime/features/static_duplicate.gd new file mode 100644 index 0000000000..418501dcc5 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/static_duplicate.gd @@ -0,0 +1,19 @@ +const PreloadClass = preload("static_duplicate_preload.notest.gd") +const PreloadClassAlias = PreloadClass + +func test(): + var dup_preload_one = PreloadClass.duplicate() + print(dup_preload_one == Vector2.ONE) + + var dup_preload_two = (PreloadClass as GDScript).duplicate() + print(dup_preload_two is GDScript) + + var dup_preload_alias_one = PreloadClassAlias.duplicate() + print(dup_preload_alias_one == Vector2.ONE) + + var dup_preload_alias_two = (PreloadClassAlias as GDScript).duplicate() + print(dup_preload_alias_two is GDScript) + + var PreloadClassAsGDScript = PreloadClass as GDScript + var dup_preload_class_as_gdscript_one = PreloadClassAsGDScript.duplicate() + print(dup_preload_class_as_gdscript_one is GDScript) diff --git a/modules/gdscript/tests/scripts/runtime/features/static_duplicate.out b/modules/gdscript/tests/scripts/runtime/features/static_duplicate.out new file mode 100644 index 0000000000..34cd5c7652 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/static_duplicate.out @@ -0,0 +1,9 @@ +GDTEST_OK +preload duplicate +true +true +preload duplicate +true +true +preload duplicate +false diff --git a/modules/gdscript/tests/scripts/runtime/features/static_duplicate_preload.notest.gd b/modules/gdscript/tests/scripts/runtime/features/static_duplicate_preload.notest.gd new file mode 100644 index 0000000000..291ffc2c0b --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/static_duplicate_preload.notest.gd @@ -0,0 +1,5 @@ +extends RefCounted + +static func duplicate() -> Vector2: + print("preload duplicate") + return Vector2.ONE |