Skip to content
This repository was archived by the owner on Feb 17, 2026. It is now read-only.

Commit a9dc0ed

Browse files
committed
test(csln): add style and locale validation
Signed-off-by: Bruce D'Arcus <bdarcus@gmail.com>
1 parent 797dfde commit a9dc0ed

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

csln/src/style/locale.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,39 @@ pub enum LocalizedTermNameMisc {
269269

270270
WorkingPaper,
271271
}
272+
#[cfg(test)]
273+
mod tests {
274+
use super::*;
275+
276+
#[test]
277+
fn test_locale_deserialization() {
278+
let json = r#"
279+
{
280+
"locale": "en-US",
281+
"dates": {
282+
"months": {
283+
"long": ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
284+
"short": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
285+
},
286+
"seasons": ["Spring", "Summer", "Autumn", "Winter"]
287+
},
288+
"roles": {},
289+
"terms": {
290+
"and": "and",
291+
"anonymous": {
292+
"long": "anonymous",
293+
"short": "anon"
294+
},
295+
"circa": {
296+
"long": "circa",
297+
"short": "c."
298+
}
299+
}
300+
}
301+
"#;
302+
let locale: Locale = serde_json::from_str(json).unwrap();
303+
assert_eq!(locale.locale, "en-US");
304+
assert_eq!(locale.dates.months.long[0], "January");
305+
assert_eq!(locale.terms.and.as_ref().unwrap(), "and");
306+
}
307+
}

csln/src/style/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,32 @@ mod tests {
9090
assert!(style.bibliography.is_none());
9191
assert!(style.citation.is_none());
9292
}
93+
94+
#[test]
95+
fn test_style_deserialization_complex() {
96+
let json = r#"
97+
{
98+
"info": {
99+
"title": "Complex Style",
100+
"id": "http://example.com/styles/complex"
101+
},
102+
"bibliography": {
103+
"template": [
104+
{
105+
"contributor": "author",
106+
"form": "long"
107+
},
108+
{
109+
"date": "issued",
110+
"form": "year"
111+
}
112+
]
113+
}
114+
}
115+
"#;
116+
let style: Style = serde_json::from_str(json).unwrap();
117+
assert_eq!(style.info.title.as_ref().unwrap(), "Complex Style");
118+
let bib = style.bibliography.unwrap();
119+
assert_eq!(bib.template.len(), 2);
120+
}
93121
}

0 commit comments

Comments
 (0)