summaryrefslogtreecommitdiffstats
path: root/modules/gdscript/tests/scripts/parser
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdscript/tests/scripts/parser')
-rw-r--r--modules/gdscript/tests/scripts/parser/errors/lambda_no_continue_on_new_line.gd6
-rw-r--r--modules/gdscript/tests/scripts/parser/errors/lambda_no_continue_on_new_line.out2
-rw-r--r--modules/gdscript/tests/scripts/parser/errors/multiple_number_separators.gd2
-rw-r--r--modules/gdscript/tests/scripts/parser/errors/multiple_number_separators.out2
-rw-r--r--modules/gdscript/tests/scripts/parser/errors/multiple_number_separators_after_decimal.gd3
-rw-r--r--modules/gdscript/tests/scripts/parser/errors/multiple_number_separators_after_decimal.out2
-rw-r--r--modules/gdscript/tests/scripts/parser/features/lambda_ends_with_new_line.gd59
-rw-r--r--modules/gdscript/tests/scripts/parser/features/lambda_ends_with_new_line.out25
-rw-r--r--modules/gdscript/tests/scripts/parser/features/number_literals_with_sign.gd17
-rw-r--r--modules/gdscript/tests/scripts/parser/features/number_literals_with_sign.out16
-rw-r--r--modules/gdscript/tests/scripts/parser/features/number_separators.gd32
-rw-r--r--modules/gdscript/tests/scripts/parser/features/number_separators.out23
12 files changed, 178 insertions, 11 deletions
diff --git a/modules/gdscript/tests/scripts/parser/errors/lambda_no_continue_on_new_line.gd b/modules/gdscript/tests/scripts/parser/errors/lambda_no_continue_on_new_line.gd
new file mode 100644
index 0000000000..8c5fb46109
--- /dev/null
+++ b/modules/gdscript/tests/scripts/parser/errors/lambda_no_continue_on_new_line.gd
@@ -0,0 +1,6 @@
+# https://github.com/godotengine/godot/issues/73273
+
+func not_called():
+ var v
+ v=func(): v=1
+ in v
diff --git a/modules/gdscript/tests/scripts/parser/errors/lambda_no_continue_on_new_line.out b/modules/gdscript/tests/scripts/parser/errors/lambda_no_continue_on_new_line.out
new file mode 100644
index 0000000000..539240f790
--- /dev/null
+++ b/modules/gdscript/tests/scripts/parser/errors/lambda_no_continue_on_new_line.out
@@ -0,0 +1,2 @@
+GDTEST_PARSER_ERROR
+Expected statement, found "in" instead.
diff --git a/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators.gd b/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators.gd
index 71a03fbc0d..f322783776 100644
--- a/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators.gd
+++ b/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators.gd
@@ -1,3 +1,3 @@
func test():
# Number separators may not be placed right next to each other.
- var __ = 1__23
+ var _num = 1__23
diff --git a/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators.out b/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators.out
index 71a3c2fd6a..b308994ae2 100644
--- a/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators.out
+++ b/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators.out
@@ -1,2 +1,2 @@
GDTEST_PARSER_ERROR
-Only one underscore can be used as a numeric separator.
+Multiple underscores cannot be adjacent in a numeric literal.
diff --git a/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators_after_decimal.gd b/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators_after_decimal.gd
new file mode 100644
index 0000000000..3140999aa9
--- /dev/null
+++ b/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators_after_decimal.gd
@@ -0,0 +1,3 @@
+func test():
+ # Number separators may not be placed right next to each other.
+ var _num = 123.45__67
diff --git a/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators_after_decimal.out b/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators_after_decimal.out
new file mode 100644
index 0000000000..b308994ae2
--- /dev/null
+++ b/modules/gdscript/tests/scripts/parser/errors/multiple_number_separators_after_decimal.out
@@ -0,0 +1,2 @@
+GDTEST_PARSER_ERROR
+Multiple underscores cannot be adjacent in a numeric literal.
diff --git a/modules/gdscript/tests/scripts/parser/features/lambda_ends_with_new_line.gd b/modules/gdscript/tests/scripts/parser/features/lambda_ends_with_new_line.gd
new file mode 100644
index 0000000000..df6001c7e2
--- /dev/null
+++ b/modules/gdscript/tests/scripts/parser/features/lambda_ends_with_new_line.gd
@@ -0,0 +1,59 @@
+# https://github.com/godotengine/godot/issues/73273
+
+func other(callable : Callable):
+ callable.call()
+
+func four_parameters(_a, callable : Callable, b=func(): print(10)):
+ callable.call()
+ b.call()
+
+func test():
+ var v
+ v=func():v=1
+ if true: v=1
+ print(v)
+ print()
+
+ v=func(): print(2) if false else print(3)
+ @warning_ignore("unsafe_cast")
+ (v as Callable).call()
+ print()
+
+ v=func():
+ print(4)
+ print(5)
+ @warning_ignore("unsafe_cast")
+ if true: (v as Callable).call()
+ print()
+
+ other(v)
+ print()
+
+ other(func(): print(6))
+ print()
+
+ other(func():
+ print(7)
+ print(8)
+ )
+ print()
+
+ four_parameters(1,func():print(9))
+ four_parameters(1,func():print(9), func(): print(11))
+ four_parameters(1,func():
+ print(12)
+ print(13)
+ , func(): print(11))
+ print()
+
+ from_ticket()
+
+func from_ticket():
+ var _v
+ if true: _v = (func(): test())
+ if true: _v = (func(): test())
+ if true: _v = (func(): test())
+
+ if true: _v = func(): test()
+ if true: _v = func(): test()
+ print(14)
diff --git a/modules/gdscript/tests/scripts/parser/features/lambda_ends_with_new_line.out b/modules/gdscript/tests/scripts/parser/features/lambda_ends_with_new_line.out
new file mode 100644
index 0000000000..4347310960
--- /dev/null
+++ b/modules/gdscript/tests/scripts/parser/features/lambda_ends_with_new_line.out
@@ -0,0 +1,25 @@
+GDTEST_OK
+1
+
+3
+
+4
+5
+
+4
+5
+
+6
+
+7
+8
+
+9
+10
+9
+11
+12
+13
+11
+
+14
diff --git a/modules/gdscript/tests/scripts/parser/features/number_literals_with_sign.gd b/modules/gdscript/tests/scripts/parser/features/number_literals_with_sign.gd
new file mode 100644
index 0000000000..cf7fb1518c
--- /dev/null
+++ b/modules/gdscript/tests/scripts/parser/features/number_literals_with_sign.gd
@@ -0,0 +1,17 @@
+func test():
+ print(-9223372036854775808 == (1 << 63))
+ print(-2)
+ print(- 2)
+ print(---2)
+ print(3 - 2)
+ print(3-2)
+ print(3---2)
+ print(-3 - 2)
+ print(-3 - -2)
+ print(-(3 - 2)-2)
+ print([1, 2, 3][0]-1)
+ var t = 1
+ print(t-1)
+ print(-0xFF)
+ print(1--0xFF)
+ print(floor(PI-1))
diff --git a/modules/gdscript/tests/scripts/parser/features/number_literals_with_sign.out b/modules/gdscript/tests/scripts/parser/features/number_literals_with_sign.out
new file mode 100644
index 0000000000..c5958365ec
--- /dev/null
+++ b/modules/gdscript/tests/scripts/parser/features/number_literals_with_sign.out
@@ -0,0 +1,16 @@
+GDTEST_OK
+true
+-2
+-2
+-2
+1
+1
+1
+-5
+-1
+-3
+0
+0
+-255
+256
+2
diff --git a/modules/gdscript/tests/scripts/parser/features/number_separators.gd b/modules/gdscript/tests/scripts/parser/features/number_separators.gd
index f5f5661cae..a534c4fde1 100644
--- a/modules/gdscript/tests/scripts/parser/features/number_separators.gd
+++ b/modules/gdscript/tests/scripts/parser/features/number_separators.gd
@@ -1,12 +1,26 @@
func test():
# `_` can be used as a separator for numbers in GDScript.
# It can be placed anywhere in the number, except at the beginning.
- # Currently, GDScript in the `master` branch only allows using one separator
- # per number.
- # Results are assigned to variables to avoid warnings.
- var __ = 1_23
- __ = 123_ # Trailing number separators are OK.
- __ = 12_3
- __ = 123_456
- __ = 0x1234_5678
- __ = 0b1001_0101
+ print(1_23)
+ print(12_3)
+ print(1_2_3)
+ print(123_) # Trailing number separators are OK.
+ print(123_456)
+ print(123_45_6_)
+ print("---")
+ print(0x1234_00ff)
+ print(0x1234_00_f_f_)
+ print(0b1001_0101)
+ print(0b1001_01_0_1_)
+ print("---")
+ print(-1_234.456_7)
+ print(-1_23_4_.4_56_7_)
+ print(-1_234.)
+ print(-1_23_4_.)
+ print(.456_7)
+ print(.4_56_7_)
+ print("---")
+ print(-1_234.5e000_3)
+ print(-1_23_4_.5e0_00_3_)
+ print(-1_234.5e+000_3)
+ print(-1_23_4_.5e+0_00_3_)
diff --git a/modules/gdscript/tests/scripts/parser/features/number_separators.out b/modules/gdscript/tests/scripts/parser/features/number_separators.out
index d73c5eb7cd..b0d2fd94fe 100644
--- a/modules/gdscript/tests/scripts/parser/features/number_separators.out
+++ b/modules/gdscript/tests/scripts/parser/features/number_separators.out
@@ -1 +1,24 @@
GDTEST_OK
+123
+123
+123
+123
+123456
+123456
+---
+305398015
+305398015
+149
+149
+---
+-1234.4567
+-1234.4567
+-1234
+-1234
+0.4567
+0.4567
+---
+-1234500
+-1234500
+-1234500
+-1234500