Skip to content

Commit

Permalink
chore: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Leandros committed Oct 16, 2024
1 parent 4da13cb commit 00f41b9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions ferrunix/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ mod common;
#[cfg(feature = "derive")]
mod derive_simple;
mod manual;
mod manual_non_object_safe;
mod manual_traits;
mod validate_traits;
34 changes: 34 additions & 0 deletions ferrunix/tests/it/manual_non_object_safe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use ferrunix::Registry;

#[derive(Debug, Default, PartialEq, PartialOrd, Hash)]
struct ExampleStruct {
num: u32,
some_string: String,
}

trait NotObjectSafe {
fn returns(&self) -> Self; // ERROR: Self in return type
}

impl NotObjectSafe for ExampleStruct {
fn returns(&self) -> Self {
Self {
num: 1,
some_string: "2".to_owned(),
}
}
}

#[test]
fn can_store_objecs_impl_non_object_safe_traits() {
let registry = Registry::empty();
registry.transient(|| ExampleStruct {
num: 0,
some_string: "1".to_owned(),
});

let example = registry.get_transient::<ExampleStruct>().unwrap();
let ret = example.returns();
assert_eq!(ret.num, 1);
assert_eq!(ret.some_string, "2");
}

0 comments on commit 00f41b9

Please sign in to comment.