From c38d117b5803c65ad57a4c4704ee0d897d9fb3cb Mon Sep 17 00:00:00 2001 From: copi143 Date: Sat, 17 Jan 2026 04:02:47 +0800 Subject: init --- test/Cargo.toml | 13 +++++++++ test/lang/src.toml | 14 ++++++++++ test/src/main.rs | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 test/Cargo.toml create mode 100644 test/lang/src.toml create mode 100644 test/src/main.rs (limited to 'test') diff --git a/test/Cargo.toml b/test/Cargo.toml new file mode 100644 index 0000000..0735f93 --- /dev/null +++ b/test/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "static-l10n-test" +version = "0.0.1" +edition = "2024" +publish = false + +[package.metadata.static-l10n] +path = "lang" +base = "en" +langs = ["en", "es", { name = "fr", fallback = "en" }, "zh-cn"] + +[dependencies] +static-l10n = { path = "../derive" } diff --git a/test/lang/src.toml b/test/lang/src.toml new file mode 100644 index 0000000..dedc083 --- /dev/null +++ b/test/lang/src.toml @@ -0,0 +1,14 @@ +["Hello, world!"] +zh-cn = "你好,世界!" +es = "¡Hola, mundo!" +fr = "Bonjour le monde!" + +["Hello, {}!"] +zh-cn = "你好,{}!" +es = "¡Hola, {}!" +fr = "Bonjour, {}!" + +["Hello, {name}!"] +zh-cn = "你好,{name}!" +es = "¡Hola, {name}!" +fr = "Bonjour, {name}!" diff --git a/test/src/main.rs b/test/src/main.rs new file mode 100644 index 0000000..fa28d00 --- /dev/null +++ b/test/src/main.rs @@ -0,0 +1,79 @@ +use static_l10n::{f16n, l10n}; + +static_l10n::main!(); + +fn main() { + static_l10n::debug_print_metadata!(); + static_l10n::lang!("zh-cn"); + println!("{}", l10n!("Hello, world!")); + println!("{}", f16n!("Hello, {}!", "Rust")); + println!("{}", f16n!("Hello, {name}!", name = "World")); +} + +#[cfg(test)] +mod tests { + use super::*; + use std::fmt::Write; + + #[test] + fn l10n_basic_lookup() { + static_l10n::lang!("es"); + assert_eq!(l10n!("Hello, world!"), "¡Hola, mundo!"); + static_l10n::lang!("fr"); + assert_eq!(l10n!("Hello, world!"), "Bonjour le monde!"); + } + + #[test] + fn f16n_formatting() { + static_l10n::lang!("zh-cn"); + assert_eq!(f16n!("Hello, {}!", "Rust"), "你好,Rust!"); + assert_eq!(f16n!("Hello, {name}!", name = "World"), "你好,World!"); + } + + #[test] + fn args_macros() { + static_l10n::lang!("en"); + let msg = format!("{}", static_l10n::l10n_args!("Hello, world!")); + assert_eq!(msg, "Hello, world!"); + let msg = format!("{}", static_l10n::f16n_args!("Hello, {}!", "Rust")); + assert_eq!(msg, "Hello, Rust!"); + } + + #[test] + fn write_macros() { + static_l10n::lang!("es"); + let mut buf = String::new(); + static_l10n::l10n_write!(&mut buf, "Hello, world!"); + assert_eq!(buf, "¡Hola, mundo!"); + + let mut buf = String::new(); + static_l10n::l10n_writeln!(&mut buf, "Hello, world!"); + assert_eq!(buf, "¡Hola, mundo!\n"); + + let mut buf = String::new(); + static_l10n::f16n_write!(&mut buf, "Hello, {}!", "Rust"); + assert_eq!(buf, "¡Hola, Rust!"); + + let mut buf = String::new(); + static_l10n::f16n_writeln!(&mut buf, "Hello, {}!", "Rust"); + assert_eq!(buf, "¡Hola, Rust!\n"); + } + + #[test] + fn assert_macros() { + static_l10n::lang!("en"); + static_l10n::l10n_assert!(1 + 1 == 2, "Hello, world!"); + static_l10n::l10n_assert_eq!(2 + 2, 4, "Hello, world!"); + static_l10n::l10n_assert_ne!(2 + 2, 5, "Hello, world!"); + static_l10n::l10n_debug_assert!(true, "Hello, world!"); + static_l10n::l10n_debug_assert_eq!(3, 3, "Hello, world!"); + static_l10n::l10n_debug_assert_ne!(3, 4, "Hello, world!"); + + static_l10n::f16n_assert!(1 + 1 == 2, "Hello, {}!", "Rust"); + static_l10n::f16n_assert_eq!(2 + 2, 4, "Hello, {}!", "Rust"); + static_l10n::f16n_assert_ne!(2 + 2, 5, "Hello, {}!", "Rust"); + static_l10n::f16n_debug_assert!(true, "Hello, {}!", "Rust"); + static_l10n::f16n_debug_assert_eq!(3, 3, "Hello, {}!", "Rust"); + static_l10n::f16n_debug_assert_ne!(3, 4, "Hello, {}!", "Rust"); + } +} -- cgit