diff options
Diffstat (limited to 'modules/gdscript/tests/scripts/parser')
32 files changed, 258 insertions, 152 deletions
| 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 ada6030132..0085b3f367 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 (except @tool). -@icon("res://path/to/optional/icon.svg") +# Error here. Annotations should be used before `class_name`, not after.  class_name HelloWorld +@icon("res://path/to/optional/icon.svg")  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 02b33c8692..5fcf1cbcad 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 (except @tool). +Annotation "@icon" must be at the top of the script, before "extends" and "class_name". diff --git a/modules/gdscript/tests/scripts/parser/errors/double_dictionary_comma.gd b/modules/gdscript/tests/scripts/parser/errors/double_dictionary_comma.gd index 92dfb2366d..816783f239 100644 --- a/modules/gdscript/tests/scripts/parser/errors/double_dictionary_comma.gd +++ b/modules/gdscript/tests/scripts/parser/errors/double_dictionary_comma.gd @@ -1,2 +1,2 @@  func test(): -    var dictionary = { hello = "world",, } +	var dictionary = { hello = "world",, } diff --git a/modules/gdscript/tests/scripts/parser/errors/identifier_similar_to_keyword.gd b/modules/gdscript/tests/scripts/parser/errors/identifier_similar_to_keyword.gd new file mode 100644 index 0000000000..4b1f284070 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/identifier_similar_to_keyword.gd @@ -0,0 +1,3 @@ +func test(): +	var аs # Using Cyrillic "а". +	print(аs) diff --git a/modules/gdscript/tests/scripts/parser/errors/identifier_similar_to_keyword.out b/modules/gdscript/tests/scripts/parser/errors/identifier_similar_to_keyword.out new file mode 100644 index 0000000000..337dec2f4d --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/identifier_similar_to_keyword.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +Identifier "аs" is visually similar to the GDScript keyword "as" and thus not allowed. 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 index 4608c778aa..7a745bd995 100644 --- 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 @@ -1,4 +1,4 @@  func test(): -    match 1: -        [[[var a]]], 2: -            pass +	match 1: +		[[[var a]]], 2: +			pass diff --git a/modules/gdscript/tests/scripts/parser/features/advanced_expression_matching.gd b/modules/gdscript/tests/scripts/parser/features/advanced_expression_matching.gd index 43b513045b..a7197bf68f 100644 --- a/modules/gdscript/tests/scripts/parser/features/advanced_expression_matching.gd +++ b/modules/gdscript/tests/scripts/parser/features/advanced_expression_matching.gd @@ -1,34 +1,34 @@  func foo(x): -    match x: -        1 + 1: -            print("1+1") -        [1,2,[1,{1:2,2:var z,..}]]: -            print("[1,2,[1,{1:2,2:var z,..}]]") -            print(z) -        1 if true else 2: -            print("1 if true else 2") -        1 < 2: -            print("1 < 2") -        1 or 2 and 1: -            print("1 or 2 and 1") -        6 | 1: -            print("1 | 1") -        1 >> 1: -            print("1 >> 1") -        1, 2 or 3, 4: -            print("1, 2 or 3, 4") -        _: -            print("wildcard") +	match x: +		1 + 1: +			print("1+1") +		[1,2,[1,{1:2,2:var z,..}]]: +			print("[1,2,[1,{1:2,2:var z,..}]]") +			print(z) +		1 if true else 2: +			print("1 if true else 2") +		1 < 2: +			print("1 < 2") +		1 or 2 and 1: +			print("1 or 2 and 1") +		6 | 1: +			print("1 | 1") +		1 >> 1: +			print("1 >> 1") +		1, 2 or 3, 4: +			print("1, 2 or 3, 4") +		_: +			print("wildcard")  func test(): -    foo(6 | 1) -    foo(1 >> 1) -    foo(2) -    foo(1) -    foo(1+1) -    foo(1 < 2) -    foo([2, 1]) -    foo(4) -    foo([1, 2, [1, {1 : 2, 2:3}]]) -    foo([1, 2, [1, {1 : 2, 2:[1,3,5, "123"], 4:2}]]) -    foo([1, 2, [1, {1 : 2}]]) +	foo(6 | 1) +	foo(1 >> 1) +	foo(2) +	foo(1) +	foo(1+1) +	foo(1 < 2) +	foo([2, 1]) +	foo(4) +	foo([1, 2, [1, {1 : 2, 2:3}]]) +	foo([1, 2, [1, {1 : 2, 2:[1,3,5, "123"], 4:2}]]) +	foo([1, 2, [1, {1 : 2}]]) 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 index cc78309ae4..a34cc26e67 100644 --- a/modules/gdscript/tests/scripts/parser/features/arrays_dictionaries_nested_const.gd +++ b/modules/gdscript/tests/scripts/parser/features/arrays_dictionaries_nested_const.gd @@ -1,6 +1,6 @@  # https://github.com/godotengine/godot/issues/50285 -@warning_ignore(unused_local_constant) +@warning_ignore("unused_local_constant")  func test():  	const CONST_INNER_DICTIONARY = { "key": true }  	const CONST_NESTED_DICTIONARY_OLD_WORKAROUND = { diff --git a/modules/gdscript/tests/scripts/parser/features/basic_expression_matching.gd b/modules/gdscript/tests/scripts/parser/features/basic_expression_matching.gd index 2b46f1e88a..c959c6c6af 100644 --- a/modules/gdscript/tests/scripts/parser/features/basic_expression_matching.gd +++ b/modules/gdscript/tests/scripts/parser/features/basic_expression_matching.gd @@ -1,27 +1,27 @@  func foo(x): -    match x: -        1: -            print("1") -        2: -            print("2") -        [1, 2]: -            print("[1, 2]") -        3 or 4: -            print("3 or 4") -        4: -            print("4") -        {1 : 2, 2 : 3}: -            print("{1 : 2, 2 : 3}") -        _: -            print("wildcard") +	match x: +		1: +			print("1") +		2: +			print("2") +		[1, 2]: +			print("[1, 2]") +		3 or 4: +			print("3 or 4") +		4: +			print("4") +		{1 : 2, 2 : 3}: +			print("{1 : 2, 2 : 3}") +		_: +			print("wildcard")  func test(): -    foo(0) -    foo(1) -    foo(2) -    foo([1, 2]) -    foo(3) -    foo(4) -    foo([4,4]) -    foo({1 : 2, 2 : 3}) -    foo({1 : 2, 4 : 3}) +	foo(0) +	foo(1) +	foo(2) +	foo([1, 2]) +	foo(3) +	foo(4) +	foo([4,4]) +	foo({1 : 2, 2 : 3}) +	foo({1 : 2, 4 : 3}) diff --git a/modules/gdscript/tests/scripts/parser/features/class_name.gd b/modules/gdscript/tests/scripts/parser/features/class_name.gd index 8bd188e247..19009e433d 100644 --- a/modules/gdscript/tests/scripts/parser/features/class_name.gd +++ b/modules/gdscript/tests/scripts/parser/features/class_name.gd @@ -1,5 +1,5 @@ -class_name HelloWorld  @icon("res://path/to/optional/icon.svg") +class_name HelloWorld  func test():  	pass diff --git a/modules/gdscript/tests/scripts/parser/features/export_variable.gd b/modules/gdscript/tests/scripts/parser/features/export_variable.gd index 1e072728fc..acf9ff2e21 100644 --- a/modules/gdscript/tests/scripts/parser/features/export_variable.gd +++ b/modules/gdscript/tests/scripts/parser/features/export_variable.gd @@ -5,7 +5,7 @@  @export var color: Color  @export_color_no_alpha var color_no_alpha: Color -@export_node_path(Sprite2D, Sprite3D, Control, Node) var nodepath := ^"hello" +@export_node_path("Sprite2D", "Sprite3D", "Control", "Node") var nodepath := ^"hello"  func test(): diff --git a/modules/gdscript/tests/scripts/parser/features/lambda_callable.gd b/modules/gdscript/tests/scripts/parser/features/lambda_callable.gd index c3b2506156..17d00bce3c 100644 --- a/modules/gdscript/tests/scripts/parser/features/lambda_callable.gd +++ b/modules/gdscript/tests/scripts/parser/features/lambda_callable.gd @@ -1,4 +1,4 @@  func test(): -    var my_lambda = func(x): -        print(x) -    my_lambda.call("hello") +	var my_lambda = func(x): +		print(x) +	my_lambda.call("hello") diff --git a/modules/gdscript/tests/scripts/parser/features/match.gd b/modules/gdscript/tests/scripts/parser/features/match.gd index 4d05490aa5..59b5ba2426 100644 --- a/modules/gdscript/tests/scripts/parser/features/match.gd +++ b/modules/gdscript/tests/scripts/parser/features/match.gd @@ -3,8 +3,6 @@ func test():  	match i:  		"Hello":  			print("hello") -			# This will fall through to the default case below. -			continue  		"Good bye":  			print("bye")  		_: diff --git a/modules/gdscript/tests/scripts/parser/features/match.out b/modules/gdscript/tests/scripts/parser/features/match.out index 732885c7a2..a2cb94399c 100644 --- a/modules/gdscript/tests/scripts/parser/features/match.out +++ b/modules/gdscript/tests/scripts/parser/features/match.out @@ -1,4 +1,3 @@  GDTEST_OK  hello -default  This will match diff --git a/modules/gdscript/tests/scripts/parser/features/match_dictionary.gd b/modules/gdscript/tests/scripts/parser/features/match_dictionary.gd index 377dd25e9e..75857fb8ff 100644 --- a/modules/gdscript/tests/scripts/parser/features/match_dictionary.gd +++ b/modules/gdscript/tests/scripts/parser/features/match_dictionary.gd @@ -1,43 +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") +	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") +	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"}) +	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_multiple_patterns_with_array.gd b/modules/gdscript/tests/scripts/parser/features/match_multiple_patterns_with_array.gd index dbe223f5f5..a278ea1154 100644 --- 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 @@ -1,26 +1,26 @@  func foo(x): -    match x: -        1, [2]: -            print('1, [2]') -        _: -            print('wildcard') +	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') +	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]) +	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_variable_binds_in_pattern.gd b/modules/gdscript/tests/scripts/parser/features/match_multiple_variable_binds_in_pattern.gd index a0ae7fb17c..0a71f33c25 100644 --- 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 @@ -1,6 +1,6 @@  func test(): -    match [1, 2, 3]: -        [var a, var b, var c]: -            print(a == 1) -            print(b == 2) -            print(c == 3) +	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/multiline_assert.gd b/modules/gdscript/tests/scripts/parser/features/multiline_assert.gd new file mode 100644 index 0000000000..8c699c604d --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/multiline_assert.gd @@ -0,0 +1,24 @@ +func test(): +	var x := 5 + +	assert(x > 0) +	assert(x > 0,) +	assert(x > 0, 'message') +	assert(x > 0, 'message',) + +	assert( +		x > 0 +	) +	assert( +		x > 0, +	) +	assert( +		x > 0, +		'message' +	) +	assert( +		x > 0, +		'message', +	) + +	print('OK') diff --git a/modules/gdscript/tests/scripts/parser/features/multiline_assert.out b/modules/gdscript/tests/scripts/parser/features/multiline_assert.out new file mode 100644 index 0000000000..1ccb591560 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/multiline_assert.out @@ -0,0 +1,2 @@ +GDTEST_OK +OK diff --git a/modules/gdscript/tests/scripts/parser/features/nested_match.gd b/modules/gdscript/tests/scripts/parser/features/nested_match.gd index aaddcc7e83..491d917a8e 100644 --- a/modules/gdscript/tests/scripts/parser/features/nested_match.gd +++ b/modules/gdscript/tests/scripts/parser/features/nested_match.gd @@ -8,11 +8,10 @@ func test():  				1234:  					print("2")  					match number: -						1234: -							print("3") -							continue +						4321: +							print("Should not be printed")  						_: -							print("Should also be printed") +							print("3")  							match number:  								1234:  									print("4") diff --git a/modules/gdscript/tests/scripts/parser/features/nested_match.out b/modules/gdscript/tests/scripts/parser/features/nested_match.out index 651d76cc59..c2d2e29a06 100644 --- a/modules/gdscript/tests/scripts/parser/features/nested_match.out +++ b/modules/gdscript/tests/scripts/parser/features/nested_match.out @@ -2,7 +2,6 @@ GDTEST_OK  1  2  3 -Should also be printed  4  5  6 diff --git a/modules/gdscript/tests/scripts/parser/features/unicode_identifiers.gd b/modules/gdscript/tests/scripts/parser/features/unicode_identifiers.gd new file mode 100644 index 0000000000..523959a016 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/unicode_identifiers.gd @@ -0,0 +1,35 @@ +const π = PI +var ㄥ = π + +func test(): +	var փորձարկում = "test" +	prints("փորձարկում", փորձարկում) +	var امتحان = "test" +	prints("امتحان", امتحان) +	var পরীক্ষা = "test" +	prints("পরীক্ষা", পরীক্ষা) +	var тест = "test" +	prints("тест", тест) +	var जाँच = "test" +	prints("जाँच", जाँच) +	var 기준 = "test" +	prints("기준", 기준) +	var 测试 = "test" +	prints("测试", 测试) +	var テスト = "test" +	prints("テスト", テスト) +	var 試験 = "test" +	prints("試験", 試験) +	var പരീക്ഷ = "test" +	prints("പരീക്ഷ", പരീക്ഷ) +	var ทดสอบ = "test" +	prints("ทดสอบ", ทดสอบ) +	var δοκιμή = "test" +	prints("δοκιμή", δοκιμή) + +	const d = 1.1 +	_process(d) +	print(is_equal_approx(ㄥ, PI + (d * PI))) + +func _process(Δ: float) -> void: +	ㄥ += Δ * π diff --git a/modules/gdscript/tests/scripts/parser/features/unicode_identifiers.out b/modules/gdscript/tests/scripts/parser/features/unicode_identifiers.out new file mode 100644 index 0000000000..c071380a8f --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/unicode_identifiers.out @@ -0,0 +1,14 @@ +GDTEST_OK +փորձարկում test +امتحان test +পরীক্ষা test +тест test +जाँच test +기준 test +测试 test +テスト test +試験 test +പരീക്ഷ test +ทดสอบ test +δοκιμή test +true diff --git a/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.gd b/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.gd new file mode 100644 index 0000000000..4cbb464f59 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.gd @@ -0,0 +1,17 @@ +class A: +	enum { X = 1 } + +	class B: +		enum { X = 2 } + +class C: +	const X = 3 + +	class D: +		enum { X = 4 } + +func test(): +	print(A.X) +	print(A.B.X) +	print(C.X) +	print(C.D.X) diff --git a/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.out b/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.out new file mode 100644 index 0000000000..7536c38490 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.out @@ -0,0 +1,5 @@ +GDTEST_OK +1 +2 +3 +4 diff --git a/modules/gdscript/tests/scripts/parser/features/vector_inf.gd b/modules/gdscript/tests/scripts/parser/features/vector_inf.gd new file mode 100644 index 0000000000..039d51d9ed --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/vector_inf.gd @@ -0,0 +1,6 @@ +func test(): +	var vec2: = Vector2.INF +	var vec3: = Vector3.INF + +	print(vec2.x == INF) +	print(vec3.z == INF) diff --git a/modules/gdscript/tests/scripts/parser/features/vector_inf.out b/modules/gdscript/tests/scripts/parser/features/vector_inf.out new file mode 100644 index 0000000000..9d111a8322 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/vector_inf.out @@ -0,0 +1,3 @@ +GDTEST_OK +true +true diff --git a/modules/gdscript/tests/scripts/parser/warnings/confusable_identifier.gd b/modules/gdscript/tests/scripts/parser/warnings/confusable_identifier.gd new file mode 100644 index 0000000000..e2caac8ffd --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/warnings/confusable_identifier.gd @@ -0,0 +1,5 @@ +func test(): +	var port = 0 # Only latin characters. +	var pοrt = 1 # The "ο" is Greek omicron. + +	prints(port, pοrt) diff --git a/modules/gdscript/tests/scripts/parser/warnings/confusable_identifier.out b/modules/gdscript/tests/scripts/parser/warnings/confusable_identifier.out new file mode 100644 index 0000000000..c483396443 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/warnings/confusable_identifier.out @@ -0,0 +1,6 @@ +GDTEST_OK +>> WARNING +>> Line: 3 +>> CONFUSABLE_IDENTIFIER +>> The identifier "pοrt" has misleading characters and might be confused with something else. +0 1 diff --git a/modules/gdscript/tests/scripts/parser/warnings/return_value_discarded.out b/modules/gdscript/tests/scripts/parser/warnings/return_value_discarded.out index 13f759dd46..e89bb9226f 100644 --- a/modules/gdscript/tests/scripts/parser/warnings/return_value_discarded.out +++ b/modules/gdscript/tests/scripts/parser/warnings/return_value_discarded.out @@ -2,4 +2,4 @@ GDTEST_OK  >> WARNING  >> Line: 6  >> RETURN_VALUE_DISCARDED ->> The function 'i_return_int()' returns a value, but this value is never used. +>> The function 'i_return_int()' returns a value that will be discarded if not used. diff --git a/modules/gdscript/tests/scripts/parser/warnings/void_assignment.gd b/modules/gdscript/tests/scripts/parser/warnings/void_assignment.gd deleted file mode 100644 index b4a42b3e3d..0000000000 --- a/modules/gdscript/tests/scripts/parser/warnings/void_assignment.gd +++ /dev/null @@ -1,6 +0,0 @@ -func i_return_void() -> void: -	return - - -func test(): -	var __ = i_return_void() diff --git a/modules/gdscript/tests/scripts/parser/warnings/void_assignment.out b/modules/gdscript/tests/scripts/parser/warnings/void_assignment.out deleted file mode 100644 index 84c9598f9a..0000000000 --- a/modules/gdscript/tests/scripts/parser/warnings/void_assignment.out +++ /dev/null @@ -1,5 +0,0 @@ -GDTEST_OK ->> WARNING ->> Line: 6 ->> VOID_ASSIGNMENT ->> Assignment operation, but the function 'i_return_void()' returns void. |