Skip to content

Commit

Permalink
Ensure empty sections are parsed but empty
Browse files Browse the repository at this point in the history
  • Loading branch information
belak authored and QEDK committed Apr 24, 2024
1 parent aef54a6 commit 1f6f20c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ini.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,8 @@ impl Ini {
(Some(0), Some(end)) => {
section = caser(trimmed[1..end].trim());

map.entry(section.clone()).or_default();

continue;
}
(Some(0), None) => {
Expand Down
19 changes: 19 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,25 @@ fn cs() -> Result<(), Box<dyn Error>> {
Ok(())
}

#[test]
fn ensure_empty_sections_exist() -> Result<(), Box<dyn Error>> {
const FILE_CONTENTS: &str = "
[basic_section]
basic_option=basic_value
[empty_section]
";

let mut config = Ini::new();
config.read(FILE_CONTENTS.to_owned())?;

assert_eq!(
config.sections(),
vec![String::from("basic_section"), String::from("empty_section")]
);

Ok(())
}

#[test]
#[cfg(feature = "indexmap")]
fn sort_on_write() -> Result<(), Box<dyn Error>> {
Expand Down

0 comments on commit 1f6f20c

Please sign in to comment.