oxedyne/fe2o3/fe2o3_text/tests/csl_archive.rs
2.9 KiB, 1 run
created by r1870400018:73158, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | use oxedyne_fe2o3_text::csl::{ |
| 2 | archive, |
| 3 | style::TermForm, |
| 4 | }; |
| 5 | |
| 6 | use oxedyne_fe2o3_core::prelude::*; |
| 7 | |
| 8 | |
| 9 | #[test] |
| 10 | fn csl_archive_every_style_resolves_parses_and_matches_its_updated() -> Outcome<()> { |
| 11 | let mut n = 0; |
| 12 | for a in archive::styles() { |
| 13 | for name in a.names { |
| 14 | let b = res!(archive::by_name(name).ok_or_else(|| err!( |
| 15 | "Style name '{}' does not resolve.", name; Missing))); |
| 16 | assert_eq!(b.stem, a.stem); |
| 17 | } |
| 18 | let b = res!(archive::by_id(a.id).ok_or_else(|| err!( |
| 19 | "Style id '{}' does not resolve.", a.id; Missing))); |
| 20 | assert_eq!(b.stem, a.stem); |
| 21 | let style = res!(a.style()); |
| 22 | assert_eq!(style.info.id.as_str(), a.id); |
| 23 | assert_eq!(style.info.updated.as_str(), a.updated); |
| 24 | assert_eq!(a.path(), format!("styles/{}.csl", a.stem)); |
| 25 | n += 1; |
| 26 | } |
| 27 | assert_eq!(n, 80); |
| 28 | assert!(archive::by_name("no-such-style").is_none()); |
| 29 | Ok(()) |
| 30 | } |
| 31 | |
| 32 | #[test] |
| 33 | fn csl_archive_every_locale_parses_under_its_own_code() -> Outcome<()> { |
| 34 | assert_eq!(archive::locale_codes().len(), 63); |
| 35 | for code in archive::locale_codes() { |
| 36 | let loc = res!(res!(archive::locale(code)).ok_or_else(|| err!( |
| 37 | "Locale '{}' is not embedded.", code; Missing))); |
| 38 | assert_eq!(loc.lang.as_deref(), Some(*code)); |
| 39 | } |
| 40 | assert!(res!(archive::locale("xx-XX")).is_none()); |
| 41 | assert!(archive::locales_json().contains("primary-dialects")); |
| 42 | Ok(()) |
| 43 | } |
| 44 | |
| 45 | #[test] |
| 46 | fn csl_archive_index_tsv_agrees_with_the_embedded_index() -> Outcome<()> { |
| 47 | let tsv = include_str!("../data/csl/index.tsv"); |
| 48 | let mut styles = 0; |
| 49 | let mut locales = 0; |
| 50 | for line in tsv.lines().filter(|l| !l.starts_with('#')) { |
| 51 | let cols: Vec<&str> = line.split('\t').collect(); |
| 52 | match cols.first() { |
| 53 | Some(&"style") => { |
| 54 | let a = res!(archive::by_id(cols[2]).ok_or_else(|| err!( |
| 55 | "index.tsv style '{}' is not in the embedded index.", cols[2]; Missing))); |
| 56 | assert_eq!(cols[4], a.updated); |
| 57 | assert_eq!(cols[1], a.path()); |
| 58 | styles += 1; |
| 59 | } |
| 60 | Some(&"locale") => { |
| 61 | assert!(archive::has_locale(cols[2])); |
| 62 | let src = res!(archive::locale_src(cols[2]).ok_or_else(|| err!( |
| 63 | "Locale '{}' is not embedded.", cols[2]; Missing))); |
| 64 | assert!(src.contains(&format!("<updated>{}</updated>", cols[4]))); |
| 65 | locales += 1; |
| 66 | } |
| 67 | _ => (), |
| 68 | } |
| 69 | } |
| 70 | assert_eq!((styles, locales), (80, 63)); |
| 71 | Ok(()) |
| 72 | } |
| 73 | |
| 74 | #[test] |
| 75 | fn csl_archive_language_alone_reaches_the_primary_dialect() -> Outcome<()> { |
| 76 | let a = res!(archive::by_name("apa").ok_or_else(|| err!("apa missing"; Missing))); |
| 77 | let style = res!(a.style()); |
| 78 | assert_eq!(archive::wanted_paths(&style, Some("de")), |
| 79 | vec!["locales/de-DE.xml".to_string(), "locales/en-US.xml".to_string()]); |
| 80 | let files = res!(archive::locales_for(&style, Some("de"))); |
| 81 | let chain = files.chain(&style, Some("de")); |
| 82 | assert_eq!(chain.term_text("and", TermForm::Long, false), Some("und")); |
| 83 | // `sr` maps to sr-RS, which hayagriva does not serve, so Typst falls to en-US. |
| 84 | let files = res!(archive::locales_for(&style, Some("sr"))); |
| 85 | assert_eq!(files.chain(&style, Some("sr")).term_text("and", TermForm::Long, false), Some("and")); |
| 86 | Ok(()) |
| 87 | } |