use crate::{error::Error, types::Section};
pub fn parse_text(input: &str) -> Result<Vec<Section>, Error> {
if input.is_empty() {
return Ok(Vec::new());
}
Ok(vec![Section {
heading: None,
depth: 0,
text: input.to_string(),
byte_range: 0..input.len(),
}])
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn single_section_pass_through() {
let input = "hello\nworld\n";
let sections = parse_text(input).unwrap();
assert_eq!(sections.len(), 1);
assert!(sections[0].heading.is_none());
assert_eq!(sections[0].depth, 0);
assert_eq!(sections[0].text, input);
}
#[test]
fn byte_range_covers_full_input() {
let input = "some plain text";
let sections = parse_text(input).unwrap();
assert_eq!(sections[0].byte_range, 0..input.len());
}
#[test]
fn empty_input_yields_no_sections() {
let sections = parse_text("").unwrap();
assert!(sections.is_empty());
}
}