Skip to content

Commit

Permalink
Tests for StringName (conversions, Eq, Ord)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bromeon committed Jul 17, 2022
1 parent e2ad37c commit 1583953
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
45 changes: 45 additions & 0 deletions gdnative-core/src/core_types/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::core_types::Variant;
use crate::object::NewRef;
use crate::private::get_api;
use crate::sys;
use std::cmp::Ordering;

use std::ffi::CStr;
use std::fmt;
Expand Down Expand Up @@ -728,3 +729,47 @@ godot_test!(test_string {
assert_eq!(fmt2, GodotString::from("foo bar"));
assert_eq!(fmt_string2, GodotString::from("{0} {1}"));
});

godot_test!(test_string_name_eq {
use crate::core_types::{GodotString, StringName};

let a: StringName = StringName::from_str("some string");
let b: StringName = StringName::from_godot_string(&GodotString::from("some string"));
let c: StringName = StringName::from_str(String::from("some other string"));
let d: StringName = StringName::from_str("yet another one");

// test Eq
assert_eq!(a, b);
assert_ne!(a, c);
assert_ne!(a, d);
assert_ne!(b, c);
assert_ne!(b, d);
assert_ne!(c, d);

let back = b.to_godot_string();
assert_eq!(back, GodotString::from("some string"));
});

godot_test!(test_string_name_ord {
use crate::core_types::{GodotString, StringName};

let a: StringName = StringName::from_str("some string");
let b: StringName = StringName::from_godot_string(&GodotString::from("some string"));
let c: StringName = StringName::from_str(String::from("some other string"));

// test Ord
let a_b = Ord::cmp(&a, &b);
let b_a = Ord::cmp(&b, &a);
assert_eq!(a_b, Ordering::Equal);
assert_eq!(b_a, Ordering::Equal);

let a_c = Ord::cmp(&a, &c);
let c_a = Ord::cmp(&c, &a);
let b_c = Ord::cmp(&b, &c);
let c_b = Ord::cmp(&c, &b);
assert_ne!(a_c, Ordering::Equal);
assert_eq!(a_c, b_c);
assert_eq!(c_a, c_b);
assert_eq!(a_c, c_a.reverse());
assert_eq!(b_c, c_b.reverse());
});
2 changes: 2 additions & 0 deletions test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub extern "C" fn run_tests(
) -> gdnative::sys::godot_variant {
let mut status = true;
status &= gdnative::core_types::test_string();
status &= gdnative::core_types::test_string_name_eq();
status &= gdnative::core_types::test_string_name_ord();

status &= gdnative::core_types::test_dictionary();
// status &= gdnative::test_dictionary_clone_clear();
Expand Down

0 comments on commit 1583953

Please sign in to comment.