Repository navigation
feat(docs): an entry in the guide for each loss code, linked from the notices that give it #3134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,7 +1,7 @@ | ||||||||
| //! Shared classification for data-loss notices, independent of their wording. | ||||||||
| //! | ||||||||
| //! A code's identifier is public: scripts match on it (`rustgis-cli run --strict --allow`), so it | ||||||||
| //! is never translated, renamed or reused. The command line guide lists every code, checked by | ||||||||
| //! is never translated, renamed or reused. The guide has an entry for each code ([`GUIDE`]), checked by | ||||||||
| //! `the_guide_lists_every_code`. | ||||||||
|
|
||||||||
| /// What happened to the data. | ||||||||
|
|
@@ -152,7 +152,16 @@ loss_codes! { | |||||||
| ), | ||||||||
| } | ||||||||
|
|
||||||||
| /// The guide's page of loss codes, which has an entry for each, anchored by its identifier. | ||||||||
| pub const GUIDE: &str = "https://rustgis.app/user-guide/loss-codes/"; | ||||||||
|
|
||||||||
| impl LossCode { | ||||||||
| /// The address of this code's entry in the guide: what it means, where it is said and what to | ||||||||
| /// do about it. | ||||||||
| pub fn doc_url(self) -> String { | ||||||||
| format!("{GUIDE}#{}", self.spec().id) | ||||||||
| } | ||||||||
|
|
||||||||
| /// The code this identifier names. | ||||||||
| pub fn from_id(id: &str) -> Option<LossCode> { | ||||||||
| Self::ALL.iter().copied().find(|code| code.spec().id == id) | ||||||||
|
|
@@ -437,18 +446,22 @@ mod tests { | |||||||
|
|
||||||||
| #[test] | ||||||||
| fn the_guide_lists_every_code() { | ||||||||
| let guide = include_str!("../../../docs/cli.md").replace("\r\n", "\n"); | ||||||||
| let section = guide.split("\n### Loss codes\n").nth(1).unwrap_or_default(); | ||||||||
| let section = section.split("\n#").next().unwrap_or_default(); | ||||||||
| let rows: Vec<&str> = section.lines().filter(|l| l.starts_with("| `")).collect(); | ||||||||
| let guide = include_str!("../../../docs/user-guide/loss-codes.md").replace("\r\n", "\n"); | ||||||||
| let headings: Vec<&str> = guide.lines().filter(|l| l.starts_with("### `")).collect(); | ||||||||
| for code in LossCode::ALL { | ||||||||
| let spec = code.spec(); | ||||||||
| let row = format!("| `{}` | {} |", spec.id, spec.action); | ||||||||
| assert!(rows.contains(&row.as_str()), "docs/cli.md: the loss codes should list\n{row}"); | ||||||||
| // The anchor each notice links to ([`LossCode::doc_url`]), and what to do under it. | ||||||||
| let heading = format!("### `{0}` {{ #{0} }}", spec.id); | ||||||||
| let entry = guide.split(&format!("\n{heading}\n")).nth(1).unwrap_or_default(); | ||||||||
| let entry = entry.split("\n### ").next().unwrap_or_default().split("\n## ").next().unwrap_or_default(); | ||||||||
| assert!(!entry.is_empty(), "docs/user-guide/loss-codes.md should have the entry\n{heading}"); | ||||||||
| let action = format!("**What to do:** {}", spec.action); | ||||||||
| assert!(entry.replace('\n', " ").contains(&action), "docs/user-guide/loss-codes.md: `{}` should say\n{action}", spec.id); | ||||||||
| assert!(code.doc_url().ends_with(&format!("/user-guide/loss-codes/#{}", spec.id))); | ||||||||
| } | ||||||||
| for row in rows { | ||||||||
| let id = row.trim_start_matches("| `").split('`').next().unwrap_or_default(); | ||||||||
| assert!(LossCode::from_id(id).is_some(), "docs/cli.md lists `{id}`, which is not a loss code"); | ||||||||
| for heading in headings { | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The per-code check finds each heading by its first match (
Suggested change
Category: quality
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A duplicate heading would need someone to write one by hand, and the anchor would still resolve to the first; pinning the count is left for the release quality pass. |
||||||||
| let id = heading.trim_start_matches("### `").split('`').next().unwrap_or_default(); | ||||||||
| assert!(LossCode::from_id(id).is_some(), "docs/user-guide/loss-codes.md lists `{id}`, which is not a loss code"); | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The guide's address is written out again here, apart from
rustgis_data::loss::GUIDEon the Rust side. The two match today, so this is not a defect. But if the Rust constant moves, Python keeps the old page, and the Python test (test_session.py) pins the same literal, so it would not catch the drift. Consider reading the address from the built package or having a test compare the two.Category: quality
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two match today. The Python test checks the address it gives against a literal, not against the Rust constant, so a move on the Rust side alone wouldn't fail it. Deriving the address from the Rust constant is left for the release quality pass.