fix handling of typing cards
This commit is contained in:
parent
f4c5aac163
commit
94485f36ae
@ -177,7 +177,12 @@ fn template_is_empty<'a>(nonempty_fields: &HashSet<&str>, nodes: &[ParsedNode<'a
|
|||||||
match node {
|
match node {
|
||||||
// ignore normal text
|
// ignore normal text
|
||||||
Text(_) => (),
|
Text(_) => (),
|
||||||
Replacement { key, .. } => {
|
Replacement { key, filters } => {
|
||||||
|
// Anki doesn't consider a type: reference as a required field
|
||||||
|
if filters.contains(&"type") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if nonempty_fields.contains(*key) {
|
if nonempty_fields.contains(*key) {
|
||||||
// a single replacement is enough
|
// a single replacement is enough
|
||||||
return false;
|
return false;
|
||||||
@ -307,7 +312,7 @@ mod test {
|
|||||||
let mut tmpl = PT::from_text("{{2}}{{1}}").unwrap();
|
let mut tmpl = PT::from_text("{{2}}{{1}}").unwrap();
|
||||||
assert_eq!(tmpl.renders_with_fields(&fields), true);
|
assert_eq!(tmpl.renders_with_fields(&fields), true);
|
||||||
tmpl = PT::from_text("{{2}}{{type:cloze:1}}").unwrap();
|
tmpl = PT::from_text("{{2}}{{type:cloze:1}}").unwrap();
|
||||||
assert_eq!(tmpl.renders_with_fields(&fields), true);
|
assert_eq!(tmpl.renders_with_fields(&fields), false);
|
||||||
tmpl = PT::from_text("{{2}}{{4}}").unwrap();
|
tmpl = PT::from_text("{{2}}{{4}}").unwrap();
|
||||||
assert_eq!(tmpl.renders_with_fields(&fields), false);
|
assert_eq!(tmpl.renders_with_fields(&fields), false);
|
||||||
tmpl = PT::from_text("{{#3}}{{^2}}{{1}}{{/2}}{{/3}}").unwrap();
|
tmpl = PT::from_text("{{#3}}{{^2}}{{1}}{{/2}}{{/3}}").unwrap();
|
||||||
@ -346,8 +351,10 @@ mod test {
|
|||||||
FieldRequirements::All(HashSet::from_iter(vec![0, 1].into_iter()))
|
FieldRequirements::All(HashSet::from_iter(vec![0, 1].into_iter()))
|
||||||
);
|
);
|
||||||
|
|
||||||
// fixme: handling of type in answer card reqs doesn't match desktop,
|
tmpl = PT::from_text("{{a}}{{type:b}}").unwrap();
|
||||||
// which only requires first field
|
assert_eq!(
|
||||||
//
|
tmpl.requirements(&field_map),
|
||||||
|
FieldRequirements::Any(HashSet::from_iter(vec![0].into_iter()))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -371,6 +371,12 @@ def test_req():
|
|||||||
mm.save(opt, templates=True)
|
mm.save(opt, templates=True)
|
||||||
assert opt['req'][1] == [1, 'none', []]
|
assert opt['req'][1] == [1, 'none', []]
|
||||||
|
|
||||||
|
opt = mm.byName("Basic (type in the answer)")
|
||||||
|
reqSize(opt)
|
||||||
|
r = opt['req'][0]
|
||||||
|
assert r[1] in ("any", "all")
|
||||||
|
assert r[2] == [0]
|
||||||
|
|
||||||
# def test_updatereqs_performance():
|
# def test_updatereqs_performance():
|
||||||
# import time
|
# import time
|
||||||
# d = getEmptyCol()
|
# d = getEmptyCol()
|
||||||
|
Loading…
Reference in New Issue
Block a user