Skip to main content

prose_quantities

Function prose_quantities 

Source
pub fn prose_quantities(path: &str, text: &str) -> Vec<ProseQuantity>
Expand description

Every unsupported quantity in the text of the file at path, read paragraph by paragraph so that a sentence hard-wrapped over several lines is read whole, with the line each quantity starts on. How lines group is decided by the file’s kind: Markdown and templates join consecutive non-blank lines, with each fenced code block, table row and heading a paragraph of its own and each list item starting a new one; TOML starts a paragraph at every key; YAML reads only the claim: and note: values, with their continuation lines. unsupported_quantity is the sentence-level test applied.

use majordomus_cli::economics::claims::prose_quantities;
let text = "# Pitch\n\nWith Majordomus a session spends\n40% fewer tokens than without.\n";
let found = prose_quantities("docs/PITCH.md", text);
assert_eq!((found[0].line, found[0].quantity.as_str()), (4, "40%"), "the line it starts on");
// list items and table rows do not run into each other
let text = "- Tokens are counted\n- 40% of tests are slow\n\n| token |\n| 40% |\n";
assert!(prose_quantities("README.md", text).is_empty());
// a claim wrapped in YAML is one sentence too
let yaml = "claims:\n  - id: x\n    claim: Majordomus saves\n      40% of tokens\n    status: planned\n";
assert_eq!(prose_quantities("docs/CLAIMS.yaml", yaml)[0].line, 4);