Skip to content

Commit 3e63a35

Browse files
committed
Tests for StringName (conversions, Eq, Ord)
1 parent 659ac47 commit 3e63a35

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

gdnative-core/src/core_types/string.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::core_types::Variant;
22
use crate::object::NewRef;
33
use crate::private::get_api;
44
use crate::sys;
5+
use std::cmp::Ordering;
56

67
use std::ffi::CStr;
78
use std::fmt;
@@ -728,3 +729,47 @@ godot_test!(test_string {
728729
assert_eq!(fmt2, GodotString::from("foo bar"));
729730
assert_eq!(fmt_string2, GodotString::from("{0} {1}"));
730731
});
732+
733+
godot_test!(test_string_name_eq {
734+
use crate::core_types::{GodotString, StringName};
735+
736+
let a: StringName = StringName::from_str("some string");
737+
let b: StringName = StringName::from_godot_string(&GodotString::from("some string"));
738+
let c: StringName = StringName::from_str(String::from("some other string"));
739+
let d: StringName = StringName::from_str("yet another one");
740+
741+
// test Eq
742+
assert_eq!(a, b);
743+
assert_ne!(a, c);
744+
assert_ne!(a, d);
745+
assert_ne!(b, c);
746+
assert_ne!(b, d);
747+
assert_ne!(c, d);
748+
749+
let back = b.to_godot_string();
750+
assert_eq!(back, GodotString::from("some string"));
751+
});
752+
753+
godot_test!(test_string_name_ord {
754+
use crate::core_types::{GodotString, StringName};
755+
756+
let a: StringName = StringName::from_str("some string");
757+
let b: StringName = StringName::from_godot_string(&GodotString::from("some string"));
758+
let c: StringName = StringName::from_str(String::from("some other string"));
759+
760+
// test Ord
761+
let a_b = Ord::cmp(&a, &b);
762+
let b_a = Ord::cmp(&b, &a);
763+
assert_eq!(a_b, Ordering::Equal);
764+
assert_eq!(b_a, Ordering::Equal);
765+
766+
let a_c = Ord::cmp(&a, &c);
767+
let c_a = Ord::cmp(&c, &a);
768+
let b_c = Ord::cmp(&b, &c);
769+
let c_b = Ord::cmp(&c, &b);
770+
assert_ne!(a_c, Ordering::Equal);
771+
assert_eq!(a_c, b_c);
772+
assert_eq!(c_a, c_b);
773+
assert_eq!(a_c, c_a.reverse());
774+
assert_eq!(b_c, c_b.reverse());
775+
});

test/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ pub extern "C" fn run_tests(
2424
) -> gdnative::sys::godot_variant {
2525
let mut status = true;
2626
status &= gdnative::core_types::test_string();
27+
status &= gdnative::core_types::test_string_name_eq();
28+
status &= gdnative::core_types::test_string_name_ord();
2729

2830
status &= gdnative::core_types::test_dictionary();
2931
// status &= gdnative::test_dictionary_clone_clear();

0 commit comments

Comments
 (0)