From 57fefcc945ddd25585c0408edf8cb872aa12b430 Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Tue, 14 Dec 2021 18:28:10 +0530 Subject: [PATCH] Improved Documentation Added some doc tests as examples. --- src/klocalizedcontext.rs | 17 +++++++++++++++++ src/klocalizedstring.rs | 8 ++++++++ tests/klocalizedcontext_tests.rs | 8 -------- tests/klocalizedstring_tests.rs | 1 - 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/klocalizedcontext.rs b/src/klocalizedcontext.rs index 7b9d37a..e1b46f8 100644 --- a/src/klocalizedcontext.rs +++ b/src/klocalizedcontext.rs @@ -22,6 +22,14 @@ cpp_class!( impl KLocalizedContext { /// Initialize KLocalizedContext from Engine. + /// #Example + /// ``` + /// use ki18n_rs::klocalizedcontext::KLocalizedContext; + /// use qmetaobject::prelude::*; + /// + /// let engine = QmlEngine::new(); + /// KLocalizedContext::init_from_engine(&engine); + /// ``` pub fn init_from_engine(engine: &QmlEngine) -> Self { let engine_ptr = engine.cpp_ptr(); cpp!(unsafe [engine_ptr as "QQmlEngine*"] -> KLocalizedContext as "KLocalizedContextHolder" { @@ -40,6 +48,15 @@ impl KLocalizedContext { } /// Set Translation Domain for current KLocalizedContext. + /// # Example + /// ``` + /// use ki18n_rs::klocalizedcontext::KLocalizedContext; + /// use qmetaobject::prelude::*; + /// + /// let engine = QmlEngine::new(); + /// let mut context = KLocalizedContext::init_from_engine(&engine); + /// context.set_translation_domain("Test Domain".into()); + /// ``` pub fn set_translation_domain(&mut self, domain: QString) { cpp!(unsafe [self as "KLocalizedContextHolder *", domain as "QString"] { self->klocalized->setTranslationDomain(domain); diff --git a/src/klocalizedstring.rs b/src/klocalizedstring.rs index d0e7872..c08396f 100644 --- a/src/klocalizedstring.rs +++ b/src/klocalizedstring.rs @@ -16,6 +16,14 @@ cpp_class!( impl KLocalizedString { /// Set Application Domain + /// # Example + /// ``` + /// use std::ffi::CString; + /// use ki18n_rs::prelude::KLocalizedString; + /// + /// let domain = CString::new("Application_Domain").unwrap(); + /// KLocalizedString::set_application_domain(&domain); + /// ``` pub fn set_application_domain(domain: &CStr) { let domain_ptr = domain.as_ptr(); cpp!(unsafe [domain_ptr as "char*"] { diff --git a/tests/klocalizedcontext_tests.rs b/tests/klocalizedcontext_tests.rs index 0ff2cfc..7467a92 100644 --- a/tests/klocalizedcontext_tests.rs +++ b/tests/klocalizedcontext_tests.rs @@ -2,14 +2,6 @@ use ki18n_rs::klocalizedcontext::KLocalizedContext; use qmetaobject::prelude::*; mod common; -#[test] -fn init_engine() { - let _lock = common::lock_for_test(); - - let engine = QmlEngine::new(); - KLocalizedContext::init_from_engine(&engine); -} - #[test] fn cpp_ptr() { let _lock = common::lock_for_test(); diff --git a/tests/klocalizedstring_tests.rs b/tests/klocalizedstring_tests.rs index 38d29dc..cae9fb8 100644 --- a/tests/klocalizedstring_tests.rs +++ b/tests/klocalizedstring_tests.rs @@ -8,7 +8,6 @@ fn application_domain() { KLocalizedString::set_application_domain(&domain); let domain = KLocalizedString::application_domain(); - println!("{:#?}", domain); assert_eq!(domain.to_str().unwrap(), "KI18n"); }