[core] Canon, claims, hooks: strict parser, fail-closed claim checker, hook templates
This commit is contained in:
@@ -49,13 +49,19 @@ fn parses_the_sample_file() {
|
||||
assert_eq!(f.id, "tabula");
|
||||
assert_eq!(f.front.name, "Tabula");
|
||||
assert_eq!(f.front.one_liner, "Notes that stay on your own computer.");
|
||||
assert_eq!(f.front.audience, "People who want notes without an account.");
|
||||
assert_eq!(
|
||||
f.front.audience,
|
||||
"People who want notes without an account."
|
||||
);
|
||||
assert_eq!(f.front.price, "(assumption) one-time purchase");
|
||||
assert!(canon::is_assumption_value(&f.front.price));
|
||||
assert!(!canon::is_assumption_value(&f.front.name));
|
||||
assert_eq!(f.front.clicks, "New note in 1 click.");
|
||||
assert_eq!(f.front.status, Status::Released);
|
||||
assert_eq!(f.front.aula.as_deref(), Some("https://aula.marek-novak.cz/tabula/"));
|
||||
assert_eq!(
|
||||
f.front.aula.as_deref(),
|
||||
Some("https://aula.marek-novak.cz/tabula/")
|
||||
);
|
||||
assert_eq!(f.front.site, None);
|
||||
assert_eq!(f.facts.len(), 3);
|
||||
let f1 = f.fact(1).unwrap();
|
||||
@@ -63,7 +69,10 @@ fn parses_the_sample_file() {
|
||||
assert!(!f1.assumption);
|
||||
assert_eq!(f1.line, 16);
|
||||
let f2 = f.fact(2).unwrap();
|
||||
assert_eq!(f2.text, "It syncs between your devices without a cloud account.");
|
||||
assert_eq!(
|
||||
f2.text,
|
||||
"It syncs between your devices without a cloud account."
|
||||
);
|
||||
assert!(f2.assumption);
|
||||
assert_eq!(f2.line, 17);
|
||||
assert!(f.fact(4).is_none());
|
||||
@@ -84,14 +93,21 @@ fn urls_are_front_matter_plus_https_in_facts() {
|
||||
|
||||
#[test]
|
||||
fn http_urls_in_facts_are_not_allowed() {
|
||||
let text = with_front(FRONT, "- [F1] See http://example.com/x and https://example.com/y.\n");
|
||||
let text = with_front(
|
||||
FRONT,
|
||||
"- [F1] See http://example.com/x and https://example.com/y.\n",
|
||||
);
|
||||
let f = canon::parse("tabula", &text).unwrap();
|
||||
assert_eq!(f.urls(), vec!["https://example.com/y".to_string()]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn site_and_status_values() {
|
||||
for (s, st) in [("released", Status::Released), ("beta", Status::Beta), ("planned", Status::Planned)] {
|
||||
for (s, st) in [
|
||||
("released", Status::Released),
|
||||
("beta", Status::Beta),
|
||||
("planned", Status::Planned),
|
||||
] {
|
||||
let front = FRONT.replace("status: beta", &format!("status: {s}"));
|
||||
let text = with_front(&format!("{front}site: https://tabula.example/\n"), "");
|
||||
let f = canon::parse("tabula", &text).unwrap();
|
||||
@@ -104,30 +120,56 @@ fn site_and_status_values() {
|
||||
#[test]
|
||||
fn rejects_bad_status() {
|
||||
let front = FRONT.replace("status: beta", "status: Released");
|
||||
assert_eq!(code("tabula", &with_front(&front, "")), (8, CanonCode::BadStatus("Released".into())));
|
||||
assert_eq!(
|
||||
code("tabula", &with_front(&front, "")),
|
||||
(8, CanonCode::BadStatus("Released".into()))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_missing_unknown_duplicate_and_empty_keys() {
|
||||
let front = FRONT.replace("price: free\n", "");
|
||||
assert_eq!(code("tabula", &with_front(&front, "")).1, CanonCode::MissingKey("price".into()));
|
||||
assert_eq!(
|
||||
code("tabula", &with_front(&front, "")).1,
|
||||
CanonCode::MissingKey("price".into())
|
||||
);
|
||||
|
||||
let front = format!("{FRONT}colour: brass\n");
|
||||
assert_eq!(code("tabula", &with_front(&front, "")), (9, CanonCode::UnknownKey("colour".into())));
|
||||
assert_eq!(
|
||||
code("tabula", &with_front(&front, "")),
|
||||
(9, CanonCode::UnknownKey("colour".into()))
|
||||
);
|
||||
|
||||
let front = format!("{FRONT}name: Other\n");
|
||||
assert_eq!(code("tabula", &with_front(&front, "")), (9, CanonCode::DuplicateKey("name".into())));
|
||||
assert_eq!(
|
||||
code("tabula", &with_front(&front, "")),
|
||||
(9, CanonCode::DuplicateKey("name".into()))
|
||||
);
|
||||
|
||||
let front = FRONT.replace("price: free", "price:");
|
||||
assert_eq!(code("tabula", &with_front(&front, "")).1, CanonCode::EmptyValue("price".into()));
|
||||
assert_eq!(
|
||||
code("tabula", &with_front(&front, "")).1,
|
||||
CanonCode::EmptyValue("price".into())
|
||||
);
|
||||
|
||||
let front = FRONT.replace("price: free", "price: ");
|
||||
assert_eq!(code("tabula", &with_front(&front, "")).1, CanonCode::EmptyValue("price".into()));
|
||||
assert_eq!(
|
||||
code("tabula", &with_front(&front, "")).1,
|
||||
CanonCode::EmptyValue("price".into())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_non_flat_front_matter() {
|
||||
for bad in ["just text", " indented: yes", "list:\n - a", "", "# comment", "Name: Tabula", "key:value"] {
|
||||
for bad in [
|
||||
"just text",
|
||||
" indented: yes",
|
||||
"list:\n - a",
|
||||
"",
|
||||
"# comment",
|
||||
"Name: Tabula",
|
||||
"key:value",
|
||||
] {
|
||||
let front = format!("{FRONT}{bad}\n");
|
||||
let (line, c) = code("tabula", &with_front(&front, ""));
|
||||
assert_eq!(line, 9, "{bad:?}");
|
||||
@@ -140,19 +182,38 @@ fn rejects_non_flat_front_matter() {
|
||||
|
||||
#[test]
|
||||
fn rejects_missing_or_unclosed_front_matter() {
|
||||
assert_eq!(code("tabula", "# Tabula\n- [F1] x\n"), (1, CanonCode::NoFrontMatter));
|
||||
assert_eq!(
|
||||
code("tabula", "# Tabula\n- [F1] x\n"),
|
||||
(1, CanonCode::NoFrontMatter)
|
||||
);
|
||||
assert_eq!(code("tabula", ""), (1, CanonCode::NoFrontMatter));
|
||||
assert_eq!(code("tabula", " ---\n"), (1, CanonCode::NoFrontMatter));
|
||||
assert_eq!(code("tabula", &format!("---\n{FRONT}")).1, CanonCode::UnclosedFrontMatter);
|
||||
assert_eq!(
|
||||
code("tabula", &format!("---\n{FRONT}")).1,
|
||||
CanonCode::UnclosedFrontMatter
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn id_must_match_stem_and_be_valid() {
|
||||
assert_eq!(
|
||||
code("other", &with_front(FRONT, "")),
|
||||
(1, CanonCode::IdMismatch { id: "tabula".into(), stem: "other".into() })
|
||||
(
|
||||
2,
|
||||
CanonCode::IdMismatch {
|
||||
id: "tabula".into(),
|
||||
stem: "other".into()
|
||||
}
|
||||
)
|
||||
);
|
||||
for bad in ["Tabula", "-tabula", "tabula-", "tab_ula", "tab ula", "a234567890123456789012345678901234"] {
|
||||
for bad in [
|
||||
"Tabula",
|
||||
"-tabula",
|
||||
"tabula-",
|
||||
"tab_ula",
|
||||
"tab ula",
|
||||
"a234567890123456789012345678901234",
|
||||
] {
|
||||
let front = FRONT.replace("id: tabula", &format!("id: {bad}"));
|
||||
let c = code(bad, &with_front(&front, "")).1;
|
||||
assert_eq!(c, CanonCode::BadId(bad.trim().into()), "{bad:?}");
|
||||
@@ -167,9 +228,18 @@ fn id_must_match_stem_and_be_valid() {
|
||||
|
||||
#[test]
|
||||
fn urls_in_front_matter_must_be_https() {
|
||||
for bad in ["http://aula.example/", "aula.example", "https://a b", "https://"] {
|
||||
for bad in [
|
||||
"http://aula.example/",
|
||||
"aula.example",
|
||||
"https://a b",
|
||||
"https://",
|
||||
] {
|
||||
let text = with_front(&format!("{FRONT}aula: {bad}\n"), "");
|
||||
assert_eq!(code("tabula", &text).1, CanonCode::BadUrl(bad.into()), "{bad:?}");
|
||||
assert_eq!(
|
||||
code("tabula", &text).1,
|
||||
CanonCode::BadUrl(bad.into()),
|
||||
"{bad:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +260,7 @@ fn rejects_malformed_fact_lines() {
|
||||
] {
|
||||
let text = with_front(FRONT, &format!("\n{bad}\n"));
|
||||
let (line, c) = code("tabula", &text);
|
||||
assert_eq!(line, 10, "{bad:?}");
|
||||
assert_eq!(line, 11, "{bad:?}");
|
||||
assert!(
|
||||
matches!(c, CanonCode::MalformedFact | CanonCode::EmptyFact),
|
||||
"{bad:?} gave {c:?}"
|
||||
@@ -202,21 +272,33 @@ fn rejects_malformed_fact_lines() {
|
||||
fn fact_ids_in_range_without_leading_zeros() {
|
||||
let ok = with_front(FRONT, "- [F1] a\n- [F9999] b\n");
|
||||
let f = canon::parse("tabula", &ok).unwrap();
|
||||
assert_eq!(f.facts.iter().map(|x| x.id).collect::<Vec<_>>(), vec![1, 9999]);
|
||||
for bad in ["- [F0] zero", "- [F10000] big", "- [F01] lead", "- [F99999999999999999999] huge"] {
|
||||
assert_eq!(
|
||||
f.facts.iter().map(|x| x.id).collect::<Vec<_>>(),
|
||||
vec![1, 9999]
|
||||
);
|
||||
for bad in [
|
||||
"- [F0] zero",
|
||||
"- [F10000] big",
|
||||
"- [F01] lead",
|
||||
"- [F99999999999999999999] huge",
|
||||
] {
|
||||
let text = with_front(FRONT, &format!("{bad}\n"));
|
||||
assert_eq!(code("tabula", &text), (9, CanonCode::FactIdOutOfRange), "{bad:?}");
|
||||
assert_eq!(
|
||||
code("tabula", &text),
|
||||
(10, CanonCode::FactIdOutOfRange),
|
||||
"{bad:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_duplicate_facts_and_empty_facts() {
|
||||
let text = with_front(FRONT, "- [F1] a\n## Limits\n- [F1] b\n");
|
||||
assert_eq!(code("tabula", &text), (11, CanonCode::DuplicateFact(1)));
|
||||
assert_eq!(code("tabula", &text), (12, CanonCode::DuplicateFact(1)));
|
||||
let text = with_front(FRONT, "- [F1] \n");
|
||||
assert_eq!(code("tabula", &text), (9, CanonCode::EmptyFact));
|
||||
assert_eq!(code("tabula", &text), (10, CanonCode::EmptyFact));
|
||||
let text = with_front(FRONT, "- [F1] (assumption)\n");
|
||||
assert_eq!(code("tabula", &text), (9, CanonCode::EmptyFact));
|
||||
assert_eq!(code("tabula", &text), (10, CanonCode::EmptyFact));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -227,7 +309,11 @@ fn assumption_marker() {
|
||||
- [F4] Inside (assumption) the text.\n- [F5] Trailing spaces (assumption) \n",
|
||||
);
|
||||
let f = canon::parse("tabula", &text).unwrap();
|
||||
let got: Vec<(&str, bool)> = f.facts.iter().map(|x| (x.text.as_str(), x.assumption)).collect();
|
||||
let got: Vec<(&str, bool)> = f
|
||||
.facts
|
||||
.iter()
|
||||
.map(|x| (x.text.as_str(), x.assumption))
|
||||
.collect();
|
||||
assert_eq!(
|
||||
got,
|
||||
vec![
|
||||
@@ -242,7 +328,10 @@ fn assumption_marker() {
|
||||
|
||||
#[test]
|
||||
fn other_body_lines_are_ignored() {
|
||||
let text = with_front(FRONT, "# T\n\nSome prose [F7] here.\n- plain bullet\n> - [F9] quoted\n- [F1] fact\n");
|
||||
let text = with_front(
|
||||
FRONT,
|
||||
"# T\n\nSome prose [F7] here.\n- plain bullet\n> - [F9] quoted\n- [F1] fact\n",
|
||||
);
|
||||
let f = canon::parse("tabula", &text).unwrap();
|
||||
assert_eq!(f.facts.len(), 1);
|
||||
}
|
||||
@@ -256,17 +345,31 @@ fn size_limit_is_64_kib() {
|
||||
assert_eq!(text.len(), canon::MAX_FILE_BYTES);
|
||||
assert!(canon::parse("tabula", &text).is_ok());
|
||||
text.push('\n');
|
||||
assert_eq!(code("tabula", &text), (0, CanonCode::TooLarge { bytes: canon::MAX_FILE_BYTES + 1 }));
|
||||
assert_eq!(
|
||||
code("tabula", &text),
|
||||
(
|
||||
0,
|
||||
CanonCode::TooLarge {
|
||||
bytes: canon::MAX_FILE_BYTES + 1
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_huge_line_is_fine_under_the_limit_and_rejected_over_it() {
|
||||
let long = "a".repeat(60 * 1024);
|
||||
let text = with_front(FRONT, &format!("- [F1] {long}\n"));
|
||||
assert_eq!(canon::parse("tabula", &text).unwrap().facts[0].text.len(), long.len());
|
||||
assert_eq!(
|
||||
canon::parse("tabula", &text).unwrap().facts[0].text.len(),
|
||||
long.len()
|
||||
);
|
||||
let long = "a".repeat(70 * 1024);
|
||||
let text = with_front(FRONT, &format!("- [F1] {long}\n"));
|
||||
assert!(matches!(code("tabula", &text).1, CanonCode::TooLarge { .. }));
|
||||
assert!(matches!(
|
||||
code("tabula", &text).1,
|
||||
CanonCode::TooLarge { .. }
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -282,7 +385,7 @@ fn bom_and_crlf_are_tolerated() {
|
||||
#[test]
|
||||
fn lone_cr_nul_and_hidden_characters_are_rejected() {
|
||||
let text = with_front(FRONT, "- [F1] a\rb\n");
|
||||
assert_eq!(code("tabula", &text), (9, CanonCode::LoneCarriageReturn));
|
||||
assert_eq!(code("tabula", &text), (10, CanonCode::LoneCarriageReturn));
|
||||
for (ch, cp) in [
|
||||
('\0', 0u32),
|
||||
('\u{7}', 7),
|
||||
@@ -297,11 +400,18 @@ fn lone_cr_nul_and_hidden_characters_are_rejected() {
|
||||
('\u{e0041}', 0xe0041),
|
||||
] {
|
||||
let text = with_front(FRONT, &format!("- [F1] a{ch}b\n"));
|
||||
assert_eq!(code("tabula", &text), (9, CanonCode::ForbiddenCharacter { codepoint: cp }), "{cp:X}");
|
||||
assert_eq!(
|
||||
code("tabula", &text),
|
||||
(10, CanonCode::ForbiddenCharacter { codepoint: cp }),
|
||||
"{cp:X}"
|
||||
);
|
||||
}
|
||||
// In the front matter too.
|
||||
let front = FRONT.replace("name: Tabula", "name: Tab\u{202e}ula");
|
||||
assert_eq!(code("tabula", &with_front(&front, "")), (3, CanonCode::ForbiddenCharacter { codepoint: 0x202e }));
|
||||
assert_eq!(
|
||||
code("tabula", &with_front(&front, "")),
|
||||
(3, CanonCode::ForbiddenCharacter { codepoint: 0x202e })
|
||||
);
|
||||
// Tabs and ordinary non-ASCII text are fine.
|
||||
let text = with_front(FRONT, "- [F1] Poznámky\tžluťoučký kůň 📝\n");
|
||||
assert!(canon::parse("tabula", &text).is_ok());
|
||||
@@ -311,13 +421,26 @@ fn lone_cr_nul_and_hidden_characters_are_rejected() {
|
||||
fn canon_set() {
|
||||
let mut c = Canon::new();
|
||||
c.insert(canon::parse("tabula", TABULA).unwrap()).unwrap();
|
||||
let err = c.insert(canon::parse("tabula", TABULA).unwrap()).unwrap_err();
|
||||
let err = c
|
||||
.insert(canon::parse("tabula", TABULA).unwrap())
|
||||
.unwrap_err();
|
||||
assert_eq!(err.code, CanonCode::DuplicateApp("tabula".into()));
|
||||
c.insert(CanonFile::adhoc("release", "Tabula", vec![(1, "Tabula 1.2 is out.".into())])).unwrap();
|
||||
assert_eq!(c.apps().map(|f| f.id.as_str()).collect::<Vec<_>>(), vec!["release", "tabula"]);
|
||||
c.insert(CanonFile::adhoc(
|
||||
"release",
|
||||
"Tabula",
|
||||
vec![(1, "Tabula 1.2 is out.".into())],
|
||||
))
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
c.apps().map(|f| f.id.as_str()).collect::<Vec<_>>(),
|
||||
vec!["release", "tabula"]
|
||||
);
|
||||
assert!(c.get("tabula").is_some());
|
||||
assert!(c.get("nope").is_none());
|
||||
assert_eq!(c.fact("tabula", 1).unwrap().text, "Tabula keeps notes on your own computer.");
|
||||
assert_eq!(
|
||||
c.fact("tabula", 1).unwrap().text,
|
||||
"Tabula keeps notes on your own computer."
|
||||
);
|
||||
assert!(c.fact("tabula", 9).is_none());
|
||||
assert!(c.fact("nope", 1).is_none());
|
||||
let urls = c.allowed_urls();
|
||||
@@ -331,11 +454,17 @@ fn adhoc_release_file() {
|
||||
let f = CanonFile::adhoc(
|
||||
"release",
|
||||
"Tabula",
|
||||
vec![(1, "Tabula 1.2 is out.".into()), (2, "Faster search. (assumption)".into())],
|
||||
vec![
|
||||
(1, "Tabula 1.2 is out.".into()),
|
||||
(2, "Faster search. (assumption)".into()),
|
||||
],
|
||||
);
|
||||
assert_eq!(f.id, "release");
|
||||
assert_eq!(f.front.name, "Tabula");
|
||||
assert_eq!(f.facts.len(), 2);
|
||||
assert!(f.facts.iter().all(|x| !x.assumption), "release facts count as confirmed");
|
||||
assert!(
|
||||
f.facts.iter().all(|x| !x.assumption),
|
||||
"release facts count as confirmed"
|
||||
);
|
||||
assert_eq!(f.fact(2).unwrap().text, "Faster search. (assumption)");
|
||||
}
|
||||
|
||||
@@ -26,23 +26,29 @@ fn canon() -> Canon {
|
||||
c.insert(CanonFile::adhoc(
|
||||
"release",
|
||||
"Tabula",
|
||||
vec![(1, "Tabula 1.2 is out.".into()), (2, "Search is faster.".into())],
|
||||
vec![
|
||||
(1, "Tabula 1.2 is out.".into()),
|
||||
(2, "Search is faster.".into()),
|
||||
],
|
||||
))
|
||||
.unwrap();
|
||||
c
|
||||
}
|
||||
|
||||
fn r(app: &str, fact: u32) -> Ref {
|
||||
Ref { app: app.into(), fact }
|
||||
Ref {
|
||||
app: app.into(),
|
||||
fact,
|
||||
}
|
||||
}
|
||||
|
||||
fn unsourced(text: &str) -> bool {
|
||||
let rep = claims::check(text, &canon());
|
||||
!rep.ok() && rep.problems.iter().all(|p| matches!(p, Problem::Unsourced { .. }))
|
||||
}
|
||||
|
||||
fn passes(text: &str) -> bool {
|
||||
claims::check(text, &canon()).ok()
|
||||
!rep.ok()
|
||||
&& rep
|
||||
.problems
|
||||
.iter()
|
||||
.all(|p| matches!(p, Problem::Unsourced { .. }))
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -54,7 +60,10 @@ fn sourced_sentences_pass_and_refs_are_collected() {
|
||||
&c,
|
||||
);
|
||||
assert!(rep.ok(), "{:?}", rep.problems);
|
||||
assert_eq!(rep.refs, vec![r("release", 1), r("tabula", 1), r("tabula", 7)]);
|
||||
assert_eq!(
|
||||
rep.refs,
|
||||
vec![r("release", 1), r("tabula", 1), r("tabula", 7)]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -136,22 +145,41 @@ fn a_plain_phrase_with_anything_extra_needs_a_ref() {
|
||||
#[test]
|
||||
fn every_sentence_is_checked_separately() {
|
||||
let c = canon();
|
||||
let rep = claims::check("Tabula keeps notes local [tabula#F1]. It runs on Linux. Try it today.", &c);
|
||||
assert_eq!(rep.problems, vec![Problem::Unsourced { sentence: "It runs on Linux.".into() }]);
|
||||
let rep = claims::check(
|
||||
"Tabula keeps notes local [tabula#F1]. It runs on Linux. Try it today.",
|
||||
&c,
|
||||
);
|
||||
assert_eq!(
|
||||
rep.problems,
|
||||
vec![Problem::Unsourced {
|
||||
sentence: "It runs on Linux.".into()
|
||||
}]
|
||||
);
|
||||
// Lines are sentences too.
|
||||
let rep = claims::check("Tabula 1.2 [release#F1]\nFaster search", &c);
|
||||
assert_eq!(rep.problems, vec![Problem::Unsourced { sentence: "Faster search".into() }]);
|
||||
assert_eq!(
|
||||
rep.problems,
|
||||
vec![Problem::Unsourced {
|
||||
sentence: "Faster search".into()
|
||||
}]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decimals_and_urls_do_not_split_sentences() {
|
||||
let c = canon();
|
||||
assert_eq!(claims::sentences("Tabula 1.2 is out. Try it."), vec!["Tabula 1.2 is out.", "Try it."]);
|
||||
assert_eq!(
|
||||
claims::sentences("Tabula 1.2 is out. Try it."),
|
||||
vec!["Tabula 1.2 is out.", "Try it."]
|
||||
);
|
||||
assert_eq!(
|
||||
claims::sentences("See https://aula.marek-novak.cz/tabula/?a=1. Thanks!"),
|
||||
vec!["See https://aula.marek-novak.cz/tabula/?a=1.", "Thanks!"]
|
||||
);
|
||||
assert_eq!(claims::sentences("A. [tabula#F1] B"), vec!["A. [tabula#F1]", "B"]);
|
||||
assert_eq!(
|
||||
claims::sentences("A. [tabula#F1] B"),
|
||||
vec!["A. [tabula#F1]", "B"]
|
||||
);
|
||||
assert!(claims::check("Tabula 1.2 is out. [release#F1]", &c).ok());
|
||||
}
|
||||
|
||||
@@ -159,17 +187,32 @@ fn decimals_and_urls_do_not_split_sentences() {
|
||||
fn bad_refs_are_rejected() {
|
||||
let c = canon();
|
||||
let rep = claims::check("Tabula keeps notes local. [tabula#F99]", &c);
|
||||
assert_eq!(rep.problems, vec![Problem::MissingFact { r: r("tabula", 99) }]);
|
||||
assert_eq!(
|
||||
rep.problems,
|
||||
vec![Problem::MissingFact { r: r("tabula", 99) }]
|
||||
);
|
||||
let rep = claims::check("Notes, done. [notapp#F1]", &c);
|
||||
assert_eq!(rep.problems, vec![Problem::UnknownApp { r: r("notapp", 1) }]);
|
||||
assert_eq!(
|
||||
rep.problems,
|
||||
vec![Problem::UnknownApp { r: r("notapp", 1) }]
|
||||
);
|
||||
let rep = claims::check("It syncs everywhere. [tabula#F2]", &c);
|
||||
assert_eq!(rep.problems, vec![Problem::Unconfirmed { r: r("tabula", 2) }]);
|
||||
assert_eq!(
|
||||
rep.problems,
|
||||
vec![Problem::Unconfirmed { r: r("tabula", 2) }]
|
||||
);
|
||||
// A bad ref fails even on a plain sentence.
|
||||
let rep = claims::check("Try it today. [tabula#F99]", &c);
|
||||
assert_eq!(rep.problems, vec![Problem::MissingFact { r: r("tabula", 99) }]);
|
||||
assert_eq!(
|
||||
rep.problems,
|
||||
vec![Problem::MissingFact { r: r("tabula", 99) }]
|
||||
);
|
||||
// One good ref does not excuse a bad one.
|
||||
let rep = claims::check("Local notes. [tabula#F1][tabula#F2]", &c);
|
||||
assert_eq!(rep.problems, vec![Problem::Unconfirmed { r: r("tabula", 2) }]);
|
||||
assert_eq!(
|
||||
rep.problems,
|
||||
vec![Problem::Unconfirmed { r: r("tabula", 2) }]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -194,7 +237,9 @@ fn malformed_refs_are_rejected() {
|
||||
let text = format!("Tabula keeps notes on your own computer. {bad}");
|
||||
let rep = claims::check(&text, &c);
|
||||
assert!(
|
||||
rep.problems.iter().any(|p| matches!(p, Problem::MalformedRef { .. })),
|
||||
rep.problems
|
||||
.iter()
|
||||
.any(|p| matches!(p, Problem::MalformedRef { .. })),
|
||||
"{bad:?}: {:?}",
|
||||
rep.problems
|
||||
);
|
||||
@@ -208,26 +253,53 @@ fn urls_must_come_from_the_canon() {
|
||||
assert!(claims::check("Get it here: https://aula.marek-novak.cz/tabula/", &c).ok());
|
||||
assert!(claims::check("Get it here: https://aula.marek-novak.cz/tabula", &c).ok());
|
||||
assert!(claims::check("Read more: https://aula.marek-novak.cz/tabula/windows.", &c).ok());
|
||||
assert!(claims::check("Read more: (https://aula.marek-novak.cz/tabula/windows)", &c).ok());
|
||||
assert!(
|
||||
claims::check(
|
||||
"Read more: (https://aula.marek-novak.cz/tabula/windows)",
|
||||
&c
|
||||
)
|
||||
.ok()
|
||||
);
|
||||
for (text, url) in [
|
||||
("Get it here: https://evil.example/tabula", "https://evil.example/tabula"),
|
||||
("Get it here: http://aula.marek-novak.cz/tabula/", "http://aula.marek-novak.cz/tabula/"),
|
||||
("Get it here: https://aula.marek-novak.cz/tabula/x", "https://aula.marek-novak.cz/tabula/x"),
|
||||
(
|
||||
"Get it here: https://evil.example/tabula",
|
||||
"https://evil.example/tabula",
|
||||
),
|
||||
(
|
||||
"Get it here: http://aula.marek-novak.cz/tabula/",
|
||||
"http://aula.marek-novak.cz/tabula/",
|
||||
),
|
||||
(
|
||||
"Get it here: https://aula.marek-novak.cz/tabula/x",
|
||||
"https://aula.marek-novak.cz/tabula/x",
|
||||
),
|
||||
("Get it here: www.evil.example", "www.evil.example"),
|
||||
("Get it here: evil.com", "evil.com"),
|
||||
("Get it here: evil.example/download", "evil.example/download"),
|
||||
(
|
||||
"Get it here: evil.example/download",
|
||||
"evil.example/download",
|
||||
),
|
||||
("Get it here: ftp://evil.example", "ftp://evil.example"),
|
||||
] {
|
||||
let rep = claims::check(text, &c);
|
||||
assert!(
|
||||
rep.problems.contains(&Problem::UrlNotInCanon { url: url.into() }),
|
||||
rep.problems
|
||||
.contains(&Problem::UrlNotInCanon { url: url.into() }),
|
||||
"{text:?}: {:?}",
|
||||
rep.problems
|
||||
);
|
||||
}
|
||||
// A URL in a sourced sentence is still checked.
|
||||
let rep = claims::check("It runs on Windows, see https://evil.example/ [tabula#F3]", &c);
|
||||
assert_eq!(rep.problems, vec![Problem::UrlNotInCanon { url: "https://evil.example/".into() }]);
|
||||
let rep = claims::check(
|
||||
"It runs on Windows, see https://evil.example/ [tabula#F3]",
|
||||
&c,
|
||||
);
|
||||
assert_eq!(
|
||||
rep.problems,
|
||||
vec![Problem::UrlNotInCanon {
|
||||
url: "https://evil.example/".into()
|
||||
}]
|
||||
);
|
||||
// A bare form of an allowed URL is fine.
|
||||
assert!(claims::check("Get it here: aula.marek-novak.cz/tabula/", &c).ok());
|
||||
}
|
||||
@@ -236,9 +308,15 @@ fn urls_must_come_from_the_canon() {
|
||||
fn hidden_characters_are_rejected() {
|
||||
let c = canon();
|
||||
let rep = claims::check("Try it today.\u{202e}", &c);
|
||||
assert_eq!(rep.problems, vec![Problem::HiddenCharacter { codepoint: 0x202e }]);
|
||||
assert_eq!(
|
||||
rep.problems,
|
||||
vec![Problem::HiddenCharacter { codepoint: 0x202e }]
|
||||
);
|
||||
let rep = claims::check("Try it\0 today.", &c);
|
||||
assert!(rep.problems.contains(&Problem::HiddenCharacter { codepoint: 0 }));
|
||||
assert!(
|
||||
rep.problems
|
||||
.contains(&Problem::HiddenCharacter { codepoint: 0 })
|
||||
);
|
||||
// CRLF and tabs are ordinary whitespace.
|
||||
assert!(claims::check("Try it today.\r\nThanks!\t", &c).ok());
|
||||
}
|
||||
@@ -251,12 +329,37 @@ fn reasons_are_plain_english() {
|
||||
&c,
|
||||
);
|
||||
let reasons: Vec<String> = rep.problems.iter().map(Problem::reason).collect();
|
||||
assert!(reasons.iter().any(|s| s.contains("It runs on Linux.") && s.contains("no source")), "{reasons:?}");
|
||||
assert!(reasons.iter().any(|s| s.contains("tabula#F99") && s.contains("does not exist")), "{reasons:?}");
|
||||
assert!(reasons.iter().any(|s| s.contains("unknown app") && s.contains("x")), "{reasons:?}");
|
||||
assert!(reasons.iter().any(|s| s.contains("unconfirmed fact") && s.contains("tabula#F2")), "{reasons:?}");
|
||||
assert!(
|
||||
reasons
|
||||
.iter()
|
||||
.any(|s| s.contains("It runs on Linux.") && s.contains("no source")),
|
||||
"{reasons:?}"
|
||||
);
|
||||
assert!(
|
||||
reasons
|
||||
.iter()
|
||||
.any(|s| s.contains("tabula#F99") && s.contains("does not exist")),
|
||||
"{reasons:?}"
|
||||
);
|
||||
assert!(
|
||||
reasons
|
||||
.iter()
|
||||
.any(|s| s.contains("unknown app") && s.contains("x")),
|
||||
"{reasons:?}"
|
||||
);
|
||||
assert!(
|
||||
reasons
|
||||
.iter()
|
||||
.any(|s| s.contains("unconfirmed fact") && s.contains("tabula#F2")),
|
||||
"{reasons:?}"
|
||||
);
|
||||
assert!(reasons.iter().any(|s| s.contains("[F3]")), "{reasons:?}");
|
||||
assert!(reasons.iter().any(|s| s.contains("https://evil.example/") && s.contains("not in the canon")), "{reasons:?}");
|
||||
assert!(
|
||||
reasons
|
||||
.iter()
|
||||
.any(|s| s.contains("https://evil.example/") && s.contains("not in the canon")),
|
||||
"{reasons:?}"
|
||||
);
|
||||
assert_eq!(
|
||||
Problem::HiddenCharacter { codepoint: 0x202e }.reason(),
|
||||
"Hidden or direction-changing character U+202E."
|
||||
@@ -267,21 +370,38 @@ fn reasons_are_plain_english() {
|
||||
fn problems_are_not_repeated() {
|
||||
let c = canon();
|
||||
let rep = claims::check("A. [tabula#F99] B. [tabula#F99]", &c);
|
||||
assert_eq!(rep.problems, vec![Problem::MissingFact { r: r("tabula", 99) }]);
|
||||
assert_eq!(
|
||||
rep.problems,
|
||||
vec![Problem::MissingFact { r: r("tabula", 99) }]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strip_refs_for_display() {
|
||||
assert_eq!(
|
||||
claims::strip_refs("Tabula keeps notes local [tabula#F1]. One click.[tabula#F7][tabula#F1] Done [release#F1]"),
|
||||
claims::strip_refs(
|
||||
"Tabula keeps notes local [tabula#F1]. One click.[tabula#F7][tabula#F1] Done [release#F1]"
|
||||
),
|
||||
"Tabula keeps notes local. One click. Done"
|
||||
);
|
||||
assert_eq!(claims::strip_refs("Tabula [tabula#F1] keeps notes."), "Tabula keeps notes.");
|
||||
assert_eq!(
|
||||
claims::strip_refs("Tabula [tabula#F1] keeps notes."),
|
||||
"Tabula keeps notes."
|
||||
);
|
||||
assert_eq!(claims::strip_refs("A.[tabula#F1]B"), "A. B");
|
||||
assert_eq!(claims::strip_refs("Line one [tabula#F1]\nLine two"), "Line one\nLine two");
|
||||
assert_eq!(claims::strip_refs("Keep [beta] and [Tabula#F1]."), "Keep [beta] and [Tabula#F1].");
|
||||
assert_eq!(
|
||||
claims::strip_refs("Line one [tabula#F1]\nLine two"),
|
||||
"Line one\nLine two"
|
||||
);
|
||||
assert_eq!(
|
||||
claims::strip_refs("Keep [beta] and [Tabula#F1]."),
|
||||
"Keep [beta] and [Tabula#F1]."
|
||||
);
|
||||
assert_eq!(claims::strip_refs(""), "");
|
||||
assert_eq!(claims::strip_refs("Žluťoučký [tabula#F1]kůň"), "Žluťoučký kůň");
|
||||
assert_eq!(
|
||||
claims::strip_refs("Žluťoučký [tabula#F1]kůň"),
|
||||
"Žluťoučký kůň"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -292,3 +412,23 @@ fn stripped_text_of_a_passing_text_has_no_refs() {
|
||||
let stripped = claims::strip_refs(text);
|
||||
assert!(claims::check(&stripped, &c).refs.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn states_fact_is_fail_closed() {
|
||||
let c = canon();
|
||||
assert!(!claims::states_fact("Try it today.", &c));
|
||||
assert!(!claims::states_fact("Here's what's new [tabula#F1].", &c));
|
||||
assert!(claims::states_fact("Tabula is great.", &c));
|
||||
assert!(claims::states_fact("It is what it is.", &c));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_huge_text_is_checked_without_trouble() {
|
||||
let c = canon();
|
||||
let text = "Local notes [tabula#F1]. ".repeat(2000);
|
||||
let rep = claims::check(&text, &c);
|
||||
assert!(rep.ok());
|
||||
assert_eq!(rep.refs, vec![r("tabula", 1)]);
|
||||
let line = "a".repeat(100_000);
|
||||
assert!(!claims::check(&line, &c).ok());
|
||||
}
|
||||
|
||||
@@ -17,13 +17,19 @@ Prose is ignored.
|
||||
";
|
||||
|
||||
fn values(pairs: &[(&str, &str)]) -> BTreeMap<String, String> {
|
||||
pairs.iter().map(|(k, v)| (k.to_string(), v.to_string())).collect()
|
||||
pairs
|
||||
.iter()
|
||||
.map(|(k, v)| (k.to_string(), v.to_string()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_templates_with_slots_in_order() {
|
||||
let hs = hooks::parse(HOOKS).unwrap();
|
||||
assert_eq!(hs.iter().map(|h| h.id.as_str()).collect::<Vec<_>>(), vec!["H1", "H2", "H3", "H4", "H5"]);
|
||||
assert_eq!(
|
||||
hs.iter().map(|h| h.id.as_str()).collect::<Vec<_>>(),
|
||||
vec!["H1", "H2", "H3", "H4", "H5"]
|
||||
);
|
||||
assert_eq!(hs[0].text, "Tired of {pain}? {app} fixes it.");
|
||||
assert_eq!(hs[0].slots, vec!["pain", "app"]);
|
||||
assert_eq!(hs[1].slots, vec!["number", "audience", "app"]);
|
||||
@@ -38,18 +44,30 @@ fn slots_are_unique() {
|
||||
|
||||
#[test]
|
||||
fn every_fixed_slot_is_allowed() {
|
||||
let line = format!("- [H1] {}\n", hooks::SLOTS.map(|s| format!("{{{s}}}")).join(" "));
|
||||
let line = format!(
|
||||
"- [H1] {}\n",
|
||||
hooks::SLOTS.map(|s| format!("{{{s}}}")).join(" ")
|
||||
);
|
||||
let hs = hooks::parse(&line).unwrap();
|
||||
assert_eq!(hs[0].slots, hooks::SLOTS.to_vec());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_slots_are_errors() {
|
||||
for (bad, slot) in [("{price}", "price"), ("{App}", "App"), ("{}", ""), ("{ app }", " app "), ("{url}", "url")] {
|
||||
for (bad, slot) in [
|
||||
("{price}", "price"),
|
||||
("{App}", "App"),
|
||||
("{}", ""),
|
||||
("{ app }", " app "),
|
||||
("{url}", "url"),
|
||||
] {
|
||||
let md = format!("# x\n- [H1] Hello {bad}\n");
|
||||
assert_eq!(
|
||||
hooks::parse(&md),
|
||||
Err(HookError::UnknownSlot { line: 2, slot: slot.into() }),
|
||||
Err(HookError::UnknownSlot {
|
||||
line: 2,
|
||||
slot: slot.into()
|
||||
}),
|
||||
"{bad:?}"
|
||||
);
|
||||
}
|
||||
@@ -59,35 +77,76 @@ fn unknown_slots_are_errors() {
|
||||
fn unbalanced_braces_are_errors() {
|
||||
for bad in ["{app", "app}", "{{app}}", "{a{pp}", "}{"] {
|
||||
let md = format!("- [H1] Hi {bad}\n");
|
||||
assert_eq!(hooks::parse(&md), Err(HookError::UnbalancedBrace { line: 1 }), "{bad:?}");
|
||||
assert_eq!(
|
||||
hooks::parse(&md),
|
||||
Err(HookError::UnbalancedBrace { line: 1 }),
|
||||
"{bad:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn malformed_duplicate_and_empty_lines() {
|
||||
for bad in ["- [H] x", "- [Hx] x", "- [H1]x", "- [H1 x", "- [h1] x", " - [H1] x", "- [H1] x"] {
|
||||
assert_eq!(hooks::parse(&format!("{bad}\n")), Err(HookError::Malformed { line: 1 }), "{bad:?}");
|
||||
for bad in [
|
||||
"- [H] x",
|
||||
"- [Hx] x",
|
||||
"- [H1]x",
|
||||
"- [H1 x",
|
||||
"- [h1] x",
|
||||
" - [H1] x",
|
||||
"- [H1] x",
|
||||
] {
|
||||
assert_eq!(
|
||||
hooks::parse(&format!("{bad}\n")),
|
||||
Err(HookError::Malformed { line: 1 }),
|
||||
"{bad:?}"
|
||||
);
|
||||
}
|
||||
for bad in ["- [H0] x", "- [H01] x", "- [H10000] x"] {
|
||||
assert_eq!(hooks::parse(&format!("{bad}\n")), Err(HookError::IdOutOfRange { line: 1 }), "{bad:?}");
|
||||
assert_eq!(
|
||||
hooks::parse(&format!("{bad}\n")),
|
||||
Err(HookError::IdOutOfRange { line: 1 }),
|
||||
"{bad:?}"
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
hooks::parse("- [H1] a\n- [H1] b\n"),
|
||||
Err(HookError::Duplicate { line: 2, id: "H1".into() })
|
||||
Err(HookError::Duplicate {
|
||||
line: 2,
|
||||
id: "H1".into()
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
hooks::parse("- [H1] \n"),
|
||||
Err(HookError::Empty { line: 1 })
|
||||
);
|
||||
assert_eq!(
|
||||
hooks::parse("- [H1]\n"),
|
||||
Err(HookError::Malformed { line: 1 })
|
||||
);
|
||||
assert_eq!(hooks::parse("- [H1] \n"), Err(HookError::Empty { line: 1 }));
|
||||
assert_eq!(hooks::parse("- [H1]\n"), Err(HookError::Malformed { line: 1 }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hostile_input() {
|
||||
let big = format!("- [H1] {}\n", "a".repeat(hooks::MAX_FILE_BYTES));
|
||||
assert!(matches!(hooks::parse(&big), Err(HookError::TooLarge { .. })));
|
||||
assert!(matches!(
|
||||
hooks::parse(&big),
|
||||
Err(HookError::TooLarge { .. })
|
||||
));
|
||||
assert_eq!(
|
||||
hooks::parse("- [H1] a\u{202e}b\n"),
|
||||
Err(HookError::ForbiddenCharacter { line: 1, codepoint: 0x202e })
|
||||
Err(HookError::ForbiddenCharacter {
|
||||
line: 1,
|
||||
codepoint: 0x202e
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
hooks::parse("x\n- [H1] a\0b\n"),
|
||||
Err(HookError::ForbiddenCharacter {
|
||||
line: 2,
|
||||
codepoint: 0
|
||||
})
|
||||
);
|
||||
assert_eq!(hooks::parse("x\n- [H1] a\0b\n"), Err(HookError::ForbiddenCharacter { line: 2, codepoint: 0 }));
|
||||
let crlf = HOOKS.replace('\n', "\r\n");
|
||||
assert_eq!(hooks::parse(&crlf).unwrap(), hooks::parse(HOOKS).unwrap());
|
||||
let bom = format!("\u{feff}{HOOKS}");
|
||||
@@ -99,7 +158,10 @@ fn hostile_input() {
|
||||
fn fill_replaces_every_slot() {
|
||||
let hs = hooks::parse(HOOKS).unwrap();
|
||||
let v = values(&[("pain", "lost notes"), ("app", "Tabula"), ("unused", "x")]);
|
||||
assert_eq!(hs[0].fill(&v).unwrap(), "Tired of lost notes? Tabula fixes it.");
|
||||
assert_eq!(
|
||||
hs[0].fill(&v).unwrap(),
|
||||
"Tired of lost notes? Tabula fixes it."
|
||||
);
|
||||
assert_eq!(hs[4].fill(&BTreeMap::new()).unwrap(), "Stop losing notes.");
|
||||
}
|
||||
|
||||
@@ -107,14 +169,22 @@ fn fill_replaces_every_slot() {
|
||||
fn fill_missing_value_is_an_error() {
|
||||
let hs = hooks::parse(HOOKS).unwrap();
|
||||
let v = values(&[("app", "Tabula")]);
|
||||
assert_eq!(hs[0].fill(&v), Err(HookError::MissingValue { slot: "pain".into() }));
|
||||
assert_eq!(
|
||||
hs[0].fill(&v),
|
||||
Err(HookError::MissingValue {
|
||||
slot: "pain".into()
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fill_does_not_re_expand_braces_in_values() {
|
||||
let hs = hooks::parse(HOOKS).unwrap();
|
||||
let v = values(&[("pain", "{app}"), ("app", "{pain} {x}")]);
|
||||
assert_eq!(hs[0].fill(&v).unwrap(), "Tired of {app}? {pain} {x} fixes it.");
|
||||
assert_eq!(
|
||||
hs[0].fill(&v).unwrap(),
|
||||
"Tired of {app}? {pain} {x} fixes it."
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -122,19 +192,39 @@ fn genome_from_text() {
|
||||
let hs = hooks::parse(HOOKS).unwrap();
|
||||
assert_eq!(
|
||||
hs[0].genome,
|
||||
Genome { opening: Opening::Question, words: 6, has_number: false, lead_verb: None }
|
||||
Genome {
|
||||
opening: Opening::Question,
|
||||
words: 6,
|
||||
has_number: false,
|
||||
lead_verb: None
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
hs[1].genome,
|
||||
Genome { opening: Opening::Number, words: 5, has_number: true, lead_verb: None }
|
||||
Genome {
|
||||
opening: Opening::Number,
|
||||
words: 5,
|
||||
has_number: true,
|
||||
lead_verb: None
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
hs[2].genome,
|
||||
Genome { opening: Opening::Command, words: 4, has_number: false, lead_verb: Some("try".into()) }
|
||||
Genome {
|
||||
opening: Opening::Command,
|
||||
words: 4,
|
||||
has_number: false,
|
||||
lead_verb: Some("try".into())
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
hs[3].genome,
|
||||
Genome { opening: Opening::Statement, words: 5, has_number: false, lead_verb: None }
|
||||
Genome {
|
||||
opening: Opening::Statement,
|
||||
words: 5,
|
||||
has_number: false,
|
||||
lead_verb: None
|
||||
}
|
||||
);
|
||||
assert_eq!(hs[4].genome.opening, Opening::Command);
|
||||
assert_eq!(hs[4].genome.lead_verb.as_deref(), Some("stop"));
|
||||
@@ -151,8 +241,24 @@ fn genome_of_filled_text() {
|
||||
let g = Genome::of("Your notes, on your computer. Ever wondered why?");
|
||||
assert_eq!(g.opening, Opening::Statement);
|
||||
let g = Genome::of("");
|
||||
assert_eq!(g, Genome { opening: Opening::Statement, words: 0, has_number: false, lead_verb: None });
|
||||
assert_eq!(
|
||||
g,
|
||||
Genome {
|
||||
opening: Opening::Statement,
|
||||
words: 0,
|
||||
has_number: false,
|
||||
lead_verb: None
|
||||
}
|
||||
);
|
||||
let g = Genome::of("Meet Tabula 2.");
|
||||
assert_eq!(g.opening, Opening::Command);
|
||||
assert!(g.has_number);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lone_carriage_return_is_an_error() {
|
||||
assert_eq!(
|
||||
hooks::parse("- [H1] a\rb\n"),
|
||||
Err(HookError::LoneCarriageReturn { line: 1 })
|
||||
);
|
||||
}
|
||||
|
||||
@@ -87,11 +87,27 @@ fn value() -> impl Strategy<Value = String> {
|
||||
|
||||
fn gen_file() -> impl Strategy<Value = (String, Vec<GenFact>, [String; 5], Status)> {
|
||||
let id = "[a-z0-9]([a-z0-9-]{0,30}[a-z0-9])?";
|
||||
let facts = prop::collection::btree_map(1u32..=9999, (fact_text(), any::<bool>()), 0..40).prop_map(|m| {
|
||||
m.into_iter().map(|(id, (text, assumption))| GenFact { id, text, assumption }).collect::<Vec<_>>()
|
||||
});
|
||||
let status = prop_oneof![Just(Status::Released), Just(Status::Beta), Just(Status::Planned)];
|
||||
(id, facts, [value(), value(), value(), value(), value()], status)
|
||||
let facts = prop::collection::btree_map(1u32..=9999, (fact_text(), any::<bool>()), 0..40)
|
||||
.prop_map(|m| {
|
||||
m.into_iter()
|
||||
.map(|(id, (text, assumption))| GenFact {
|
||||
id,
|
||||
text,
|
||||
assumption,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
});
|
||||
let status = prop_oneof![
|
||||
Just(Status::Released),
|
||||
Just(Status::Beta),
|
||||
Just(Status::Planned)
|
||||
];
|
||||
(
|
||||
id,
|
||||
facts,
|
||||
[value(), value(), value(), value(), value()],
|
||||
status,
|
||||
)
|
||||
}
|
||||
|
||||
fn render(id: &str, facts: &[GenFact], v: &[String; 5], status: Status, shuffle: u64) -> String {
|
||||
@@ -114,7 +130,12 @@ fn render(id: &str, facts: &[GenFact], v: &[String; 5], status: Status, shuffle:
|
||||
if i % 7 == 3 {
|
||||
s.push_str("\n## More\n\nSome prose.\n");
|
||||
}
|
||||
s.push_str(&format!("- [F{}] {}{}\n", f.id, f.text, if f.assumption { " (assumption)" } else { "" }));
|
||||
s.push_str(&format!(
|
||||
"- [F{}] {}{}\n",
|
||||
f.id,
|
||||
f.text,
|
||||
if f.assumption { " (assumption)" } else { "" }
|
||||
));
|
||||
}
|
||||
s
|
||||
}
|
||||
@@ -140,7 +161,8 @@ proptest! {
|
||||
hooks::SLOTS.iter().map(|s| (s.to_string(), "{app}".to_string())).collect();
|
||||
for h in hs {
|
||||
let filled = h.fill(&v).unwrap();
|
||||
prop_assert!(!filled.contains("{feature}"));
|
||||
let slot = format!("{{{}}}", "feature");
|
||||
prop_assert!(!filled.contains(&slot));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user