`async_trait` se re-exporta desde `pagetop` y se añade al preludio; ya no es necesario declararlo como dependencia en las extensiones. `initialize()` es ahora verdaderamente `async` (con `.await`), y `Application::new()` y `prepare()` pasan también a ser funciones `async`.
62 lines
1.6 KiB
Rust
62 lines
1.6 KiB
Rust
use pagetop::prelude::*;
|
|
|
|
async fn setup() {
|
|
Application::new().await;
|
|
}
|
|
|
|
#[pagetop::test]
|
|
async fn literal_text() {
|
|
setup().await;
|
|
|
|
let l10n = L10n::n("© 2025 PageTop");
|
|
assert_eq!(l10n.get(), Some("© 2025 PageTop".to_string()));
|
|
}
|
|
|
|
#[pagetop::test]
|
|
async fn translation_without_args() {
|
|
setup().await;
|
|
|
|
let l10n = L10n::l("test_hello_world");
|
|
let translation = l10n.lookup(&Locale::resolve("es-ES"));
|
|
assert_eq!(translation, Some("¡Hola mundo!".to_string()));
|
|
}
|
|
|
|
#[pagetop::test]
|
|
async fn translation_with_args() {
|
|
setup().await;
|
|
|
|
let l10n = L10n::l("test_hello_user").with_arg("userName", "Manuel");
|
|
let translation = l10n.lookup(&Locale::resolve("es-ES"));
|
|
assert_eq!(translation, Some("¡Hola, Manuel!".to_string()));
|
|
}
|
|
|
|
#[pagetop::test]
|
|
async fn translation_with_plural_and_select() {
|
|
setup().await;
|
|
|
|
let l10n = L10n::l("test_shared_photos").with_args(vec![
|
|
("userName", "Roberto"),
|
|
("photoCount", "3"),
|
|
("userGender", "male"),
|
|
]);
|
|
let translation = l10n.lookup(&Locale::resolve("es-ES")).unwrap();
|
|
assert!(translation.contains("añadido 3 nuevas fotos de él"));
|
|
}
|
|
|
|
#[pagetop::test]
|
|
async fn check_fallback_language() {
|
|
setup().await;
|
|
|
|
let l10n = L10n::l("test_hello_world");
|
|
let translation = l10n.lookup(&Locale::resolve("xx-YY")); // Retrocede a "en-US".
|
|
assert_eq!(translation, Some("Hello world!".to_string()));
|
|
}
|
|
|
|
#[pagetop::test]
|
|
async fn check_unknown_key() {
|
|
setup().await;
|
|
|
|
let l10n = L10n::l("non-existent-key");
|
|
let translation = l10n.lookup(&Locale::resolve("en-US"));
|
|
assert_eq!(translation, None);
|
|
}
|