diff options
Diffstat (limited to 'modules/gdscript/tests')
30 files changed, 245 insertions, 2 deletions
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/bitwise_float_right_operand.gd b/modules/gdscript/tests/scripts/analyzer/errors/bitwise_float_right_operand.gd index 4502960105..0a4f647f57 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/bitwise_float_right_operand.gd +++ b/modules/gdscript/tests/scripts/analyzer/errors/bitwise_float_right_operand.gd @@ -1,3 +1,3 @@ func test(): # Error here. - print(2 << 4.4) + print(2 >> 4.4) diff --git a/modules/gdscript/tests/scripts/analyzer/errors/bitwise_float_right_operand.out b/modules/gdscript/tests/scripts/analyzer/errors/bitwise_float_right_operand.out index 1879fc1adf..1edbf47ec0 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/bitwise_float_right_operand.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/bitwise_float_right_operand.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Invalid operands to operator <<, int and float. +Invalid operands to operator >>, int and float. diff --git a/modules/gdscript/tests/scripts/analyzer/features/static_method_builtin_type.gd b/modules/gdscript/tests/scripts/analyzer/features/static_method_builtin_type.gd new file mode 100644 index 0000000000..569f95850f --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/static_method_builtin_type.gd @@ -0,0 +1,2 @@ +func test(): + print(Color.html_is_valid("00ffff")) diff --git a/modules/gdscript/tests/scripts/analyzer/features/static_method_builtin_type.out b/modules/gdscript/tests/scripts/analyzer/features/static_method_builtin_type.out new file mode 100644 index 0000000000..55482c2b52 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/static_method_builtin_type.out @@ -0,0 +1,2 @@ +GDTEST_OK +true diff --git a/modules/gdscript/tests/scripts/parser/errors/brace_syntax.gd b/modules/gdscript/tests/scripts/parser/errors/brace_syntax.gd new file mode 100644 index 0000000000..ab66537c93 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/brace_syntax.gd @@ -0,0 +1,3 @@ +func test() { + print("Hello world!"); +} diff --git a/modules/gdscript/tests/scripts/parser/errors/brace_syntax.out b/modules/gdscript/tests/scripts/parser/errors/brace_syntax.out new file mode 100644 index 0000000000..2f37a740ab --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/brace_syntax.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +Expected ":" after function declaration. diff --git a/modules/gdscript/tests/scripts/parser/errors/invalid_escape_sequence.gd b/modules/gdscript/tests/scripts/parser/errors/invalid_escape_sequence.gd new file mode 100644 index 0000000000..3b52f6e324 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/invalid_escape_sequence.gd @@ -0,0 +1,2 @@ +func test(): + var escape = "invalid escape \h <- here" diff --git a/modules/gdscript/tests/scripts/parser/errors/invalid_escape_sequence.out b/modules/gdscript/tests/scripts/parser/errors/invalid_escape_sequence.out new file mode 100644 index 0000000000..32b4d004db --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/invalid_escape_sequence.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +Invalid escape in string. diff --git a/modules/gdscript/tests/scripts/parser/errors/invalid_ternary_operator.gd b/modules/gdscript/tests/scripts/parser/errors/invalid_ternary_operator.gd new file mode 100644 index 0000000000..c835ce15e1 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/invalid_ternary_operator.gd @@ -0,0 +1,5 @@ +func test(): + var amount = 50 + # C-style ternary operator is invalid in GDScript. + # The valid syntax is `"yes" if amount < 60 else "no"`, like in Python. + var ternary = amount < 60 ? "yes" : "no" diff --git a/modules/gdscript/tests/scripts/parser/errors/invalid_ternary_operator.out b/modules/gdscript/tests/scripts/parser/errors/invalid_ternary_operator.out new file mode 100644 index 0000000000..ac82d691b7 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/invalid_ternary_operator.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +Unexpected "?" in source. If you want a ternary operator, use "truthy_value if true_condition else falsy_value". diff --git a/modules/gdscript/tests/scripts/parser/errors/vcs_conflict_marker.gd b/modules/gdscript/tests/scripts/parser/errors/vcs_conflict_marker.gd new file mode 100644 index 0000000000..8850892f2d --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/vcs_conflict_marker.gd @@ -0,0 +1,13 @@ +# The VCS conflict marker has only 6 `=` signs instead of 7 to prevent editors like +# Visual Studio Code from recognizing it as an actual VCS conflict marker. +# Nonetheless, the GDScript parser is still expected to find and report the VCS +# conflict marker error correctly. + +<<<<<<< HEAD +Hello world +====== +Goodbye +>>>>>>> 77976da35a11db4580b80ae27e8d65caf5208086 + +func test(): + pass diff --git a/modules/gdscript/tests/scripts/parser/errors/vcs_conflict_marker.out b/modules/gdscript/tests/scripts/parser/errors/vcs_conflict_marker.out new file mode 100644 index 0000000000..df9dab2223 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/vcs_conflict_marker.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +Unexpected "VCS conflict marker" in class body. diff --git a/modules/gdscript/tests/scripts/parser/features/export_variable.gd b/modules/gdscript/tests/scripts/parser/features/export_variable.gd index 51e7d4a8ed..1e072728fc 100644 --- a/modules/gdscript/tests/scripts/parser/features/export_variable.gd +++ b/modules/gdscript/tests/scripts/parser/features/export_variable.gd @@ -3,9 +3,16 @@ @export_range(0, 100, 1) var example_range_step = 101 @export_range(0, 100, 1, "or_greater") var example_range_step_or_greater = 102 +@export var color: Color +@export_color_no_alpha var color_no_alpha: Color +@export_node_path(Sprite2D, Sprite3D, Control, Node) var nodepath := ^"hello" + func test(): print(example) print(example_range) print(example_range_step) print(example_range_step_or_greater) + print(color) + print(color_no_alpha) + print(nodepath) diff --git a/modules/gdscript/tests/scripts/parser/features/export_variable.out b/modules/gdscript/tests/scripts/parser/features/export_variable.out index b455196359..bae35e75c6 100644 --- a/modules/gdscript/tests/scripts/parser/features/export_variable.out +++ b/modules/gdscript/tests/scripts/parser/features/export_variable.out @@ -3,3 +3,6 @@ GDTEST_OK 100 101 102 +(0, 0, 0, 1) +(0, 0, 0, 1) +hello diff --git a/modules/gdscript/tests/scripts/parser/features/function_default_parameter_type_inference.gd b/modules/gdscript/tests/scripts/parser/features/function_default_parameter_type_inference.gd new file mode 100644 index 0000000000..f5098b00ae --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/function_default_parameter_type_inference.gd @@ -0,0 +1,5 @@ +func example(_number: int, _number2: int = 5, number3 := 10): + return number3 + +func test(): + print(example(3)) diff --git a/modules/gdscript/tests/scripts/parser/features/function_default_parameter_type_inference.out b/modules/gdscript/tests/scripts/parser/features/function_default_parameter_type_inference.out new file mode 100644 index 0000000000..404cd41fe5 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/function_default_parameter_type_inference.out @@ -0,0 +1,2 @@ +GDTEST_OK +10 diff --git a/modules/gdscript/tests/scripts/parser/features/function_many_parameters.gd b/modules/gdscript/tests/scripts/parser/features/function_many_parameters.gd new file mode 100644 index 0000000000..01edb37cec --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/function_many_parameters.gd @@ -0,0 +1,5 @@ +func example(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23, arg24, arg25, arg26, arg27, arg28, arg29, arg30, arg31, arg32, arg33, arg34, arg35, arg36, arg37, arg38, arg39, arg40, arg41, arg42, arg43, arg44, arg45, arg46, arg47, arg48 = false, arg49 = true, arg50 = null): + print(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23, arg24, arg25, arg26, arg27, arg28, arg29, arg30, arg31, arg32, arg33, arg34, arg35, arg36, arg37, arg38, arg39, arg40, arg41, arg42, arg43, arg44, arg45, arg46, arg47, arg48, arg49, arg50) + +func test(): + example(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47) diff --git a/modules/gdscript/tests/scripts/parser/features/function_many_parameters.out b/modules/gdscript/tests/scripts/parser/features/function_many_parameters.out new file mode 100644 index 0000000000..3a979227d4 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/function_many_parameters.out @@ -0,0 +1,2 @@ +GDTEST_OK +123456789101112131415161718192212223242526272829303132333435363738394041424344454647falsetruenull diff --git a/modules/gdscript/tests/scripts/parser/features/lambda_callable.gd b/modules/gdscript/tests/scripts/parser/features/lambda_callable.gd new file mode 100644 index 0000000000..c3b2506156 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/lambda_callable.gd @@ -0,0 +1,4 @@ +func test(): + var my_lambda = func(x): + print(x) + my_lambda.call("hello") diff --git a/modules/gdscript/tests/scripts/parser/features/lambda_callable.out b/modules/gdscript/tests/scripts/parser/features/lambda_callable.out new file mode 100644 index 0000000000..58774d2d3f --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/lambda_callable.out @@ -0,0 +1,2 @@ +GDTEST_OK +hello diff --git a/modules/gdscript/tests/scripts/parser/features/lambda_capture_callable.gd b/modules/gdscript/tests/scripts/parser/features/lambda_capture_callable.gd new file mode 100644 index 0000000000..f081a0b6a7 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/lambda_capture_callable.gd @@ -0,0 +1,4 @@ +func test(): + var x = 42 + var my_lambda = func(): print(x) + my_lambda.call() # Prints "42". diff --git a/modules/gdscript/tests/scripts/parser/features/lambda_capture_callable.out b/modules/gdscript/tests/scripts/parser/features/lambda_capture_callable.out new file mode 100644 index 0000000000..0982f3718c --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/lambda_capture_callable.out @@ -0,0 +1,2 @@ +GDTEST_OK +42 diff --git a/modules/gdscript/tests/scripts/parser/features/lambda_named_callable.gd b/modules/gdscript/tests/scripts/parser/features/lambda_named_callable.gd new file mode 100644 index 0000000000..7971ca72a6 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/lambda_named_callable.gd @@ -0,0 +1,10 @@ +func i_take_lambda(lambda: Callable, param: String): + lambda.call(param) + + +func test(): + var my_lambda := func this_is_lambda(x): + print("Hello") + print("This is %s" % x) + + i_take_lambda(my_lambda, "a lambda") diff --git a/modules/gdscript/tests/scripts/parser/features/lambda_named_callable.out b/modules/gdscript/tests/scripts/parser/features/lambda_named_callable.out new file mode 100644 index 0000000000..c627187d82 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/lambda_named_callable.out @@ -0,0 +1,3 @@ +GDTEST_OK +Hello +This is a lambda diff --git a/modules/gdscript/tests/scripts/parser/features/nested_function_calls.gd b/modules/gdscript/tests/scripts/parser/features/nested_function_calls.gd new file mode 100644 index 0000000000..59cdc7d6c2 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/nested_function_calls.gd @@ -0,0 +1,5 @@ +func foo(x): + return x + 1 + +func test(): + print(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(0))))))))))))))))))))))))) diff --git a/modules/gdscript/tests/scripts/parser/features/nested_function_calls.out b/modules/gdscript/tests/scripts/parser/features/nested_function_calls.out new file mode 100644 index 0000000000..28a6636a7b --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/nested_function_calls.out @@ -0,0 +1,2 @@ +GDTEST_OK +24 diff --git a/modules/gdscript/tests/scripts/parser/features/typed_arrays.gd b/modules/gdscript/tests/scripts/parser/features/typed_arrays.gd new file mode 100644 index 0000000000..21bf3fdfcf --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/typed_arrays.gd @@ -0,0 +1,5 @@ +func test(): + var my_array: Array[int] = [1, 2, 3] + var inferred_array := [1, 2, 3] # This is Array[int]. + print(my_array) + print(inferred_array) diff --git a/modules/gdscript/tests/scripts/parser/features/typed_arrays.out b/modules/gdscript/tests/scripts/parser/features/typed_arrays.out new file mode 100644 index 0000000000..953d54d5e0 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/typed_arrays.out @@ -0,0 +1,3 @@ +GDTEST_OK +[1, 2, 3] +[1, 2, 3] diff --git a/modules/gdscript/tests/scripts/runtime/features/recursion.gd b/modules/gdscript/tests/scripts/runtime/features/recursion.gd new file mode 100644 index 0000000000..a35485022e --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/recursion.gd @@ -0,0 +1,19 @@ +func is_prime(number: int, divisor: int = 2) -> bool: + print(divisor) + if number <= 2: + return (number == 2) + elif number % divisor == 0: + return false + elif divisor * divisor > number: + return true + + return is_prime(number, divisor + 1) + +func test(): + # Not a prime number. + print(is_prime(989)) + + print() + + # Largest prime number below 10000. + print(is_prime(9973)) diff --git a/modules/gdscript/tests/scripts/runtime/features/recursion.out b/modules/gdscript/tests/scripts/runtime/features/recursion.out new file mode 100644 index 0000000000..2bd8f24988 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/recursion.out @@ -0,0 +1,125 @@ +GDTEST_OK +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +false + +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +true |