summaryrefslogtreecommitdiff
path: root/server/common/src/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/common/src/tests.rs')
-rw-r--r--server/common/src/tests.rs170
1 files changed, 169 insertions, 1 deletions
diff --git a/server/common/src/tests.rs b/server/common/src/tests.rs
index 9ce44c8..29ee6d6 100644
--- a/server/common/src/tests.rs
+++ b/server/common/src/tests.rs
@@ -1,4 +1,4 @@
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
use testdir::testdir;
use tokio::fs;
use tokio::sync::OnceCell;
@@ -808,3 +808,171 @@ fn test_grit_get_message_id() {
7770247413830876286,
)
}
+
+#[tokio::test]
+async fn test_grit_parse_xlf() {
+ let basepath = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("src/testdata/grit/translations");
+ let en_gb = grit::parse_xlf(basepath.join(Path::new("base_en_gb.xlf")))
+ .await
+ .unwrap();
+ assert_eq!(
+ en_gb,
+ grit::TranslationFile {
+ target_language: "en-gb".to_string(),
+ units: vec![
+ grit::TranslationUnit {
+ id: 8820817407110198400,
+ target: vec![grit::TextPlaceholder::Text("Bookmarks".to_string()),],
+ },
+ grit::TranslationUnit {
+ id: 8443102241046796905,
+ target: vec![
+ grit::TextPlaceholder::Text("Welcome to ".to_string()),
+ grit::TextPlaceholder::Placeholder {
+ name: "STRING".to_string(),
+ content: String::new(),
+ example: None,
+ },
+ ],
+ },
+ grit::TranslationUnit {
+ id: 2466140279568640908,
+ target: vec![
+ grit::TextPlaceholder::Text(
+ "By using this application you are agreeing to Opera's ".to_string(),
+ ),
+ grit::TextPlaceholder::Placeholder {
+ name: "TOS_BEGIN".to_string(),
+ content: String::new(),
+ example: None,
+ },
+ grit::TextPlaceholder::Text("Terms of Service".to_string(),),
+ grit::TextPlaceholder::Placeholder {
+ name: "TOS_END".to_string(),
+ content: String::new(),
+ example: None,
+ },
+ grit::TextPlaceholder::Text(
+ ". Also, you can learn how Opera handles and protects your data in our "
+ .to_string(),
+ ),
+ grit::TextPlaceholder::Placeholder {
+ name: "PRIVACY_BEGIN".to_string(),
+ content: String::new(),
+ example: None,
+ },
+ grit::TextPlaceholder::Text("Privacy Statement".to_string(),),
+ grit::TextPlaceholder::Placeholder {
+ name: "PRIVACY_END".to_string(),
+ content: String::new(),
+ example: None,
+ },
+ grit::TextPlaceholder::Text(".".to_string(),),
+ ],
+ },
+ grit::TranslationUnit {
+ id: 7770247413830876286,
+ target: vec![
+ grit::TextPlaceholder::Text(
+ "{BOOKMARKS, plural,\n one {".to_string(),
+ ),
+ grit::TextPlaceholder::Placeholder {
+ name: "COUNT".to_string(),
+ content: String::new(),
+ example: None,
+ },
+ grit::TextPlaceholder::Text(
+ " folder deleted}\n few {".to_string(),
+ ),
+ grit::TextPlaceholder::Placeholder {
+ name: "COUNT".to_string(),
+ content: String::new(),
+ example: None,
+ },
+ grit::TextPlaceholder::Text(
+ " folders deleted}\n many {".to_string(),
+ ),
+ grit::TextPlaceholder::Placeholder {
+ name: "COUNT".to_string(),
+ content: String::new(),
+ example: None,
+ },
+ grit::TextPlaceholder::Text(
+ " folders deleted}\n other {".to_string(),
+ ),
+ grit::TextPlaceholder::Placeholder {
+ name: "COUNT".to_string(),
+ content: String::new(),
+ example: None,
+ },
+ grit::TextPlaceholder::Text(" folders deleted}}".to_string(),),
+ ],
+ },
+ ],
+ },
+ );
+
+ let sv = grit::parse_xlf(basepath.join(Path::new("base_sv.xlf")))
+ .await
+ .unwrap();
+ assert_eq!(
+ sv,
+ grit::TranslationFile {
+ target_language: "sv".to_string(),
+ units: vec![
+ grit::TranslationUnit {
+ id: 8820817407110198400,
+ target: vec![
+ grit::TextPlaceholder::Text("Bokmärken".to_string()),
+ ],
+ },
+ grit::TranslationUnit {
+ id: 8443102241046796905,
+ target: vec![
+ grit::TextPlaceholder::Text("Välkommen till ".to_string()),
+ grit::TextPlaceholder::Placeholder {
+ name: "STRING".to_string(),
+ content: String::new(),
+ example: None,
+ },
+ ],
+ },
+ grit::TranslationUnit {
+ id: 2466140279568640908,
+ target: vec![
+ grit::TextPlaceholder::Text(
+ "I och med din användning av det här programmet samtycker du till Operas ".to_string(),
+ ),
+ grit::TextPlaceholder::Placeholder {
+ name: "TOS_BEGIN".to_string(),
+ content: String::new(),
+ example: None,
+ },
+ grit::TextPlaceholder::Text("Licensvillkor".to_string(),),
+ grit::TextPlaceholder::Placeholder {
+ name: "TOS_END".to_string(),
+ content: String::new(),
+ example: None,
+ },
+ grit::TextPlaceholder::Text(
+ ". Du kan också läsa om hur Opera hanterar och skyddar dina data i vårt "
+ .to_string(),
+ ),
+ grit::TextPlaceholder::Placeholder {
+ name: "PRIVACY_BEGIN".to_string(),
+ content: String::new(),
+ example: None,
+ },
+ grit::TextPlaceholder::Text("Sekretessmeddelande".to_string(),),
+ grit::TextPlaceholder::Placeholder {
+ name: "PRIVACY_END".to_string(),
+ content: String::new(),
+ example: None,
+ },
+ grit::TextPlaceholder::Text(".".to_string(),),
+ ],
+ },
+ ],
+ },
+ )
+}