#![cfg(feature = "alloc")] use crate::derive::Language; use std::borrow::Cow; mod common; mod derive { #![no_implicit_prelude] use ::typed_i18n::TypedI18N; #[derive(Copy, Clone, TypedI18N)] #[typed_i18n(filename = "example.yaml")] #[typed_i18n(builder = "_")] pub enum Language { En, De, } } #[test] fn string() { assert_eq!(Language::En.hello_world::(), "Hello world"); assert_eq!(Language::De.hello_world::(), "Hallo Welt"); assert_eq!( Language::En.hello_you::("you"), "Hello you".to_string() ); assert_eq!(Language::En.maybe_note::(), ""); assert_eq!(Language::De.maybe_note::(), "Hinweis"); } #[test] fn cow() { assert_eq!( Language::En.hello_world::>(), Cow::Borrowed("Hello world") ); assert_eq!( Language::De.hello_world::>(), Cow::Borrowed("Hallo Welt") ); assert_eq!( Language::En.hello_you::>("you"), Cow::<'static, str>::Owned("Hello you".to_string()) ); assert_eq!( Language::En.maybe_note::>(), Cow::Borrowed("") ); assert_eq!( Language::De.maybe_note::>(), Cow::Borrowed("Hinweis") ); }