diff options
Diffstat (limited to 'modules/gdscript/tests/scripts/runtime')
12 files changed, 168 insertions, 0 deletions
diff --git a/modules/gdscript/tests/scripts/runtime/features/assign_operator.gd b/modules/gdscript/tests/scripts/runtime/features/assign_operator.gd new file mode 100644 index 0000000000..2a9fe851ef --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/assign_operator.gd @@ -0,0 +1,31 @@ +# https://github.com/godotengine/godot/issues/75832 + +@warning_ignore("narrowing_conversion") +func test(): + var hf := 2.0 + var sf = 2.0 + + var i := 2 + i *= hf + i *= sf + i *= 2.0 + print(i) + var v2 := Vector2i(1, 2) + v2 *= hf + v2 *= sf + v2 *= 2.0 + print(v2) + var v3 := Vector3i(1, 2, 3) + v3 *= hf + v3 *= sf + v3 *= 2.0 + print(v3) + var v4 := Vector4i(1, 2, 3, 4) + v4 *= hf + v4 *= sf + v4 *= 2.0 + print(v4) + + var arr := [1, 2, 3] + arr += [4, 5] + print(arr) diff --git a/modules/gdscript/tests/scripts/runtime/features/assign_operator.out b/modules/gdscript/tests/scripts/runtime/features/assign_operator.out new file mode 100644 index 0000000000..bfcfc1dff5 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/assign_operator.out @@ -0,0 +1,6 @@ +GDTEST_OK +16 +(8, 16) +(8, 16, 24) +(8, 16, 24, 32) +[1, 2, 3, 4, 5] diff --git a/modules/gdscript/tests/scripts/runtime/features/getter_with_freed_object.gd b/modules/gdscript/tests/scripts/runtime/features/getter_with_freed_object.gd new file mode 100644 index 0000000000..a2d09bf7d3 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/getter_with_freed_object.gd @@ -0,0 +1,15 @@ +# https://github.com/godotengine/godot/issues/68184 + +var node: Node: + get: + return node + set(n): + node = n + + +func test(): + node = Node.new() + node.free() + + if !is_instance_valid(node): + print("It is freed") diff --git a/modules/gdscript/tests/scripts/runtime/features/getter_with_freed_object.out b/modules/gdscript/tests/scripts/runtime/features/getter_with_freed_object.out new file mode 100644 index 0000000000..b380f593d9 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/getter_with_freed_object.out @@ -0,0 +1,2 @@ +GDTEST_OK +It is freed diff --git a/modules/gdscript/tests/scripts/runtime/features/static_constructor.gd b/modules/gdscript/tests/scripts/runtime/features/static_constructor.gd new file mode 100644 index 0000000000..e08f77df12 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/static_constructor.gd @@ -0,0 +1,13 @@ +@static_unload + +static var foo = "bar" + +static func _static_init(): + print("static init called") + prints("foo is", foo) + +func test(): + var _lambda = func _static_init(): + print("lambda does not conflict with static constructor") + + print("done") diff --git a/modules/gdscript/tests/scripts/runtime/features/static_constructor.out b/modules/gdscript/tests/scripts/runtime/features/static_constructor.out new file mode 100644 index 0000000000..7f72a0ac2c --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/static_constructor.out @@ -0,0 +1,4 @@ +GDTEST_OK +static init called +foo is bar +done diff --git a/modules/gdscript/tests/scripts/runtime/features/static_variables.gd b/modules/gdscript/tests/scripts/runtime/features/static_variables.gd new file mode 100644 index 0000000000..e193312381 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/static_variables.gd @@ -0,0 +1,56 @@ +@static_unload + +static var perm := 0 + +static var prop := "Hello!": + get: return prop + " suffix" + set(value): prop = "prefix " + str(value) + +static func get_data(): + return "data" + +static var data = get_data() + +class Inner: + static var prop := "inner" + static func _static_init() -> void: + prints("Inner._static_init", prop) + + class InnerInner: + static var prop := "inner inner" + static func _static_init() -> void: + prints("InnerInner._static_init", prop) + +func test(): + prints("data:", data) + + prints("perm:", perm) + prints("prop:", prop) + + perm = 1 + prop = "World!" + + prints("perm:", perm) + prints("prop:", prop) + + print("other.perm:", StaticVariablesOther.perm) + print("other.prop:", StaticVariablesOther.prop) + + StaticVariablesOther.perm = 2 + StaticVariablesOther.prop = "foo" + + print("other.perm:", StaticVariablesOther.perm) + print("other.prop:", StaticVariablesOther.prop) + + @warning_ignore("unsafe_method_access") + var path = get_script().get_path().get_base_dir() + var other = load(path + "/static_variables_load.gd") + + print("load.perm:", other.perm) + print("load.prop:", other.prop) + + other.perm = 3 + other.prop = "bar" + + print("load.perm:", other.perm) + print("load.prop:", other.prop) diff --git a/modules/gdscript/tests/scripts/runtime/features/static_variables.out b/modules/gdscript/tests/scripts/runtime/features/static_variables.out new file mode 100644 index 0000000000..d2491aef5e --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/static_variables.out @@ -0,0 +1,16 @@ +GDTEST_OK +Inner._static_init inner +InnerInner._static_init inner inner +data: data +perm: 0 +prop: prefix Hello! suffix +perm: 1 +prop: prefix World! suffix +other.perm:0 +other.prop:prefix Hello! suffix +other.perm:2 +other.prop:prefix foo suffix +load.perm:0 +load.prop:prefix Hello! suffix +load.perm:3 +load.prop:prefix bar suffix diff --git a/modules/gdscript/tests/scripts/runtime/features/static_variables_load.gd b/modules/gdscript/tests/scripts/runtime/features/static_variables_load.gd new file mode 100644 index 0000000000..8913b02756 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/static_variables_load.gd @@ -0,0 +1,10 @@ +@static_unload + +static var perm := 0 + +static var prop := "Hello!": + get: return prop + " suffix" + set(value): prop = "prefix " + str(value) + +func test(): + print("ok") diff --git a/modules/gdscript/tests/scripts/runtime/features/static_variables_load.out b/modules/gdscript/tests/scripts/runtime/features/static_variables_load.out new file mode 100644 index 0000000000..1b47ed10dc --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/static_variables_load.out @@ -0,0 +1,2 @@ +GDTEST_OK +ok diff --git a/modules/gdscript/tests/scripts/runtime/features/static_variables_other.gd b/modules/gdscript/tests/scripts/runtime/features/static_variables_other.gd new file mode 100644 index 0000000000..7a3b0acca6 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/static_variables_other.gd @@ -0,0 +1,11 @@ +@static_unload +class_name StaticVariablesOther + +static var perm := 0 + +static var prop := "Hello!": + get: return prop + " suffix" + set(value): prop = "prefix " + str(value) + +func test(): + print("ok") diff --git a/modules/gdscript/tests/scripts/runtime/features/static_variables_other.out b/modules/gdscript/tests/scripts/runtime/features/static_variables_other.out new file mode 100644 index 0000000000..1b47ed10dc --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/static_variables_other.out @@ -0,0 +1,2 @@ +GDTEST_OK +ok |