Skip to content

Commit

Permalink
Add remove_statement and tests (complete)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiwonz committed Jan 27, 2025
1 parent 327ced2 commit b56033b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/nodes/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ impl Block {
self.statements.push(statement.into());
}

pub fn remove_statement(&mut self, index: usize) {
self.statements.remove(index);
if let Some(tokens) = &mut self.tokens {
tokens.semicolons.remove(index);
}
}

pub fn with_statement<T: Into<Statement>>(mut self, statement: T) -> Self {
self.statements.push(statement.into());
self
Expand Down Expand Up @@ -407,6 +414,15 @@ mod test {
);
}

#[test]
fn remove_statement() {
let mut block = parse_block_with_tokens("while true do end");

block.remove_statement(0);

assert!(block.is_empty());
}

#[test]
fn clean_removes_semicolon_tokens() {
let mut block = Block::default()
Expand Down

0 comments on commit b56033b

Please sign in to comment.