Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Add test for insert only suggestion #107

Merged
merged 6 commits into from
May 18, 2018
Merged

Conversation

yaahc
Copy link
Member

@yaahc yaahc commented May 16, 2018

  • Also remove the ensure that prevents handling of insert only
    suggestions

yaahc added 2 commits May 16, 2018 13:48
* Also remove the ensure that prevents handling of insert only
suggestions
src/replace.rs Outdated
@@ -75,6 +70,8 @@ impl Data {
self.original.len()
);

let insert_only = from > up_to_and_including;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel like this should check that its== from+1 and the ensure above should check for that, i think ranges where from is 2 or more are still invalid, not sure if its worth testing for that or its one of those "I assume this will actually never happen" things.

src/replace.rs Outdated
@@ -135,7 +143,8 @@ impl Data {
if from > part_to_split.start {
new_parts.push(Span {
start: part_to_split.start,
end: from,
// end: if insert_only { from - 1 } else { from },
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gonna remove this

* Also adds a test for invalid ranges, specifically looking for ranges
that are neither replace nor insert, as in the exclusive_end is less
than the start.
@yaahc
Copy link
Member Author

yaahc commented May 17, 2018

#103

Copy link
Member

@killercup killercup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

Looking at CI, it seems that proptest found some issues with replace::tests::new_to_vec_roundtrip, though (a quickcheck-like tool for property testing, you can run it with cargo test --all -- --ignored).

The first problems are easily fixed by changing the x - 1s to x.saturating_sub(1)s, which I've commented on in the diff. Another error is Test failed: index 1 out of range for slice of length 0; minimal failing input: ref s = "" which gets triggered in the to_vec method.

src/replace.rs Outdated
@@ -36,7 +37,7 @@ impl Data {
Span {
data: State::Initial,
start: 0,
end: data.len(),
end: data.len() - 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's replace this with data.len().saturating_sub(1) so it can never underflow (0.saturating_sub(1) == 0)

src/replace.rs Outdated
@@ -135,7 +152,7 @@ impl Data {
if from > part_to_split.start {
new_parts.push(Span {
start: part_to_split.start,
end: from,
end: from - 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's replace this with from.saturating_sub(1) so it can never underflow

src/replace.rs Outdated
} else {
false
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to see the closure work! Looking at how it is used here, it might be more idiomatic to write this as a method on State, though

Copy link
Member

@killercup killercup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! Thanks so much for working on this!

@killercup killercup merged commit 85aa218 into rust-lang:master May 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants