#![allow(non_snake_case)] extern crate he_di; #[macro_use] extern crate he_di_derive; use he_di::ContainerBuilder; use he_di::Error as DIError; use he_di::container::ValidatorError; trait Foo : ::std::fmt::Debug { fn foo(&self); } #[derive(Component, Debug)] #[interface(Foo)] struct FooImpl { value: String, } impl Foo for FooImpl { fn foo(&self) { println!("FooImpl > foo > value = {}", self.value); } } #[test] fn invalid_registration_no_as_type() { let mut builder = ContainerBuilder::new(); builder.register::(); let container = builder.build(); assert!(&container.is_err()); if let DIError::RegistrationError(err) = container.unwrap_err() { let expected_msg = "invalid entry: Component 'FooImpl' hasn't been registered to a type (use `as_trait()` in the registration chain)".to_string(); assert_eq!(err, ValidatorError::EmptyValue(expected_msg)); } else { panic!("invalid state > container should be a RegistrationError"); } }