Fix/Missing cardID special field (#4078)

This commit is contained in:
Luc Mcgrady 2025-06-13 04:47:16 +01:00 committed by GitHub
parent b1f3783a6a
commit 11cc9287ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 0 deletions

View file

@ -77,6 +77,7 @@ static SPECIAL_FIELDS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
"Subdeck",
"Tags",
"Type",
"CardID",
])
});

View file

@ -214,6 +214,7 @@ fn fill_empty_fields(note: &mut Note, qfmt: &str, nt: &Notetype, tr: &I18n) {
mod test {
use super::*;
use crate::collection::CollectionBuilder;
use crate::notetype::SPECIAL_FIELDS;
#[test]
fn can_render_fully() -> Result<()> {
@ -235,4 +236,20 @@ mod test {
Ok(())
}
#[test]
fn special_fields_complete() -> Result<()> {
let mut col = CollectionBuilder::default().build()?;
let mut map = HashMap::new();
let nt = col.get_notetype_by_name("Basic")?.unwrap();
let note = Note::new(&nt);
let card = Card::new(0.into(), 0.try_into().unwrap(), 0.into(), 0);
let tmpl = nt.templates[0].clone();
col.add_special_fields(&mut map, &note, &card, &nt, &tmpl)?;
assert!(map.iter().all(|val| SPECIAL_FIELDS.contains(val.0)));
Ok(())
}
}