apif_utils/ast.rs
1/// Convert a section-relative line index to an absolute line number.
2///
3/// `start_line` is the line where the section header begins.
4/// `idx` is the 0-based index within the section content lines.
5/// The `+ 2` accounts for: (1) the header line itself, (2) the blank/content separator.
6pub fn section_content_line(start_line: usize, idx: usize) -> usize {
7 start_line + idx + 2
8}
9
10#[cfg(test)]
11mod tests {
12 use super::*;
13
14 #[test]
15 fn test_section_content_line_first() {
16 assert_eq!(section_content_line(5, 0), 7);
17 }
18
19 #[test]
20 fn test_section_content_line_offset() {
21 assert_eq!(section_content_line(10, 3), 15);
22 }
23}