summaryrefslogtreecommitdiffstats
path: root/modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.gd
blob: bd38259cec58e156ccd21901c5990f3ae080aac2 (plain)
1
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
# https://github.com/godotengine/godot/issues/63965

func test():
	var array_str: Array = []
	array_str.push_back("godot")
	print("StringName in Array: ", &"godot" in array_str)

	var array_sname: Array = []
	array_sname.push_back(&"godot")
	print("String in Array: ", "godot" in array_sname)

	# Not equal because the values are different types.
	print("Arrays not equal: ", array_str != array_sname)

	var string_array: Array[String] = []
	var stringname_array: Array[StringName] = []

	string_array.push_back(&"abc")
	print("Array[String] insert converted: ", typeof(string_array[0]) == TYPE_STRING)

	stringname_array.push_back("abc")
	print("Array[StringName] insert converted: ", typeof(stringname_array[0]) == TYPE_STRING_NAME)

	print("StringName in Array[String]: ", &"abc" in string_array)
	print("String in Array[StringName]: ", "abc" in stringname_array)

	var packed_string_array: PackedStringArray = []
	assert(!packed_string_array.push_back("abc"))
	print("StringName in PackedStringArray: ", &"abc" in packed_string_array)

	string_array.push_back("abc")
	print("StringName finds String in Array: ", string_array.find(&"abc"))

	stringname_array.push_back(&"abc")
	print("String finds StringName in Array: ", stringname_array.find("abc"))