diff options
Diffstat (limited to 'modules/gdscript/tests')
73 files changed, 658 insertions, 67 deletions
| diff --git a/modules/gdscript/tests/gdscript_test_runner.cpp b/modules/gdscript/tests/gdscript_test_runner.cpp index c2bb2caa29..6c346acb7e 100644 --- a/modules/gdscript/tests/gdscript_test_runner.cpp +++ b/modules/gdscript/tests/gdscript_test_runner.cpp @@ -36,6 +36,7 @@  #include "../gdscript_parser.h"  #include "core/config/project_settings.h" +#include "core/core_globals.h"  #include "core/core_string_names.h"  #include "core/io/dir_access.h"  #include "core/io/file_access_pack.h" @@ -48,11 +49,11 @@  namespace GDScriptTests {  void init_autoloads() { -	OrderedHashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list(); +	HashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();  	// First pass, add the constants so they exist before any script is loaded. -	for (OrderedHashMap<StringName, ProjectSettings::AutoloadInfo>::Element E = autoloads.front(); E; E = E.next()) { -		const ProjectSettings::AutoloadInfo &info = E.get(); +	for (const KeyValue<StringName, ProjectSettings::AutoloadInfo> &E : ProjectSettings::get_singleton()->get_autoload_list()) { +		const ProjectSettings::AutoloadInfo &info = E.value;  		if (info.is_singleton) {  			for (int i = 0; i < ScriptServer::get_language_count(); i++) { @@ -62,15 +63,15 @@ void init_autoloads() {  	}  	// Second pass, load into global constants. -	for (OrderedHashMap<StringName, ProjectSettings::AutoloadInfo>::Element E = autoloads.front(); E; E = E.next()) { -		const ProjectSettings::AutoloadInfo &info = E.get(); +	for (const KeyValue<StringName, ProjectSettings::AutoloadInfo> &E : ProjectSettings::get_singleton()->get_autoload_list()) { +		const ProjectSettings::AutoloadInfo &info = E.value;  		if (!info.is_singleton) {  			// Skip non-singletons since we don't have a scene tree here anyway.  			continue;  		} -		RES res = ResourceLoader::load(info.path); +		Ref<Resource> res = ResourceLoader::load(info.path);  		ERR_CONTINUE_MSG(res.is_null(), "Can't autoload: " + info.path);  		Node *n = nullptr;  		Ref<PackedScene> scn = res; @@ -80,7 +81,7 @@ void init_autoloads() {  		} else if (script.is_valid()) {  			StringName ibt = script->get_instance_base_type();  			bool valid_type = ClassDB::is_parent_class(ibt, "Node"); -			ERR_CONTINUE_MSG(!valid_type, "Script does not inherit a Node: " + info.path); +			ERR_CONTINUE_MSG(!valid_type, "Script does not inherit from Node: " + info.path);  			Object *obj = ClassDB::instantiate(ibt); @@ -142,8 +143,8 @@ GDScriptTestRunner::GDScriptTestRunner(const String &p_source_dir, bool p_init_l  #endif  	// Enable printing to show results -	_print_line_enabled = true; -	_print_error_enabled = true; +	CoreGlobals::print_line_enabled = true; +	CoreGlobals::print_error_enabled = true;  }  GDScriptTestRunner::~GDScriptTestRunner() { @@ -229,7 +230,7 @@ bool GDScriptTestRunner::generate_outputs() {  bool GDScriptTestRunner::make_tests_for_dir(const String &p_dir) {  	Error err = OK; -	DirAccessRef dir(DirAccess::open(p_dir, &err)); +	Ref<DirAccess> dir(DirAccess::open(p_dir, &err));  	if (err != OK) {  		return false; @@ -246,7 +247,7 @@ bool GDScriptTestRunner::make_tests_for_dir(const String &p_dir) {  				next = dir->get_next();  				continue;  			} -			if (!make_tests_for_dir(current_dir.plus_file(next))) { +			if (!make_tests_for_dir(current_dir.path_join(next))) {  				return false;  			}  		} else { @@ -254,7 +255,7 @@ bool GDScriptTestRunner::make_tests_for_dir(const String &p_dir) {  #ifndef DEBUG_ENABLED  				// On release builds, skip tests marked as debug only.  				Error open_err = OK; -				FileAccessRef script_file(FileAccess::open(current_dir.plus_file(next), FileAccess::READ, &open_err)); +				Ref<FileAccess> script_file(FileAccess::open(current_dir.path_join(next), FileAccess::READ, &open_err));  				if (open_err != OK) {  					ERR_PRINT(vformat(R"(Couldn't open test file "%s".)", next));  					next = dir->get_next(); @@ -271,7 +272,7 @@ bool GDScriptTestRunner::make_tests_for_dir(const String &p_dir) {  				if (!is_generating && !dir->file_exists(out_file)) {  					ERR_FAIL_V_MSG(false, "Could not find output file for " + next);  				} -				GDScriptTest test(current_dir.plus_file(next), current_dir.plus_file(out_file), source_dir); +				GDScriptTest test(current_dir.path_join(next), current_dir.path_join(out_file), source_dir);  				tests.push_back(test);  			}  		} @@ -286,7 +287,7 @@ bool GDScriptTestRunner::make_tests_for_dir(const String &p_dir) {  bool GDScriptTestRunner::make_tests() {  	Error err = OK; -	DirAccessRef dir(DirAccess::open(source_dir, &err)); +	Ref<DirAccess> dir(DirAccess::open(source_dir, &err));  	ERR_FAIL_COND_V_MSG(err != OK, false, "Could not open specified test directory."); @@ -363,7 +364,7 @@ void GDScriptTest::disable_stdout() {  	OS::get_singleton()->set_stderr_enabled(false);  } -void GDScriptTest::print_handler(void *p_this, const String &p_message, bool p_error) { +void GDScriptTest::print_handler(void *p_this, const String &p_message, bool p_error, bool p_rich) {  	TestResult *result = (TestResult *)p_this;  	result->output += p_message + "\n";  } @@ -543,8 +544,8 @@ GDScriptTest::TestResult GDScriptTest::execute_test_code(bool p_is_generating) {  		return result;  	}  	// Test running. -	const Map<StringName, GDScriptFunction *>::Element *test_function_element = script->get_member_functions().find(GDScriptTestRunner::test_function_name); -	if (test_function_element == nullptr) { +	const HashMap<StringName, GDScriptFunction *>::ConstIterator test_function_element = script->get_member_functions().find(GDScriptTestRunner::test_function_name); +	if (!test_function_element) {  		enable_stdout();  		result.status = GDTEST_LOAD_ERROR;  		result.output = ""; @@ -573,7 +574,7 @@ GDScriptTest::TestResult GDScriptTest::execute_test_code(bool p_is_generating) {  	// Call test function.  	Callable::CallError call_err; -	instance->call(GDScriptTestRunner::test_function_name, nullptr, 0, call_err); +	instance->callp(GDScriptTestRunner::test_function_name, nullptr, 0, call_err);  	// Tear down output handlers.  	remove_print_handler(&_print_handler); @@ -611,7 +612,7 @@ bool GDScriptTest::generate_output() {  	}  	Error err = OK; -	FileAccessRef out_file = FileAccess::open(output_file, FileAccess::WRITE, &err); +	Ref<FileAccess> out_file = FileAccess::open(output_file, FileAccess::WRITE, &err);  	if (err != OK) {  		return false;  	} @@ -620,7 +621,6 @@ bool GDScriptTest::generate_output() {  	output += "\n"; // Make sure to insert newline for CI static checks.  	out_file->store_string(output); -	out_file->close();  	return true;  } diff --git a/modules/gdscript/tests/gdscript_test_runner.h b/modules/gdscript/tests/gdscript_test_runner.h index 1a950c6898..033d2fcad1 100644 --- a/modules/gdscript/tests/gdscript_test_runner.h +++ b/modules/gdscript/tests/gdscript_test_runner.h @@ -28,8 +28,8 @@  /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */  /*************************************************************************/ -#ifndef GDSCRIPT_TEST_H -#define GDSCRIPT_TEST_H +#ifndef GDSCRIPT_TEST_RUNNER_H +#define GDSCRIPT_TEST_RUNNER_H  #include "../gdscript.h"  #include "core/error/error_macros.h" @@ -63,8 +63,8 @@ public:  private:  	struct ErrorHandlerData { -		TestResult *result; -		GDScriptTest *self; +		TestResult *result = nullptr; +		GDScriptTest *self = nullptr;  		ErrorHandlerData(TestResult *p_result, GDScriptTest *p_this) {  			result = p_result;  			self = p_this; @@ -86,7 +86,7 @@ private:  	TestResult execute_test_code(bool p_is_generating);  public: -	static void print_handler(void *p_this, const String &p_message, bool p_error); +	static void print_handler(void *p_this, const String &p_message, bool p_error, bool p_rich);  	static void error_handler(void *p_this, const char *p_function, const char *p_file, int p_line, const char *p_error, const char *p_explanation, bool p_editor_notify, ErrorHandlerType p_type);  	TestResult run_test();  	bool generate_output(); @@ -123,4 +123,4 @@ public:  } // namespace GDScriptTests -#endif // GDSCRIPT_TEST_H +#endif // GDSCRIPT_TEST_RUNNER_H diff --git a/modules/gdscript/tests/gdscript_test_runner_suite.h b/modules/gdscript/tests/gdscript_test_runner_suite.h index 0722fb800e..90f6d7f7e8 100644 --- a/modules/gdscript/tests/gdscript_test_runner_suite.h +++ b/modules/gdscript/tests/gdscript_test_runner_suite.h @@ -69,6 +69,40 @@ func _init():  	CHECK_MESSAGE(int(ref_counted->get_meta("result")) == 42, "The script should assign object metadata successfully.");  } +TEST_CASE("[Modules][GDScript] Validate built-in API") { +	GDScriptLanguage *lang = GDScriptLanguage::get_singleton(); + +	// Validate methods. +	List<MethodInfo> builtin_methods; +	lang->get_public_functions(&builtin_methods); + +	SUBCASE("[Modules][GDScript] Validate built-in methods") { +		for (const MethodInfo &mi : builtin_methods) { +			for (int j = 0; j < mi.arguments.size(); j++) { +				PropertyInfo arg = mi.arguments[j]; + +				TEST_COND((arg.name.is_empty() || arg.name.begins_with("_unnamed_arg")), +						vformat("Unnamed argument in position %d of built-in method '%s'.", j, mi.name)); +			} +		} +	} + +	// Validate annotations. +	List<MethodInfo> builtin_annotations; +	lang->get_public_annotations(&builtin_annotations); + +	SUBCASE("[Modules][GDScript] Validate built-in annotations") { +		for (const MethodInfo &ai : builtin_annotations) { +			for (int j = 0; j < ai.arguments.size(); j++) { +				PropertyInfo arg = ai.arguments[j]; + +				TEST_COND((arg.name.is_empty() || arg.name.begins_with("_unnamed_arg")), +						vformat("Unnamed argument in position %d of built-in annotation '%s'.", j, ai.name)); +			} +		} +	} +} +  } // namespace GDScriptTests  #endif // GDSCRIPT_TEST_RUNNER_SUITE_H diff --git a/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_count_less.gd b/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_count_less.gd new file mode 100644 index 0000000000..435711fcaf --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_count_less.gd @@ -0,0 +1,10 @@ +func test(): +	print("Shouldn't reach this") + +class Parent: +	func my_function(_par1: int) -> int: +		return 0 + +class Child extends Parent: +	func my_function() -> int: +		return 0 diff --git a/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_count_less.out b/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_count_less.out new file mode 100644 index 0000000000..3baeb17066 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_count_less.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +The function signature doesn't match the parent. Parent signature is "int my_function(int)". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_count_more.gd b/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_count_more.gd new file mode 100644 index 0000000000..2bd392e8f8 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_count_more.gd @@ -0,0 +1,10 @@ +func test(): +	print("Shouldn't reach this") + +class Parent: +	func my_function(_par1: int) -> int: +		return 0 + +class Child extends Parent: +	func my_function(_pary1: int, _par2: int) -> int: +		return 0 diff --git a/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_count_more.out b/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_count_more.out new file mode 100644 index 0000000000..3baeb17066 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_count_more.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +The function signature doesn't match the parent. Parent signature is "int my_function(int)". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_default_values.gd b/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_default_values.gd new file mode 100644 index 0000000000..49ec82ce2d --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_default_values.gd @@ -0,0 +1,10 @@ +func test(): +	print("Shouldn't reach this") + +class Parent: +	func my_function(_par1: int = 0) -> int: +		return 0 + +class Child extends Parent: +	func my_function(_par1: int) -> int: +		return 0 diff --git a/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_default_values.out b/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_default_values.out new file mode 100644 index 0000000000..665c229339 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_default_values.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +The function signature doesn't match the parent. Parent signature is "int my_function(int = default)". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_type.gd b/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_type.gd new file mode 100644 index 0000000000..4a17a7831f --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_type.gd @@ -0,0 +1,10 @@ +func test(): +	print("Shouldn't reach this") + +class Parent: +	func my_function(_par1: int) -> int: +		return 0 + +class Child extends Parent: +	func my_function(_par1: Vector2) -> int: +		return 0 diff --git a/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_type.out b/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_type.out new file mode 100644 index 0000000000..3baeb17066 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_parameter_type.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +The function signature doesn't match the parent. Parent signature is "int my_function(int)". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_return_type.gd b/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_return_type.gd new file mode 100644 index 0000000000..b205ec96ef --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_return_type.gd @@ -0,0 +1,10 @@ +func test(): +	print("Shouldn't reach this") + +class Parent: +	func my_function() -> int: +		return 0 + +class Child extends Parent: +	func my_function() -> Vector2: +		return Vector2() diff --git a/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_return_type.out b/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_return_type.out new file mode 100644 index 0000000000..5b22739a93 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/function_dont_match_parent_signature_return_type.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +The function signature doesn't match the parent. Parent signature is "int my_function()". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/invalid_array_index.out b/modules/gdscript/tests/scripts/analyzer/errors/invalid_array_index.out index 015ad756f8..6f7f0783f0 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/invalid_array_index.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/invalid_array_index.out @@ -1,2 +1,2 @@  GDTEST_ANALYZER_ERROR -Invalid index type "bool" for a base of type "Array". +Cannot get index "true" from "[0, 1]". diff --git a/modules/gdscript/tests/scripts/analyzer/features/await_with_signals_no_warning.gd b/modules/gdscript/tests/scripts/analyzer/features/await_with_signals_no_warning.gd new file mode 100644 index 0000000000..9a7c6a8250 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/await_with_signals_no_warning.gd @@ -0,0 +1,12 @@ +# https://github.com/godotengine/godot/issues/54589 +# https://github.com/godotengine/godot/issues/56265 + +extends Resource + +func test(): +	print("okay") +	await self.changed +	await unknown(self) + +func unknown(arg): +	await arg.changed diff --git a/modules/gdscript/tests/scripts/analyzer/features/await_with_signals_no_warning.out b/modules/gdscript/tests/scripts/analyzer/features/await_with_signals_no_warning.out new file mode 100644 index 0000000000..2dc04a363e --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/await_with_signals_no_warning.out @@ -0,0 +1,2 @@ +GDTEST_OK +okay diff --git a/modules/gdscript/tests/scripts/analyzer/features/function_match_parent_signature_with_default_dict_void.gd b/modules/gdscript/tests/scripts/analyzer/features/function_match_parent_signature_with_default_dict_void.gd new file mode 100644 index 0000000000..631e7be5ce --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/function_match_parent_signature_with_default_dict_void.gd @@ -0,0 +1,14 @@ +func test(): +	var instance := Parent.new() +	instance.my_function({"a": 1}) +	instance = Child.new() +	instance.my_function({"a": 1}) +	print("No failure") + +class Parent: +	func my_function(_par1: Dictionary = {}) -> void: +		pass + +class Child extends Parent: +	func my_function(_par1: Dictionary = {}) -> void: +		pass diff --git a/modules/gdscript/tests/scripts/analyzer/features/function_match_parent_signature_with_default_dict_void.out b/modules/gdscript/tests/scripts/analyzer/features/function_match_parent_signature_with_default_dict_void.out new file mode 100644 index 0000000000..67f0045867 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/function_match_parent_signature_with_default_dict_void.out @@ -0,0 +1,2 @@ +GDTEST_OK +No failure diff --git a/modules/gdscript/tests/scripts/analyzer/features/function_match_parent_signature_with_extra_parameters.gd b/modules/gdscript/tests/scripts/analyzer/features/function_match_parent_signature_with_extra_parameters.gd new file mode 100644 index 0000000000..d678f3acfc --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/function_match_parent_signature_with_extra_parameters.gd @@ -0,0 +1,17 @@ +func test(): +	var instance := Parent.new() +	var result := instance.my_function(1) +	print(result) +	assert(result == 1) +	instance = Child.new() +	result = instance.my_function(2) +	print(result) +	assert(result == 0) + +class Parent: +	func my_function(par1: int) -> int: +		return par1 + +class Child extends Parent: +	func my_function(_par1: int, par2: int = 0) -> int: +		return par2 diff --git a/modules/gdscript/tests/scripts/analyzer/features/function_match_parent_signature_with_extra_parameters.out b/modules/gdscript/tests/scripts/analyzer/features/function_match_parent_signature_with_extra_parameters.out new file mode 100644 index 0000000000..fc5315a501 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/function_match_parent_signature_with_extra_parameters.out @@ -0,0 +1,3 @@ +GDTEST_OK +1 +0 diff --git a/modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.gd b/modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.gd index fb0ace6a90..ea744e3027 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.gd @@ -1,3 +1,5 @@ +const A := 42 +  func test():  	pass diff --git a/modules/gdscript/tests/scripts/analyzer/features/preload_constant_types_are_inferred.gd b/modules/gdscript/tests/scripts/analyzer/features/preload_constant_types_are_inferred.gd new file mode 100644 index 0000000000..276875dd5a --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/preload_constant_types_are_inferred.gd @@ -0,0 +1,6 @@ +const Constants = preload("gdscript_to_preload.gd") + +func test(): +	var a := Constants.A +	print(a) + diff --git a/modules/gdscript/tests/scripts/analyzer/features/preload_constant_types_are_inferred.out b/modules/gdscript/tests/scripts/analyzer/features/preload_constant_types_are_inferred.out new file mode 100644 index 0000000000..0982f3718c --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/preload_constant_types_are_inferred.out @@ -0,0 +1,2 @@ +GDTEST_OK +42 diff --git a/modules/gdscript/tests/scripts/analyzer/features/property_inline.out b/modules/gdscript/tests/scripts/analyzer/features/property_inline.out index 5482592e90..63e59398ae 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/property_inline.out +++ b/modules/gdscript/tests/scripts/analyzer/features/property_inline.out @@ -1,5 +1,5 @@  GDTEST_OK -null +<null>  0  1  2 diff --git a/modules/gdscript/tests/scripts/analyzer/typed_array_assignment.gd b/modules/gdscript/tests/scripts/analyzer/typed_array_assignment.gd new file mode 100644 index 0000000000..9f86d0531c --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/typed_array_assignment.gd @@ -0,0 +1,2 @@ +func test(): +	const arr: Array[int] = ["Hello", "World"] diff --git a/modules/gdscript/tests/scripts/analyzer/typed_array_assignment.out b/modules/gdscript/tests/scripts/analyzer/typed_array_assignment.out new file mode 100644 index 0000000000..26b6e13d4f --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/typed_array_assignment.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Assigned value for constant "arr" has type Array[String] which is not compatible with defined type Array[int]. diff --git a/modules/gdscript/tests/scripts/parser/errors/class_name_after_annotation.gd b/modules/gdscript/tests/scripts/parser/errors/class_name_after_annotation.gd index d13d713454..ada6030132 100644 --- a/modules/gdscript/tests/scripts/parser/errors/class_name_after_annotation.gd +++ b/modules/gdscript/tests/scripts/parser/errors/class_name_after_annotation.gd @@ -1,6 +1,6 @@ -# Error here. `class_name` should be used *before* annotations, not after. +# Error here. `class_name` should be used *before* annotations, not after (except @tool).  @icon("res://path/to/optional/icon.svg")  class_name HelloWorld  func test(): -	pass +    pass diff --git a/modules/gdscript/tests/scripts/parser/errors/class_name_after_annotation.out b/modules/gdscript/tests/scripts/parser/errors/class_name_after_annotation.out index 0bcc8acc55..02b33c8692 100644 --- a/modules/gdscript/tests/scripts/parser/errors/class_name_after_annotation.out +++ b/modules/gdscript/tests/scripts/parser/errors/class_name_after_annotation.out @@ -1,2 +1,2 @@  GDTEST_PARSER_ERROR -"class_name" should be used before annotations. +"class_name" should be used before annotations (except @tool). diff --git a/modules/gdscript/tests/scripts/parser/errors/dollar-assignment-bug-53696.out b/modules/gdscript/tests/scripts/parser/errors/dollar-assignment-bug-53696.out index b3dc181a22..9fafcb5a64 100644 --- a/modules/gdscript/tests/scripts/parser/errors/dollar-assignment-bug-53696.out +++ b/modules/gdscript/tests/scripts/parser/errors/dollar-assignment-bug-53696.out @@ -1,2 +1,2 @@  GDTEST_PARSER_ERROR -Expect node path as string or identifier after "$". +Expected node path as string or identifier after "$". diff --git a/modules/gdscript/tests/scripts/parser/errors/lambda_standalone.gd b/modules/gdscript/tests/scripts/parser/errors/lambda_standalone.gd new file mode 100644 index 0000000000..fa0a43094e --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/lambda_standalone.gd @@ -0,0 +1,3 @@ +func test(): +	func standalone(): +		print("can't be accessed") diff --git a/modules/gdscript/tests/scripts/parser/errors/lambda_standalone.out b/modules/gdscript/tests/scripts/parser/errors/lambda_standalone.out new file mode 100644 index 0000000000..c6830c8258 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/lambda_standalone.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +Standalone lambdas cannot be accessed. Consider assigning it to a variable. diff --git a/modules/gdscript/tests/scripts/parser/errors/match_multiple_variable_binds_in_branch.gd b/modules/gdscript/tests/scripts/parser/errors/match_multiple_variable_binds_in_branch.gd new file mode 100644 index 0000000000..4608c778aa --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/match_multiple_variable_binds_in_branch.gd @@ -0,0 +1,4 @@ +func test(): +    match 1: +        [[[var a]]], 2: +            pass diff --git a/modules/gdscript/tests/scripts/parser/errors/match_multiple_variable_binds_in_branch.out b/modules/gdscript/tests/scripts/parser/errors/match_multiple_variable_binds_in_branch.out new file mode 100644 index 0000000000..1cdc24683b --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/match_multiple_variable_binds_in_branch.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +Cannot use a variable bind with multiple patterns. diff --git a/modules/gdscript/tests/scripts/parser/errors/nothing_after_dollar.out b/modules/gdscript/tests/scripts/parser/errors/nothing_after_dollar.out index b3dc181a22..9fafcb5a64 100644 --- a/modules/gdscript/tests/scripts/parser/errors/nothing_after_dollar.out +++ b/modules/gdscript/tests/scripts/parser/errors/nothing_after_dollar.out @@ -1,2 +1,2 @@  GDTEST_PARSER_ERROR -Expect node path as string or identifier after "$". +Expected node path as string or identifier after "$". diff --git a/modules/gdscript/tests/scripts/parser/errors/variable_conflicts_for_variable.gd b/modules/gdscript/tests/scripts/parser/errors/variable_conflicts_for_variable.gd new file mode 100644 index 0000000000..409da11051 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/variable_conflicts_for_variable.gd @@ -0,0 +1,4 @@ +func test(): +	var TEST = 1 +	for TEST in 2: +		pass diff --git a/modules/gdscript/tests/scripts/parser/errors/variable_conflicts_for_variable.out b/modules/gdscript/tests/scripts/parser/errors/variable_conflicts_for_variable.out new file mode 100644 index 0000000000..407f094ca0 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/variable_conflicts_for_variable.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +There is already a variable named "TEST" declared in this scope. diff --git a/modules/gdscript/tests/scripts/parser/errors/variable_conflicts_variable.gd b/modules/gdscript/tests/scripts/parser/errors/variable_conflicts_variable.gd new file mode 100644 index 0000000000..b353fd1288 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/variable_conflicts_variable.gd @@ -0,0 +1,3 @@ +func test(): +	var TEST = 1 +	var TEST = 2 diff --git a/modules/gdscript/tests/scripts/parser/errors/variable_conflicts_variable.out b/modules/gdscript/tests/scripts/parser/errors/variable_conflicts_variable.out new file mode 100644 index 0000000000..407f094ca0 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/variable_conflicts_variable.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +There is already a variable named "TEST" declared in this scope. diff --git a/modules/gdscript/tests/scripts/parser/errors/wrong_value_after_dollar.out b/modules/gdscript/tests/scripts/parser/errors/wrong_value_after_dollar.out index b3dc181a22..9fafcb5a64 100644 --- a/modules/gdscript/tests/scripts/parser/errors/wrong_value_after_dollar.out +++ b/modules/gdscript/tests/scripts/parser/errors/wrong_value_after_dollar.out @@ -1,2 +1,2 @@  GDTEST_PARSER_ERROR -Expect node path as string or identifier after "$". +Expected node path as string or identifier after "$". diff --git a/modules/gdscript/tests/scripts/parser/errors/wrong_value_after_dollar_slash.out b/modules/gdscript/tests/scripts/parser/errors/wrong_value_after_dollar_slash.out index dcb4ccecb0..3062f0be70 100644 --- a/modules/gdscript/tests/scripts/parser/errors/wrong_value_after_dollar_slash.out +++ b/modules/gdscript/tests/scripts/parser/errors/wrong_value_after_dollar_slash.out @@ -1,2 +1,2 @@  GDTEST_PARSER_ERROR -Expect node path after "/". +Expected node path as string or identifier after "/". diff --git a/modules/gdscript/tests/scripts/parser/features/advanced_expression_matching.out b/modules/gdscript/tests/scripts/parser/features/advanced_expression_matching.out index 67c7e28046..3cdafb04a9 100644 --- a/modules/gdscript/tests/scripts/parser/features/advanced_expression_matching.out +++ b/modules/gdscript/tests/scripts/parser/features/advanced_expression_matching.out @@ -10,5 +10,5 @@ wildcard  [1,2,[1,{1:2,2:var z,..}]]  3  [1,2,[1,{1:2,2:var z,..}]] -[1, 3, 5, 123] +[1, 3, 5, "123"]  wildcard diff --git a/modules/gdscript/tests/scripts/parser/features/arrays_dictionaries_nested_const.gd b/modules/gdscript/tests/scripts/parser/features/arrays_dictionaries_nested_const.gd new file mode 100644 index 0000000000..cc78309ae4 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/arrays_dictionaries_nested_const.gd @@ -0,0 +1,58 @@ +# https://github.com/godotengine/godot/issues/50285 + +@warning_ignore(unused_local_constant) +func test(): +	const CONST_INNER_DICTIONARY = { "key": true } +	const CONST_NESTED_DICTIONARY_OLD_WORKAROUND = { +		"key1": "value1", +		"key2": CONST_INNER_DICTIONARY +	} +	# All of these should be valid +	const CONST_NESTED_DICTIONARY = { +		"key1": "value1", +		"key2": { "key": true } +	} + + +	const CONST_DICTIONARY_WITH_ARRAY = { +		"key1": [1,2,3,4] +	} + +	const CONST_NESTED_ARRAY = [[],[2],[1,2,3]] +	const CONST_ARRAY_WITH_DICT = [{"key1": 3}, {"key2": 5}] + +	const THREE_DIMENSIONAL_ARRAY = [[[],[],[]],[[],[],[]],[[],[],[]]] +	const MANY_NESTED_DICT = { +		"key1": { +			"key11": { +				"key111": {}, +				"key112": {}, +			}, +			"key12": { +				"key121": {}, +				"key122": {}, +			}, +		}, +		"key2": { +			"key21": { +				"key211": {}, +				"key212": {}, +			}, +			"key22": { +				"key221": {}, +				"key222": {}, +			}, +		} +	} + + +	const CONST_ARRAY_ACCESS = [1,2,3][0] +	const CONST_DICT_ACCESS = {"key1": 5}["key1"] + +	const CONST_ARRAY_NESTED_ACCESS = [[1,2,3],[4,5,6],[8,9,10]][0][1] +	const CONST_DICT_NESTED_ACCESS = {"key1": {"key2": 1}}["key1"]["key2"] + +	print(CONST_ARRAY_ACCESS) +	print(CONST_DICT_ACCESS) +	print(CONST_ARRAY_NESTED_ACCESS) +	print(CONST_DICT_NESTED_ACCESS) diff --git a/modules/gdscript/tests/scripts/parser/features/arrays_dictionaries_nested_const.out b/modules/gdscript/tests/scripts/parser/features/arrays_dictionaries_nested_const.out new file mode 100644 index 0000000000..5883fc5c18 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/arrays_dictionaries_nested_const.out @@ -0,0 +1,5 @@ +GDTEST_OK +1 +5 +2 +1 diff --git a/modules/gdscript/tests/scripts/parser/features/class_inheritance_access.gd b/modules/gdscript/tests/scripts/parser/features/class_inheritance_access.gd new file mode 100644 index 0000000000..eb392672eb --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/class_inheritance_access.gd @@ -0,0 +1,40 @@ +# Test access visibility of parent elements in nested class architectures. +class Parent: +	const parent_const := 1 + +	var parent_variable := 2 + +	signal parent_signal + +	var parent_attribute: int: +		get: +			return 3 + +	func parent_func(): +		return 4 + +	class Nested: +		const nested_const := 5 + + +class Child extends Parent: +	func child_test(): +		print(parent_const) +		print(self.parent_const) +		print(parent_variable) +		print(self.parent_variable) +		print(parent_signal.get_name()) +		print(self.parent_signal.get_name()) +		print(parent_attribute) +		print(self.parent_attribute) +		print(parent_func.get_method()) +		print(self.parent_func.get_method()) +		print(parent_func()) +		print(self.parent_func()) +		print(Nested.nested_const) +		print(self.Nested.nested_const) +		print(Parent.Nested.nested_const) + + +func test(): +	Child.new().child_test() diff --git a/modules/gdscript/tests/scripts/parser/features/class_inheritance_access.out b/modules/gdscript/tests/scripts/parser/features/class_inheritance_access.out new file mode 100644 index 0000000000..09e87bccfa --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/class_inheritance_access.out @@ -0,0 +1,16 @@ +GDTEST_OK +1 +1 +2 +2 +parent_signal +parent_signal +3 +3 +parent_func +parent_func +4 +4 +5 +5 +5 diff --git a/modules/gdscript/tests/scripts/parser/features/dictionary.out b/modules/gdscript/tests/scripts/parser/features/dictionary.out index 54083c1afc..5f999f573a 100644 --- a/modules/gdscript/tests/scripts/parser/features/dictionary.out +++ b/modules/gdscript/tests/scripts/parser/features/dictionary.out @@ -7,8 +7,8 @@ null  false  empty array  zero Vector2i -{22:{4:[nesting, arrays]}} -{4:[nesting, arrays]} -[nesting, arrays] +{22:{4:["nesting", "arrays"]}} +{4:["nesting", "arrays"]} +["nesting", "arrays"]  nesting  arrays diff --git a/modules/gdscript/tests/scripts/parser/features/dictionary_lua_style.out b/modules/gdscript/tests/scripts/parser/features/dictionary_lua_style.out index 5b0ea9df43..5143d040a9 100644 --- a/modules/gdscript/tests/scripts/parser/features/dictionary_lua_style.out +++ b/modules/gdscript/tests/scripts/parser/features/dictionary_lua_style.out @@ -1,2 +1,2 @@  GDTEST_OK -{a:1, b:2, with spaces:3, 2:4} +{"a":1, "b":2, "with spaces":3, "2":4} diff --git a/modules/gdscript/tests/scripts/parser/features/dictionary_mixed_syntax.out b/modules/gdscript/tests/scripts/parser/features/dictionary_mixed_syntax.out index 62be807a1f..dd28609850 100644 --- a/modules/gdscript/tests/scripts/parser/features/dictionary_mixed_syntax.out +++ b/modules/gdscript/tests/scripts/parser/features/dictionary_mixed_syntax.out @@ -1,2 +1,2 @@  GDTEST_OK -{hello:{world:{is:beautiful}}} +{"hello":{"world":{"is":"beautiful"}}} diff --git a/modules/gdscript/tests/scripts/parser/features/dollar_and_percent_get_node.gd b/modules/gdscript/tests/scripts/parser/features/dollar_and_percent_get_node.gd new file mode 100644 index 0000000000..f04f4de08d --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/dollar_and_percent_get_node.gd @@ -0,0 +1,49 @@ +extends Node + +func test(): +	var child = Node.new() +	child.name = "Child" +	add_child(child) +	child.owner = self + +	var hey = Node.new() +	hey.name = "Hey" +	child.add_child(hey) +	hey.owner = self +	hey.unique_name_in_owner = true + +	var fake_hey = Node.new() +	fake_hey.name = "Hey" +	add_child(fake_hey) +	fake_hey.owner = self + +	var sub_child = Node.new() +	sub_child.name = "SubChild" +	hey.add_child(sub_child) +	sub_child.owner = self + +	var howdy = Node.new() +	howdy.name = "Howdy" +	sub_child.add_child(howdy) +	howdy.owner = self +	howdy.unique_name_in_owner = true + +	print(hey == $Child/Hey) +	print(howdy == $Child/Hey/SubChild/Howdy) + +	print(%Hey == hey) +	print($%Hey == hey) +	print(%"Hey" == hey) +	print($"%Hey" == hey) +	print($%"Hey" == hey) +	print(%Hey/%Howdy == howdy) +	print($%Hey/%Howdy == howdy) +	print($"%Hey/%Howdy" == howdy) +	print($"%Hey"/"%Howdy" == howdy) +	print(%"Hey"/"%Howdy" == howdy) +	print($%"Hey"/"%Howdy" == howdy) +	print($"%Hey"/%"Howdy" == howdy) +	print(%"Hey"/%"Howdy" == howdy) +	print($%"Hey"/%"Howdy" == howdy) +	print(%"Hey/%Howdy" == howdy) +	print($%"Hey/%Howdy" == howdy) diff --git a/modules/gdscript/tests/scripts/parser/features/dollar_and_percent_get_node.out b/modules/gdscript/tests/scripts/parser/features/dollar_and_percent_get_node.out new file mode 100644 index 0000000000..041c4439b0 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/dollar_and_percent_get_node.out @@ -0,0 +1,19 @@ +GDTEST_OK +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true diff --git a/modules/gdscript/tests/scripts/parser/features/function_many_parameters.out b/modules/gdscript/tests/scripts/parser/features/function_many_parameters.out index 3a979227d4..80df7a3d4c 100644 --- a/modules/gdscript/tests/scripts/parser/features/function_many_parameters.out +++ b/modules/gdscript/tests/scripts/parser/features/function_many_parameters.out @@ -1,2 +1,2 @@  GDTEST_OK -123456789101112131415161718192212223242526272829303132333435363738394041424344454647falsetruenull +123456789101112131415161718192212223242526272829303132333435363738394041424344454647falsetrue<null> diff --git a/modules/gdscript/tests/scripts/parser/features/if_after_lambda.gd b/modules/gdscript/tests/scripts/parser/features/if_after_lambda.gd new file mode 100644 index 0000000000..f5e26ab1ab --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/if_after_lambda.gd @@ -0,0 +1,7 @@ +# https://github.com/godotengine/godot/issues/61231 + +func test(): +	var my_lambda = func(): +		print("hello") +	if 0 == 0: +		my_lambda.call() diff --git a/modules/gdscript/tests/scripts/parser/features/if_after_lambda.out b/modules/gdscript/tests/scripts/parser/features/if_after_lambda.out new file mode 100644 index 0000000000..58774d2d3f --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/if_after_lambda.out @@ -0,0 +1,2 @@ +GDTEST_OK +hello diff --git a/modules/gdscript/tests/scripts/parser/features/lambda_default_parameter_capture.gd b/modules/gdscript/tests/scripts/parser/features/lambda_default_parameter_capture.gd new file mode 100644 index 0000000000..2140b6923e --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/lambda_default_parameter_capture.gd @@ -0,0 +1,7 @@ +# https://github.com/godotengine/godot/issues/56751 + +func test(): +	var x = "local" +	var lambda = func(param = x): +		print(param) +	lambda.call() diff --git a/modules/gdscript/tests/scripts/parser/features/lambda_default_parameter_capture.out b/modules/gdscript/tests/scripts/parser/features/lambda_default_parameter_capture.out new file mode 100644 index 0000000000..ce3241b94d --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/lambda_default_parameter_capture.out @@ -0,0 +1,2 @@ +GDTEST_OK +local diff --git a/modules/gdscript/tests/scripts/parser/features/match_bind_unused.gd b/modules/gdscript/tests/scripts/parser/features/match_bind_unused.gd new file mode 100644 index 0000000000..707e4532cc --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/match_bind_unused.gd @@ -0,0 +1,13 @@ +# https://github.com/godotengine/godot/pull/61666 + +func test(): +	var dict := {"key": "value"} +	match dict: +		{"key": var value}: +			print(value) # used, no warning +	match dict: +		{"key": var value}: +			pass # unused, warning +	match dict: +		{"key": var _value}: +			pass # unused, suppressed warning from underscore diff --git a/modules/gdscript/tests/scripts/parser/features/match_bind_unused.out b/modules/gdscript/tests/scripts/parser/features/match_bind_unused.out new file mode 100644 index 0000000000..057c1b11e5 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/match_bind_unused.out @@ -0,0 +1,6 @@ +GDTEST_OK +>> WARNING +>> Line: 9 +>> UNUSED_VARIABLE +>> The local variable 'value' is declared but never used in the block. If this is intended, prefix it with an underscore: '_value' +value diff --git a/modules/gdscript/tests/scripts/parser/features/match_dictionary.gd b/modules/gdscript/tests/scripts/parser/features/match_dictionary.gd new file mode 100644 index 0000000000..377dd25e9e --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/match_dictionary.gd @@ -0,0 +1,43 @@ +func foo(x): +    match x: +        {"key1": "value1", "key2": "value2"}: +            print('{"key1": "value1", "key2": "value2"}') +        {"key1": "value1", "key2"}: +            print('{"key1": "value1", "key2"}') +        {"key1", "key2": "value2"}: +            print('{"key1", "key2": "value2"}') +        {"key1", "key2"}: +            print('{"key1", "key2"}') +        {"key1": "value1"}: +            print('{"key1": "value1"}') +        {"key1"}: +            print('{"key1"}') +        _: +            print("wildcard") + +func bar(x): +    match x: +        {0}: +            print("0") +        {1}: +            print("1") +        {2}: +            print("2") +        _: +            print("wildcard") + +func test(): +    foo({"key1": "value1", "key2": "value2"}) +    foo({"key1": "value1", "key2": ""}) +    foo({"key1": "", "key2": "value2"}) +    foo({"key1": "", "key2": ""}) +    foo({"key1": "value1"}) +    foo({"key1": ""}) +    foo({"key1": "value1", "key2": "value2", "key3": "value3"}) +    foo({"key1": "value1", "key3": ""}) +    foo({"key2": "value2"}) +    foo({"key3": ""}) +    bar({0: "0"}) +    bar({1: "1"}) +    bar({2: "2"}) +    bar({3: "3"}) diff --git a/modules/gdscript/tests/scripts/parser/features/match_dictionary.out b/modules/gdscript/tests/scripts/parser/features/match_dictionary.out new file mode 100644 index 0000000000..4dee886927 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/match_dictionary.out @@ -0,0 +1,15 @@ +GDTEST_OK +{"key1": "value1", "key2": "value2"} +{"key1": "value1", "key2"} +{"key1", "key2": "value2"} +{"key1", "key2"} +{"key1": "value1"} +{"key1"} +wildcard +wildcard +wildcard +wildcard +0 +1 +2 +wildcard diff --git a/modules/gdscript/tests/scripts/parser/features/match_multiple_patterns_with_array.gd b/modules/gdscript/tests/scripts/parser/features/match_multiple_patterns_with_array.gd new file mode 100644 index 0000000000..dbe223f5f5 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/match_multiple_patterns_with_array.gd @@ -0,0 +1,26 @@ +func foo(x): +    match x: +        1, [2]: +            print('1, [2]') +        _: +            print('wildcard') + +func bar(x): +    match x: +        [1], [2], [3]: +            print('[1], [2], [3]') +        [4]: +            print('[4]') +        _: +            print('wildcard') + +func test(): +    foo(1) +    foo([2]) +    foo(2) +    bar([1]) +    bar([2]) +    bar([3]) +    bar([4]) +    bar([5]) + diff --git a/modules/gdscript/tests/scripts/parser/features/match_multiple_patterns_with_array.out b/modules/gdscript/tests/scripts/parser/features/match_multiple_patterns_with_array.out new file mode 100644 index 0000000000..a12b934d67 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/match_multiple_patterns_with_array.out @@ -0,0 +1,9 @@ +GDTEST_OK +1, [2] +1, [2] +wildcard +[1], [2], [3] +[1], [2], [3] +[1], [2], [3] +[4] +wildcard diff --git a/modules/gdscript/tests/scripts/parser/features/match_multiple_variable_binds_in_pattern.gd b/modules/gdscript/tests/scripts/parser/features/match_multiple_variable_binds_in_pattern.gd new file mode 100644 index 0000000000..a0ae7fb17c --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/match_multiple_variable_binds_in_pattern.gd @@ -0,0 +1,6 @@ +func test(): +    match [1, 2, 3]: +        [var a, var b, var c]: +            print(a == 1) +            print(b == 2) +            print(c == 3) diff --git a/modules/gdscript/tests/scripts/parser/features/match_multiple_variable_binds_in_pattern.out b/modules/gdscript/tests/scripts/parser/features/match_multiple_variable_binds_in_pattern.out new file mode 100644 index 0000000000..316db6d748 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/match_multiple_variable_binds_in_pattern.out @@ -0,0 +1,4 @@ +GDTEST_OK +true +true +true diff --git a/modules/gdscript/tests/scripts/parser/features/nested_dictionary.out b/modules/gdscript/tests/scripts/parser/features/nested_dictionary.out index 4009160439..8b8c33202f 100644 --- a/modules/gdscript/tests/scripts/parser/features/nested_dictionary.out +++ b/modules/gdscript/tests/scripts/parser/features/nested_dictionary.out @@ -1,5 +1,5 @@  GDTEST_OK -{8:{key:value}} -{key:value} +{8:{"key":"value"}} +{"key":"value"}  value  value diff --git a/modules/gdscript/tests/scripts/parser/features/str_preserves_case.out b/modules/gdscript/tests/scripts/parser/features/str_preserves_case.out index abba38e87c..867f45f0ac 100644 --- a/modules/gdscript/tests/scripts/parser/features/str_preserves_case.out +++ b/modules/gdscript/tests/scripts/parser/features/str_preserves_case.out @@ -1,4 +1,4 @@  GDTEST_OK -null +<null>  true  false diff --git a/modules/gdscript/tests/scripts/parser/warnings/unreachable_code_after_return_bug_55154.gd b/modules/gdscript/tests/scripts/parser/warnings/unreachable_code_after_return_bug_55154.gd new file mode 100644 index 0000000000..d00d483a73 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/warnings/unreachable_code_after_return_bug_55154.gd @@ -0,0 +1,16 @@ +func test(): +	var foo := "bar" +	match foo: +		"baz": +			return +		_: +			pass +	match foo: +		"baz": +			return +	match foo: +		"bar": +			pass +		_: +			return +	print("reached") diff --git a/modules/gdscript/tests/scripts/parser/warnings/unreachable_code_after_return_bug_55154.out b/modules/gdscript/tests/scripts/parser/warnings/unreachable_code_after_return_bug_55154.out new file mode 100644 index 0000000000..47db6b631b --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/warnings/unreachable_code_after_return_bug_55154.out @@ -0,0 +1,2 @@ +GDTEST_OK +reached diff --git a/modules/gdscript/tests/scripts/runtime/features/chain_assignment_works.gd b/modules/gdscript/tests/scripts/runtime/features/chain_assignment_works.gd new file mode 100644 index 0000000000..d2f3a3e18f --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/chain_assignment_works.gd @@ -0,0 +1,19 @@ +func test(): +	var dictionary1: Variant = {1:Vector2()} +	dictionary1[1].x = 2 +	var dictionary2: Dictionary = {3:Vector2()} +	dictionary2[3].x = 4 +	var array1: Variant = [[Vector2()]] +	array1[0][0].x = 5 +	var array2: Array = [[Vector2()]] +	array2[0][0].x = 6 +	var array3: Array[Array] = [[Vector2()]] +	array3[0][0].x = 7 +	var transform = Transform3D() +	transform.basis.x = Vector3(8.0, 9.0, 7.0) +	print(dictionary1) +	print(dictionary2) +	print(array1) +	print(array2) +	print(array3) +	print(transform) diff --git a/modules/gdscript/tests/scripts/runtime/features/chain_assignment_works.out b/modules/gdscript/tests/scripts/runtime/features/chain_assignment_works.out new file mode 100644 index 0000000000..5e7ccf534a --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/chain_assignment_works.out @@ -0,0 +1,7 @@ +GDTEST_OK +{1:(2, 0)} +{3:(4, 0)} +[[(5, 0)]] +[[(6, 0)]] +[[(7, 0)]] +[X: (8, 9, 7), Y: (0, 1, 0), Z: (0, 0, 1), O: (0, 0, 0)] diff --git a/modules/gdscript/tests/scripts/runtime/features/lambda_use_self.gd b/modules/gdscript/tests/scripts/runtime/features/lambda_use_self.gd new file mode 100644 index 0000000000..3d063869ab --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/lambda_use_self.gd @@ -0,0 +1,23 @@ +var member = "foo" + +func bar(): +	print("bar") + +func test(): +	var lambda1 = func(): +		print(member) +	lambda1.call() + +	var lambda2 = func(): +		var nested = func(): +			print(member) +		nested.call() +	lambda2.call() + +	var lambda3 = func(): +		bar() +	lambda3.call() + +	var lambda4 = func(): +		return self +	print(lambda4.call() == self) diff --git a/modules/gdscript/tests/scripts/runtime/features/lambda_use_self.out b/modules/gdscript/tests/scripts/runtime/features/lambda_use_self.out new file mode 100644 index 0000000000..53d602b234 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/lambda_use_self.out @@ -0,0 +1,5 @@ +GDTEST_OK +foo +foo +bar +true diff --git a/modules/gdscript/tests/scripts/runtime/features/stringify.out b/modules/gdscript/tests/scripts/runtime/features/stringify.out index 7670fc0128..d4468737a5 100644 --- a/modules/gdscript/tests/scripts/runtime/features/stringify.out +++ b/modules/gdscript/tests/scripts/runtime/features/stringify.out @@ -21,14 +21,14 @@ hello/world  RID(0)  Node::get_name  Node::[signal]property_list_changed -{hello:123} -[hello, 123] +{"hello":123} +["hello", 123]  [255, 0, 1]  [-1, 0, 1]  [-1, 0, 1]  [-1, 0, 1]  [-1, 0, 1] -[hello, world] +["hello", "world"]  [(1, 1), (0, 0)]  [(1, 1, 1), (0, 0, 0)]  [(1, 0, 0, 1), (0, 0, 1, 1), (0, 1, 0, 1)] diff --git a/modules/gdscript/tests/test_gdscript.cpp b/modules/gdscript/tests/test_gdscript.cpp index 4255030b4e..cbcd7b2955 100644 --- a/modules/gdscript/tests/test_gdscript.cpp +++ b/modules/gdscript/tests/test_gdscript.cpp @@ -134,6 +134,34 @@ static void test_parser(const String &p_code, const String &p_script_path, const  #endif  } +static void recursively_disassemble_functions(const Ref<GDScript> script, const Vector<String> &p_lines) { +	for (const KeyValue<StringName, GDScriptFunction *> &E : script->get_member_functions()) { +		const GDScriptFunction *func = E.value; + +		String signature = "Disassembling " + func->get_name().operator String() + "("; +		for (int i = 0; i < func->get_argument_count(); i++) { +			if (i > 0) { +				signature += ", "; +			} +			signature += func->get_argument_name(i); +		} +		print_line(signature + ")"); +#ifdef TOOLS_ENABLED +		func->disassemble(p_lines); +#endif +		print_line(""); +		print_line(""); +	} + +	for (const KeyValue<StringName, Ref<GDScript>> &F : script->get_subclasses()) { +		const Ref<GDScript> inner_script = F.value; +		print_line(""); +		print_line(vformat("Inner Class: %s", inner_script->get_script_class_name())); +		print_line(""); +		recursively_disassemble_functions(inner_script, p_lines); +	} +} +  static void test_compiler(const String &p_code, const String &p_script_path, const Vector<String> &p_lines) {  	GDScriptParser parser;  	Error err = parser.parse(p_code, p_script_path, false); @@ -172,23 +200,7 @@ static void test_compiler(const String &p_code, const String &p_script_path, con  		return;  	} -	for (const KeyValue<StringName, GDScriptFunction *> &E : script->get_member_functions()) { -		const GDScriptFunction *func = E.value; - -		String signature = "Disassembling " + func->get_name().operator String() + "("; -		for (int i = 0; i < func->get_argument_count(); i++) { -			if (i > 0) { -				signature += ", "; -			} -			signature += func->get_argument_name(i); -		} -		print_line(signature + ")"); -#ifdef TOOLS_ENABLED -		func->disassemble(p_lines); -#endif -		print_line(""); -		print_line(""); -	} +	recursively_disassemble_functions(script, p_lines);  }  void test(TestType p_type) { @@ -204,8 +216,8 @@ void test(TestType p_type) {  		return;  	} -	FileAccessRef fa = FileAccess::open(test, FileAccess::READ); -	ERR_FAIL_COND_MSG(!fa, "Could not open file: " + test); +	Ref<FileAccess> fa = FileAccess::open(test, FileAccess::READ); +	ERR_FAIL_COND_MSG(fa.is_null(), "Could not open file: " + test);  	// Initialize the language for the test routine.  	init_language(fa->get_path_absolute().get_base_dir()); |