diff options
Diffstat (limited to 'modules/gdscript/tests/scripts/parser')
12 files changed, 109 insertions, 55 deletions
diff --git a/modules/gdscript/tests/scripts/parser/features/constants.out b/modules/gdscript/tests/scripts/parser/features/constants.out index 7ec33470d3..d73c5eb7cd 100644 --- a/modules/gdscript/tests/scripts/parser/features/constants.out +++ b/modules/gdscript/tests/scripts/parser/features/constants.out @@ -1,33 +1 @@ GDTEST_OK ->> WARNING ->> Line: 2 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_TEST" is declared but never used in the block. If this is intended, prefix it with an underscore: "__TEST". ->> WARNING ->> Line: 3 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_STRING" is declared but never used in the block. If this is intended, prefix it with an underscore: "__STRING". ->> WARNING ->> Line: 4 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_VECTOR" is declared but never used in the block. If this is intended, prefix it with an underscore: "__VECTOR". ->> WARNING ->> Line: 5 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_ARRAY" is declared but never used in the block. If this is intended, prefix it with an underscore: "__ARRAY". ->> WARNING ->> Line: 6 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_DICTIONARY" is declared but never used in the block. If this is intended, prefix it with an underscore: "__DICTIONARY". ->> WARNING ->> Line: 9 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_HELLO" is declared but never used in the block. If this is intended, prefix it with an underscore: "__HELLO". ->> WARNING ->> Line: 10 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_INFINITY" is declared but never used in the block. If this is intended, prefix it with an underscore: "__INFINITY". ->> WARNING ->> Line: 11 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_NOT_A_NUMBER" is declared but never used in the block. If this is intended, prefix it with an underscore: "__NOT_A_NUMBER". diff --git a/modules/gdscript/tests/scripts/parser/features/continuation_lines_comments.bin.gd b/modules/gdscript/tests/scripts/parser/features/continuation_lines_comments.bin.gd new file mode 100644 index 0000000000..cb0bc94d2e --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/continuation_lines_comments.bin.gd @@ -0,0 +1,12 @@ +# GH-89403 + +func test(): + var x := 1 + if x == 0 \ + # Comment. + # Comment. + and (x < 1 or x > 2) \ + # Comment. + and x != 3: + pass + print("Ok") diff --git a/modules/gdscript/tests/scripts/parser/features/continuation_lines_comments.bin.out b/modules/gdscript/tests/scripts/parser/features/continuation_lines_comments.bin.out new file mode 100644 index 0000000000..0e9f482af4 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/continuation_lines_comments.bin.out @@ -0,0 +1,2 @@ +GDTEST_OK +Ok diff --git a/modules/gdscript/tests/scripts/parser/features/match_array.gd b/modules/gdscript/tests/scripts/parser/features/match_array.gd new file mode 100644 index 0000000000..9103092cb4 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/match_array.gd @@ -0,0 +1,33 @@ +func foo(x): + match x: + ["value1"]: + print('["value1"]') + ["value1", "value2"]: + print('["value1", "value2"]') + +func bar(x): + match x: + [ + "value1" + ]: + print('multiline ["value1"]') + [ + "value1", + "value2", + ]: + print('multiline ["value1", "value2",]') + [ + "value1", + [ + "value2", + .., + ], + ]: + print('multiline ["value1", ["value2", ..,],]') + +func test(): + foo(["value1"]) + foo(["value1", "value2"]) + bar(["value1"]) + bar(["value1", "value2"]) + bar(["value1", ["value2", "value3"]]) diff --git a/modules/gdscript/tests/scripts/parser/features/match_array.out b/modules/gdscript/tests/scripts/parser/features/match_array.out new file mode 100644 index 0000000000..d0111f07b1 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/match_array.out @@ -0,0 +1,6 @@ +GDTEST_OK +["value1"] +["value1", "value2"] +multiline ["value1"] +multiline ["value1", "value2",] +multiline ["value1", ["value2", ..,],] diff --git a/modules/gdscript/tests/scripts/parser/features/match_dictionary.gd b/modules/gdscript/tests/scripts/parser/features/match_dictionary.gd index 75857fb8ff..7685622e5a 100644 --- a/modules/gdscript/tests/scripts/parser/features/match_dictionary.gd +++ b/modules/gdscript/tests/scripts/parser/features/match_dictionary.gd @@ -26,6 +26,24 @@ func bar(x): _: print("wildcard") +func baz(x): + match x: + { + "key1": "value1" + }: + print('multiline {"key1": "value1"}') + { + "key2": "value2", + }: + print('multiline {"key2": "value2",}') + { + "key3": { + "key1", + .., + }, + }: + print('multiline {"key3": {"key1", ..,},}') + func test(): foo({"key1": "value1", "key2": "value2"}) foo({"key1": "value1", "key2": ""}) @@ -41,3 +59,6 @@ func test(): bar({1: "1"}) bar({2: "2"}) bar({3: "3"}) + baz({"key1": "value1"}) + baz({"key2": "value2"}) + baz({"key3": {"key1": "value1", "key2": "value2"}}) diff --git a/modules/gdscript/tests/scripts/parser/features/match_dictionary.out b/modules/gdscript/tests/scripts/parser/features/match_dictionary.out index 4dee886927..f9adcbd331 100644 --- a/modules/gdscript/tests/scripts/parser/features/match_dictionary.out +++ b/modules/gdscript/tests/scripts/parser/features/match_dictionary.out @@ -13,3 +13,6 @@ wildcard 1 2 wildcard +multiline {"key1": "value1"} +multiline {"key2": "value2",} +multiline {"key3": {"key1", ..,},} diff --git a/modules/gdscript/tests/scripts/parser/features/static_typing.out b/modules/gdscript/tests/scripts/parser/features/static_typing.out index 40a8f97416..d73c5eb7cd 100644 --- a/modules/gdscript/tests/scripts/parser/features/static_typing.out +++ b/modules/gdscript/tests/scripts/parser/features/static_typing.out @@ -1,21 +1 @@ GDTEST_OK ->> WARNING ->> Line: 11 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_INTEGER" is declared but never used in the block. If this is intended, prefix it with an underscore: "__INTEGER". ->> WARNING ->> Line: 12 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_INTEGER_REDUNDANT_TYPED" is declared but never used in the block. If this is intended, prefix it with an underscore: "__INTEGER_REDUNDANT_TYPED". ->> WARNING ->> Line: 13 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_INTEGER_REDUNDANT_TYPED2" is declared but never used in the block. If this is intended, prefix it with an underscore: "__INTEGER_REDUNDANT_TYPED2". ->> WARNING ->> Line: 14 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_INTEGER_REDUNDANT_INFERRED" is declared but never used in the block. If this is intended, prefix it with an underscore: "__INTEGER_REDUNDANT_INFERRED". ->> WARNING ->> Line: 15 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_INTEGER_REDUNDANT_INFERRED2" is declared but never used in the block. If this is intended, prefix it with an underscore: "__INTEGER_REDUNDANT_INFERRED2". diff --git a/modules/gdscript/tests/scripts/parser/warnings/unassigned_variable.gd b/modules/gdscript/tests/scripts/parser/warnings/unassigned_variable.gd index afb5059eea..b38cffb754 100644 --- a/modules/gdscript/tests/scripts/parser/warnings/unassigned_variable.gd +++ b/modules/gdscript/tests/scripts/parser/warnings/unassigned_variable.gd @@ -1,2 +1,11 @@ func test(): - var __ + var unassigned + print(unassigned) + unassigned = "something" # Assigned only after use. + + var a + print(a) # Unassigned, warn. + if a: # Still unassigned, warn. + a = 1 + print(a) # Assigned (dead code), don't warn. + print(a) # "Maybe" assigned, don't warn. diff --git a/modules/gdscript/tests/scripts/parser/warnings/unassigned_variable.out b/modules/gdscript/tests/scripts/parser/warnings/unassigned_variable.out index 10f89be132..36db304ef4 100644 --- a/modules/gdscript/tests/scripts/parser/warnings/unassigned_variable.out +++ b/modules/gdscript/tests/scripts/parser/warnings/unassigned_variable.out @@ -1,5 +1,16 @@ GDTEST_OK >> WARNING ->> Line: 2 +>> Line: 3 >> UNASSIGNED_VARIABLE ->> The variable "__" was used but never assigned a value. +>> The variable "unassigned" was used before being assigned a value. +>> WARNING +>> Line: 7 +>> UNASSIGNED_VARIABLE +>> The variable "a" was used before being assigned a value. +>> WARNING +>> Line: 8 +>> UNASSIGNED_VARIABLE +>> The variable "a" was used before being assigned a value. +<null> +<null> +<null> diff --git a/modules/gdscript/tests/scripts/parser/warnings/unused_constant.gd b/modules/gdscript/tests/scripts/parser/warnings/unused_constant.gd new file mode 100644 index 0000000000..3d355197e1 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/warnings/unused_constant.gd @@ -0,0 +1,4 @@ +func test(): + const UNUSED = "not used" + + const _UNUSED = "not used, but no warning since the constant name starts with an underscore" diff --git a/modules/gdscript/tests/scripts/parser/warnings/unused_constant.out b/modules/gdscript/tests/scripts/parser/warnings/unused_constant.out new file mode 100644 index 0000000000..99ced48433 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/warnings/unused_constant.out @@ -0,0 +1,5 @@ +GDTEST_OK +>> WARNING +>> Line: 2 +>> UNUSED_LOCAL_CONSTANT +>> The local constant "UNUSED" is declared but never used in the block. If this is intended, prefix it with an underscore: "_UNUSED". |