Skip to content

Commit

Permalink
remove Indentation::add_capture return type
Browse files Browse the repository at this point in the history
Inexplicably, this makes Rust indentation incorrect
  • Loading branch information
dead10ck committed Jun 25, 2023
1 parent 899a970 commit 9dd8a2a
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions helix-core/src/indent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl Indentation {

/// Add an indent capture to this indent.
/// All the captures that are added in this way should be on the same line.
fn add_capture(&mut self, added: IndentCaptureType) -> &mut Self {
fn add_capture(&mut self, added: IndentCaptureType) {
match added {
IndentCaptureType::Indent => {
if self.indent_always == 0 {
Expand All @@ -281,8 +281,6 @@ impl Indentation {
self.outdent = 0;
}
}

self
}

fn as_string(&self, indent_style: &IndentStyle) -> String {
Expand Down Expand Up @@ -911,39 +909,44 @@ mod test {
..Default::default()
};

let add_capture = |mut indent: Indentation, capture| {
indent.add_capture(capture);
indent
};

// adding an indent to no indent makes an indent
assert_eq!(
indent(),
*Indentation::default().add_capture(IndentCaptureType::Indent)
add_capture(Indentation::default(), IndentCaptureType::Indent)
);
assert_eq!(
indent_always(),
*Indentation::default().add_capture(IndentCaptureType::IndentAlways)
add_capture(Indentation::default(), IndentCaptureType::IndentAlways)
);
assert_eq!(
outdent(),
*Indentation::default().add_capture(IndentCaptureType::Outdent)
add_capture(Indentation::default(), IndentCaptureType::Outdent)
);
assert_eq!(
outdent_always(),
*Indentation::default().add_capture(IndentCaptureType::OutdentAlways)
add_capture(Indentation::default(), IndentCaptureType::OutdentAlways)
);

// adding an indent to an already indented has no effect
assert_eq!(indent(), *indent().add_capture(IndentCaptureType::Indent));
assert_eq!(indent(), add_capture(indent(), IndentCaptureType::Indent));
assert_eq!(
outdent(),
*outdent().add_capture(IndentCaptureType::Outdent)
add_capture(outdent(), IndentCaptureType::Outdent)
);

// adding an always to a regular makes it always
assert_eq!(
indent_always(),
*indent().add_capture(IndentCaptureType::IndentAlways)
add_capture(indent(), IndentCaptureType::IndentAlways)
);
assert_eq!(
outdent_always(),
*outdent().add_capture(IndentCaptureType::OutdentAlways)
add_capture(outdent(), IndentCaptureType::OutdentAlways)
);

// adding an always to an always is additive
Expand All @@ -952,14 +955,14 @@ mod test {
indent_always: 2,
..Default::default()
},
*indent_always().add_capture(IndentCaptureType::IndentAlways)
add_capture(indent_always(), IndentCaptureType::IndentAlways)
);
assert_eq!(
Indentation {
outdent_always: 2,
..Default::default()
},
*outdent_always().add_capture(IndentCaptureType::OutdentAlways)
add_capture(outdent_always(), IndentCaptureType::OutdentAlways)
);

// adding regular to always should be associative
Expand All @@ -968,36 +971,40 @@ mod test {
indent_always: 1,
..Default::default()
},
*indent()
.add_capture(IndentCaptureType::Indent)
.add_capture(IndentCaptureType::IndentAlways)
add_capture(
add_capture(indent(), IndentCaptureType::Indent),
IndentCaptureType::IndentAlways
)
);
assert_eq!(
Indentation {
indent_always: 1,
..Default::default()
},
*indent()
.add_capture(IndentCaptureType::IndentAlways)
.add_capture(IndentCaptureType::Indent)
add_capture(
add_capture(indent(), IndentCaptureType::IndentAlways),
IndentCaptureType::Indent
)
);
assert_eq!(
Indentation {
outdent_always: 1,
..Default::default()
},
*outdent()
.add_capture(IndentCaptureType::Outdent)
.add_capture(IndentCaptureType::OutdentAlways)
add_capture(
add_capture(outdent(), IndentCaptureType::Outdent),
IndentCaptureType::OutdentAlways
)
);
assert_eq!(
Indentation {
outdent_always: 1,
..Default::default()
},
*outdent()
.add_capture(IndentCaptureType::OutdentAlways)
.add_capture(IndentCaptureType::Outdent)
add_capture(
add_capture(outdent(), IndentCaptureType::OutdentAlways),
IndentCaptureType::Outdent
)
);
}
}

0 comments on commit 9dd8a2a

Please sign in to comment.