summaryrefslogtreecommitdiff
path: root/modules/gdscript/tests/scripts/runtime
diff options
context:
space:
mode:
authorrune-scape <allie.smith.epic@gmail.com>2022-12-05 21:46:47 -0500
committerrune-scape <allie.smith.epic@gmail.com>2022-12-05 21:46:47 -0500
commite79be6ce07ed8c89011f759ecade070a3bd5a806 (patch)
treefbe13a625acf7630c4a5aeb4a8664e6c67472818 /modules/gdscript/tests/scripts/runtime
parentf3e6750a7e4702918e05f42b1376e30e652f2f90 (diff)
Unify String and StringName
Diffstat (limited to 'modules/gdscript/tests/scripts/runtime')
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.gd35
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.out11
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/dictionary_string_stringname_equivalent.gd17
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/dictionary_string_stringname_equivalent.out6
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/match_string_stringname_equivalent.gd14
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/match_string_stringname_equivalent.out3
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/string_stringname_equivalent.gd11
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/string_stringname_equivalent.out8
8 files changed, 105 insertions, 0 deletions
diff --git a/modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.gd b/modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.gd
new file mode 100644
index 0000000000..5303fb04e2
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.gd
@@ -0,0 +1,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] = []
+
+ assert(!string_array.push_back(&"abc"))
+ print("Array[String] insert converted: ", typeof(string_array[0]) == TYPE_STRING)
+
+ assert(!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)
+
+ assert(!string_array.push_back("abc"))
+ print("StringName finds String in Array: ", string_array.find(&"abc"))
+
+ assert(!stringname_array.push_back(&"abc"))
+ print("String finds StringName in Array: ", stringname_array.find("abc"))
diff --git a/modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.out b/modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.out
new file mode 100644
index 0000000000..98ab78e8f1
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.out
@@ -0,0 +1,11 @@
+GDTEST_OK
+StringName in Array: true
+String in Array: true
+Arrays not equal: true
+Array[String] insert converted: true
+Array[StringName] insert converted: true
+StringName in Array[String]: true
+String in Array[StringName]: true
+StringName in PackedStringArray: true
+StringName finds String in Array: 0
+String finds StringName in Array: 0
diff --git a/modules/gdscript/tests/scripts/runtime/features/dictionary_string_stringname_equivalent.gd b/modules/gdscript/tests/scripts/runtime/features/dictionary_string_stringname_equivalent.gd
new file mode 100644
index 0000000000..1f15026f17
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/dictionary_string_stringname_equivalent.gd
@@ -0,0 +1,17 @@
+# https://github.com/godotengine/godot/issues/62957
+
+func test():
+ var string_dict = {}
+ string_dict["abc"] = 42
+ var stringname_dict = {}
+ stringname_dict[&"abc"] = 24
+
+ print("String key is TYPE_STRING: ", typeof(string_dict.keys()[0]) == TYPE_STRING)
+ print("StringName key is TYPE_STRING: ", typeof(stringname_dict.keys()[0]) == TYPE_STRING)
+
+ print("StringName gets String: ", string_dict.get(&"abc"))
+ print("String gets StringName: ", stringname_dict.get("abc"))
+
+ stringname_dict[&"abc"] = 42
+ # They compare equal because StringName keys are converted to String.
+ print("String Dictionary == StringName Dictionary: ", string_dict == stringname_dict)
diff --git a/modules/gdscript/tests/scripts/runtime/features/dictionary_string_stringname_equivalent.out b/modules/gdscript/tests/scripts/runtime/features/dictionary_string_stringname_equivalent.out
new file mode 100644
index 0000000000..ab5b89d55c
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/dictionary_string_stringname_equivalent.out
@@ -0,0 +1,6 @@
+GDTEST_OK
+String key is TYPE_STRING: true
+StringName key is TYPE_STRING: true
+StringName gets String: 42
+String gets StringName: 24
+String Dictionary == StringName Dictionary: true
diff --git a/modules/gdscript/tests/scripts/runtime/features/match_string_stringname_equivalent.gd b/modules/gdscript/tests/scripts/runtime/features/match_string_stringname_equivalent.gd
new file mode 100644
index 0000000000..55be021a90
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/match_string_stringname_equivalent.gd
@@ -0,0 +1,14 @@
+# https://github.com/godotengine/godot/issues/60145
+
+func test():
+ match "abc":
+ &"abc":
+ print("String matched StringName")
+ _:
+ print("no match")
+
+ match &"abc":
+ "abc":
+ print("StringName matched String")
+ _:
+ print("no match")
diff --git a/modules/gdscript/tests/scripts/runtime/features/match_string_stringname_equivalent.out b/modules/gdscript/tests/scripts/runtime/features/match_string_stringname_equivalent.out
new file mode 100644
index 0000000000..9d5a18da3d
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/match_string_stringname_equivalent.out
@@ -0,0 +1,3 @@
+GDTEST_OK
+String matched StringName
+StringName matched String
diff --git a/modules/gdscript/tests/scripts/runtime/features/string_stringname_equivalent.gd b/modules/gdscript/tests/scripts/runtime/features/string_stringname_equivalent.gd
new file mode 100644
index 0000000000..f8bd46523e
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/string_stringname_equivalent.gd
@@ -0,0 +1,11 @@
+# https://github.com/godotengine/godot/issues/64171
+
+func test():
+ print("Compare ==: ", "abc" == &"abc")
+ print("Compare ==: ", &"abc" == "abc")
+ print("Compare !=: ", "abc" != &"abc")
+ print("Compare !=: ", &"abc" != "abc")
+
+ print("Concat: ", "abc" + &"def")
+ print("Concat: ", &"abc" + "def")
+ print("Concat: ", &"abc" + &"def")
diff --git a/modules/gdscript/tests/scripts/runtime/features/string_stringname_equivalent.out b/modules/gdscript/tests/scripts/runtime/features/string_stringname_equivalent.out
new file mode 100644
index 0000000000..7e9c364b60
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/string_stringname_equivalent.out
@@ -0,0 +1,8 @@
+GDTEST_OK
+Compare ==: true
+Compare ==: true
+Compare !=: false
+Compare !=: false
+Concat: abcdef
+Concat: abcdef
+Concat: abcdef