Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

1.8 KB
Raw Blame
class Foo:
	const NAME: StringName = String("Barrel T.")

	static var foo: StringName = String("1")
	var bar: String = &"1"

	func _init():
		Utils.check(typeof(NAME) == TYPE_STRING_NAME)
		Utils.check(NAME == &"Barrel T.")

		Utils.check(typeof(foo) == TYPE_STRING_NAME)
		Utils.check(foo == &"1")

		foo = String("2")
		Utils.check(typeof(foo) == TYPE_STRING_NAME)
		Utils.check(foo == &"2")

		Utils.check(typeof(bar) == TYPE_STRING)
		Utils.check(bar == "1")

		bar = &"2"
		Utils.check(typeof(bar) == TYPE_STRING)
		Utils.check(bar == "2")


func test_external_property_typed(f: Foo):
	f.foo = String("3")
	Utils.check(typeof(f.foo) == TYPE_STRING_NAME)
	Utils.check(f.foo == &"3")

	f.bar = NodePath("3")
	Utils.check(typeof(f.bar) == TYPE_STRING)
	Utils.check(f.bar == "3")


func test_external_property_untyped_assignee(f):
	f.foo = "4"
	Utils.check(typeof(f.foo) == TYPE_STRING_NAME)
	Utils.check(f.foo == &"4")

	f.bar = StringName("4")
	Utils.check(typeof(f.bar) == TYPE_STRING)
	Utils.check(f.bar == "4")


func _make_untyped(value: String, type):
	match type:
		TYPE_STRING:
			return String(value)
		TYPE_STRING_NAME:
			return StringName(value)
	return null

func test_external_property_untyped_value(f: Foo):
	f.foo = _make_untyped("5", TYPE_STRING)
	Utils.check(typeof(f.foo) == TYPE_STRING_NAME)
	Utils.check(f.foo == &"5")

	f.bar = _make_untyped("5", TYPE_STRING_NAME)
	Utils.check(typeof(f.bar) == TYPE_STRING)
	Utils.check(f.bar == "5")


func test_static(cls):
	Foo.foo = String("6")
	Utils.check(typeof(Foo.foo) == TYPE_STRING_NAME)
	Utils.check(Foo.foo == &"6")

	cls.foo = String("7")
	Utils.check(typeof(cls.foo) == TYPE_STRING_NAME)
	Utils.check(cls.foo == &"7")


func test():
	var foo := Foo.new()

	test_external_property_typed(foo)
	test_external_property_untyped_assignee(foo)
	test_external_property_untyped_value(foo)
	test_static(Foo)

	print('ok')