Skip to main content

apif_utils/
ast.rs

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