Skip to content

Commit

Permalink
fix steps in components mode and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Zheoni committed Oct 19, 2023
1 parent c165c17 commit d2be0d5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/analysis/ast_walker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ impl<'i, 'c> RecipeCollector<'i, 'c> {
// If define mode is ingredients, don't add the
// step to the section. The components should have been
// added to their lists
if new_content.is_step() && self.define_mode != DefineMode::Components {
self.step_counter += 1;
self.current_section.content.push(new_content);
} else {
if self.define_mode != DefineMode::Components || new_content.is_text() {
if new_content.is_step() {
self.step_counter += 1;
}
self.current_section.content.push(new_content);
}

Expand Down
18 changes: 18 additions & 0 deletions tests/general_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,21 @@ fn multiple_temperatures() {
]
);
}

#[test]
fn no_steps_component_mode() {
let input = indoc! {r#"
>> [mode]: components
@igr
>> [mode]: steps
= section
step
"#};
let r = cooklang::parse(input).take_output().unwrap();
assert_eq!(r.sections.len(), 1);
assert_eq!(r.sections[0].name.as_deref(), Some("section"));
assert!(matches!(
r.sections[0].content.as_slice(),
[Content::Step(_)]
));
}

0 comments on commit d2be0d5

Please sign in to comment.