requirements.authoring.line_numbers.detection
Requirements index · View definition
Requirement
A rationale MUST be treated as citing line numbers when it contains a file path followed by
:and a digit, the wordlineorlinesin any case followed by a number, or a parenthesized number range such as(12–30)or(12-30).
Rationale
The requirement has one MUST with three detection forms. Each is implemented by the LINE_NUMBERS regex in src/authoring/line_numbers.rs#static[LINE_NUMBERS]. src/authoring/line_numbers.rs#fn[cited] applies that regex to a rationale and returns the first match. Both items carry the {impl} reference.
- File path followed by
:and a digit. The first alternative,(?:[\w.-]+/)*[\w-]+\.[A-Za-z][A-Za-z0-9]*:\d, matchessrc/lib.rs:12andCargo.toml:4. Requiring the extension to start with a letter rejects version-like text such as0.1:9. It also rejects12.30:15. - The word
lineorlinesin any case, followed by a number. The second alternative,(?i:\blines?)\s+\d, is case-insensitive and uses a word boundary. It matcheson line 7andLines 10 to 12. It does not matchdeadline 7orinline 3, andtwo lines of outputhas no number after it. - A parenthesized number range. The third alternative,
\(\s*\d+\s*[-–]\s*\d+\s*\), accepts both the en dash and the hyphen. It matches(12–30),(12-30)and( 3 - 4 ), but not(1).
Testing. mod[tests]/fn[line_numbers_are_detected_in_each_form] carries the {test} reference. It asserts that cited detects every form, including the hyphen and en dash ranges and the mixed-case Lines. It also asserts that cited returns None for near-miss inputs:
- bare paths such as
src/lib.rs#fn[check] deadline 7 days3:40.1:9(1)
It also checks that the first match is the one returned.
Other points.
- I found no unspecified observable behavior. Returning the first matched text is a natural way to expose the detection.
- Every obligation is covered by an
{impl}item and a test, so I found no gaps.
Inputs
Implementation
Input 2: outline src/authoring/line_numbers.rs static[LINE_NUMBERS]
- File:
src/authoring/line_numbers.rs - Selector:
static[LINE_NUMBERS] - Kind:
static src/authoring/line_numbers.rs:8–21
/// The forms of a line-number citation: a file path followed by `:` and a
/// digit, `line` or `lines` followed by a number, or a parenthesized number
/// range.
// {impl}`requirements.authoring.line_numbers.detection`
static LINE_NUMBERS: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(concat!(
// A file path's extension starts with a letter, so a version
// such as `0.1:9` is not one.
r"(?:[\w.-]+/)*[\w-]+\.[A-Za-z][A-Za-z0-9]*:\d",
r"|(?i:\blines?)\s+\d",
r"|\(\s*\d+\s*[-–]\s*\d+\s*\)",
))
.expect("line-number pattern")
});
Input 3: outline src/authoring/line_numbers.rs fn[cited]
- File:
src/authoring/line_numbers.rs - Selector:
fn[cited] - Kind:
fn src/authoring/line_numbers.rs:23–27
/// The first text in `rationale` that cites line numbers, if any.
// {impl}`requirements.authoring.line_numbers.detection`
pub(crate) fn cited(rationale: &str) -> Option<&str> {
LINE_NUMBERS.find(rationale).map(|found| found.as_str())
}
Tests
Input 4: outline src/authoring/line_numbers.rs mod[tests]/fn[line_numbers_are_detected_in_each_form]
- File:
src/authoring/line_numbers.rs - Selector:
mod[tests]/fn[line_numbers_are_detected_in_each_form] - Kind:
fn src/authoring/line_numbers.rs:150–180
// {test}`requirements.authoring.line_numbers.detection`
#[test]
fn line_numbers_are_detected_in_each_form() {
for text in [
"see src/lib.rs:12",
"`tests/cli.rs:3-9` covers it",
"Cargo.toml:4",
"on line 7",
"Lines 10 to 12",
"`check` (12–30) handles it",
"`check` (12-30)",
"( 3 - 4 )",
] {
assert!(cited(text).is_some(), "{text}");
}
for text in [
"`src/lib.rs#fn[check]` covers it",
"`src/lib.rs` and `requirements.ci.errors`",
"the deadline 7 days",
"inline 3 items",
"two lines of output",
"(see the example)",
"a ratio of 3:4",
"version 0.1:9",
"at 12.30:15",
"(1)",
] {
assert_eq!(cited(text), None, "{text}");
}
assert_eq!(cited("at src/a.rs:5 and line 3"), Some("src/a.rs:5"));
}
Other sources
Input 1: requirements selection requirements.authoring.line_numbers.detection
requirements.authoring.line_numbers.detection:md/requirements/authoring.md:1251–1255
:::{req} line_numbers.detection
A rationale MUST be treated as citing line numbers when it contains a file path
followed by `:` and a digit, the word `line` or `lines` in any case followed by
a number, or a parenthesized number range such as `(12–30)` or `(12-30)`.
:::