Browse Source

Add more integration tests to the GDScript test suite

This also fixes a typo in the `bitwise_float_right_operand.gd` test.
Hugo Locurcio 4 năm trước cách đây
mục cha
commit
c6ca09dc6f
30 tập tin đã thay đổi với 245 bổ sung2 xóa
  1. 1 1
      modules/gdscript/tests/scripts/analyzer/errors/bitwise_float_right_operand.gd
  2. 1 1
      modules/gdscript/tests/scripts/analyzer/errors/bitwise_float_right_operand.out
  3. 2 0
      modules/gdscript/tests/scripts/analyzer/features/static_method_builtin_type.gd
  4. 2 0
      modules/gdscript/tests/scripts/analyzer/features/static_method_builtin_type.out
  5. 3 0
      modules/gdscript/tests/scripts/parser/errors/brace_syntax.gd
  6. 2 0
      modules/gdscript/tests/scripts/parser/errors/brace_syntax.out
  7. 2 0
      modules/gdscript/tests/scripts/parser/errors/invalid_escape_sequence.gd
  8. 2 0
      modules/gdscript/tests/scripts/parser/errors/invalid_escape_sequence.out
  9. 5 0
      modules/gdscript/tests/scripts/parser/errors/invalid_ternary_operator.gd
  10. 2 0
      modules/gdscript/tests/scripts/parser/errors/invalid_ternary_operator.out
  11. 13 0
      modules/gdscript/tests/scripts/parser/errors/vcs_conflict_marker.gd
  12. 2 0
      modules/gdscript/tests/scripts/parser/errors/vcs_conflict_marker.out
  13. 7 0
      modules/gdscript/tests/scripts/parser/features/export_variable.gd
  14. 3 0
      modules/gdscript/tests/scripts/parser/features/export_variable.out
  15. 5 0
      modules/gdscript/tests/scripts/parser/features/function_default_parameter_type_inference.gd
  16. 2 0
      modules/gdscript/tests/scripts/parser/features/function_default_parameter_type_inference.out
  17. 5 0
      modules/gdscript/tests/scripts/parser/features/function_many_parameters.gd
  18. 2 0
      modules/gdscript/tests/scripts/parser/features/function_many_parameters.out
  19. 4 0
      modules/gdscript/tests/scripts/parser/features/lambda_callable.gd
  20. 2 0
      modules/gdscript/tests/scripts/parser/features/lambda_callable.out
  21. 4 0
      modules/gdscript/tests/scripts/parser/features/lambda_capture_callable.gd
  22. 2 0
      modules/gdscript/tests/scripts/parser/features/lambda_capture_callable.out
  23. 10 0
      modules/gdscript/tests/scripts/parser/features/lambda_named_callable.gd
  24. 3 0
      modules/gdscript/tests/scripts/parser/features/lambda_named_callable.out
  25. 5 0
      modules/gdscript/tests/scripts/parser/features/nested_function_calls.gd
  26. 2 0
      modules/gdscript/tests/scripts/parser/features/nested_function_calls.out
  27. 5 0
      modules/gdscript/tests/scripts/parser/features/typed_arrays.gd
  28. 3 0
      modules/gdscript/tests/scripts/parser/features/typed_arrays.out
  29. 19 0
      modules/gdscript/tests/scripts/runtime/features/recursion.gd
  30. 125 0
      modules/gdscript/tests/scripts/runtime/features/recursion.out

+ 1 - 1
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)

+ 1 - 1
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.

+ 2 - 0
modules/gdscript/tests/scripts/analyzer/features/static_method_builtin_type.gd

@@ -0,0 +1,2 @@
+func test():
+	print(Color.html_is_valid("00ffff"))

+ 2 - 0
modules/gdscript/tests/scripts/analyzer/features/static_method_builtin_type.out

@@ -0,0 +1,2 @@
+GDTEST_OK
+true

+ 3 - 0
modules/gdscript/tests/scripts/parser/errors/brace_syntax.gd

@@ -0,0 +1,3 @@
+func test() {
+	print("Hello world!");
+}

+ 2 - 0
modules/gdscript/tests/scripts/parser/errors/brace_syntax.out

@@ -0,0 +1,2 @@
+GDTEST_PARSER_ERROR
+Expected ":" after function declaration.

+ 2 - 0
modules/gdscript/tests/scripts/parser/errors/invalid_escape_sequence.gd

@@ -0,0 +1,2 @@
+func test():
+	var escape = "invalid escape \h <- here"

+ 2 - 0
modules/gdscript/tests/scripts/parser/errors/invalid_escape_sequence.out

@@ -0,0 +1,2 @@
+GDTEST_PARSER_ERROR
+Invalid escape in string.

+ 5 - 0
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"

+ 2 - 0
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".

+ 13 - 0
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

+ 2 - 0
modules/gdscript/tests/scripts/parser/errors/vcs_conflict_marker.out

@@ -0,0 +1,2 @@
+GDTEST_PARSER_ERROR
+Unexpected "VCS conflict marker" in class body.

+ 7 - 0
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)

+ 3 - 0
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

+ 5 - 0
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))

+ 2 - 0
modules/gdscript/tests/scripts/parser/features/function_default_parameter_type_inference.out

@@ -0,0 +1,2 @@
+GDTEST_OK
+10

+ 5 - 0
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)

+ 2 - 0
modules/gdscript/tests/scripts/parser/features/function_many_parameters.out

@@ -0,0 +1,2 @@
+GDTEST_OK
+123456789101112131415161718192212223242526272829303132333435363738394041424344454647falsetruenull

+ 4 - 0
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")

+ 2 - 0
modules/gdscript/tests/scripts/parser/features/lambda_callable.out

@@ -0,0 +1,2 @@
+GDTEST_OK
+hello

+ 4 - 0
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".

+ 2 - 0
modules/gdscript/tests/scripts/parser/features/lambda_capture_callable.out

@@ -0,0 +1,2 @@
+GDTEST_OK
+42

+ 10 - 0
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")

+ 3 - 0
modules/gdscript/tests/scripts/parser/features/lambda_named_callable.out

@@ -0,0 +1,3 @@
+GDTEST_OK
+Hello
+This is a lambda

+ 5 - 0
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)))))))))))))))))))))))))

+ 2 - 0
modules/gdscript/tests/scripts/parser/features/nested_function_calls.out

@@ -0,0 +1,2 @@
+GDTEST_OK
+24

+ 5 - 0
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)

+ 3 - 0
modules/gdscript/tests/scripts/parser/features/typed_arrays.out

@@ -0,0 +1,3 @@
+GDTEST_OK
+[1, 2, 3]
+[1, 2, 3]

+ 19 - 0
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))

+ 125 - 0
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