diff options
Diffstat (limited to 'modules/gdscript/tests/scripts/parser/features')
12 files changed, 198 insertions, 0 deletions
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/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  |