Skip to content

Commit

Permalink
Apply recent nightly suggestions (#1286)
Browse files Browse the repository at this point in the history
array iterators are now implicit
  • Loading branch information
kirawi authored Dec 18, 2021
1 parent a668335 commit 02fc52f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
52 changes: 25 additions & 27 deletions helix-core/src/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,6 @@ fn reached_target(target: WordMotionTarget, prev_ch: char, next_ch: char) -> boo

#[cfg(test)]
mod test {
use std::array::{self, IntoIter};

use ropey::Rope;

use super::*;
Expand Down Expand Up @@ -360,7 +358,7 @@ mod test {
((Direction::Backward, 999usize), (0, 0)), // |This is a simple alphabetic line
];

for ((direction, amount), coordinates) in IntoIter::new(moves_and_expected_coordinates) {
for ((direction, amount), coordinates) in moves_and_expected_coordinates {
range = move_horizontally(slice, range, direction, amount, Movement::Move);
assert_eq!(coords_at_pos(slice, range.head), coordinates.into())
}
Expand All @@ -374,7 +372,7 @@ mod test {

let mut range = Range::point(position);

let moves_and_expected_coordinates = IntoIter::new([
let moves_and_expected_coordinates = [
((Direction::Forward, 11usize), (1, 1)), // Multiline\nt|ext sample\n...
((Direction::Backward, 1usize), (1, 0)), // Multiline\n|text sample\n...
((Direction::Backward, 5usize), (0, 5)), // Multi|line\ntext sample\n...
Expand All @@ -384,7 +382,7 @@ mod test {
((Direction::Backward, 0usize), (0, 3)), // Mul|tiline\ntext sample\n...
((Direction::Forward, 999usize), (5, 0)), // ...and whitespaced\n|
((Direction::Forward, 999usize), (5, 0)), // ...and whitespaced\n|
]);
];

for ((direction, amount), coordinates) in moves_and_expected_coordinates {
range = move_horizontally(slice, range, direction, amount, Movement::Move);
Expand All @@ -402,11 +400,11 @@ mod test {
let mut range = Range::point(position);
let original_anchor = range.anchor;

let moves = IntoIter::new([
let moves = [
(Direction::Forward, 1usize),
(Direction::Forward, 5usize),
(Direction::Backward, 3usize),
]);
];

for (direction, amount) in moves {
range = move_horizontally(slice, range, direction, amount, Movement::Extend);
Expand All @@ -420,7 +418,7 @@ mod test {
let slice = text.slice(..);
let position = pos_at_coords(slice, (0, 0).into(), true);
let mut range = Range::point(position);
let moves_and_expected_coordinates = IntoIter::new([
let moves_and_expected_coordinates = [
((Direction::Forward, 1usize), (1, 0)),
((Direction::Forward, 2usize), (3, 0)),
((Direction::Forward, 1usize), (4, 0)),
Expand All @@ -430,7 +428,7 @@ mod test {
((Direction::Backward, 0usize), (4, 0)),
((Direction::Forward, 5), (5, 0)),
((Direction::Forward, 999usize), (5, 0)),
]);
];

for ((direction, amount), coordinates) in moves_and_expected_coordinates {
range = move_vertically(slice, range, direction, amount, Movement::Move);
Expand All @@ -450,7 +448,7 @@ mod test {
H,
V,
}
let moves_and_expected_coordinates = IntoIter::new([
let moves_and_expected_coordinates = [
// Places cursor at the end of line
((Axis::H, Direction::Forward, 8usize), (0, 8)),
// First descent preserves column as the target line is wider
Expand All @@ -463,7 +461,7 @@ mod test {
((Axis::V, Direction::Backward, 999usize), (0, 8)),
((Axis::V, Direction::Forward, 4usize), (4, 8)),
((Axis::V, Direction::Forward, 999usize), (5, 0)),
]);
];

for ((axis, direction, amount), coordinates) in moves_and_expected_coordinates {
range = match axis {
Expand All @@ -489,7 +487,7 @@ mod test {
H,
V,
}
let moves_and_expected_coordinates = IntoIter::new([
let moves_and_expected_coordinates = [
// Places cursor at the fourth kana.
((Axis::H, Direction::Forward, 4), (0, 4)),
// Descent places cursor at the 4th character.
Expand All @@ -498,7 +496,7 @@ mod test {
((Axis::H, Direction::Backward, 1usize), (1, 3)),
// Jumping back up 1 line.
((Axis::V, Direction::Backward, 1usize), (0, 3)),
]);
];

for ((axis, direction, amount), coordinates) in moves_and_expected_coordinates {
range = match axis {
Expand Down Expand Up @@ -530,7 +528,7 @@ mod test {

#[test]
fn test_behaviour_when_moving_to_start_of_next_words() {
let tests = array::IntoIter::new([
let tests = [
("Basic forward motion stops at the first space",
vec![(1, Range::new(0, 0), Range::new(0, 6))]),
(" Starting from a boundary advances the anchor",
Expand Down Expand Up @@ -604,7 +602,7 @@ mod test {
vec![
(1, Range::new(0, 0), Range::new(0, 6)),
]),
]);
];

for (sample, scenario) in tests {
for (count, begin, expected_end) in scenario.into_iter() {
Expand All @@ -616,7 +614,7 @@ mod test {

#[test]
fn test_behaviour_when_moving_to_start_of_next_long_words() {
let tests = array::IntoIter::new([
let tests = [
("Basic forward motion stops at the first space",
vec![(1, Range::new(0, 0), Range::new(0, 6))]),
(" Starting from a boundary advances the anchor",
Expand Down Expand Up @@ -688,7 +686,7 @@ mod test {
vec![
(1, Range::new(0, 0), Range::new(0, 8)),
]),
]);
];

for (sample, scenario) in tests {
for (count, begin, expected_end) in scenario.into_iter() {
Expand All @@ -700,7 +698,7 @@ mod test {

#[test]
fn test_behaviour_when_moving_to_start_of_previous_words() {
let tests = array::IntoIter::new([
let tests = [
("Basic backward motion from the middle of a word",
vec![(1, Range::new(3, 3), Range::new(4, 0))]),

Expand Down Expand Up @@ -773,7 +771,7 @@ mod test {
vec![
(1, Range::new(0, 6), Range::new(6, 0)),
]),
]);
];

for (sample, scenario) in tests {
for (count, begin, expected_end) in scenario.into_iter() {
Expand All @@ -785,7 +783,7 @@ mod test {

#[test]
fn test_behaviour_when_moving_to_start_of_previous_long_words() {
let tests = array::IntoIter::new([
let tests = [
(
"Basic backward motion from the middle of a word",
vec![(1, Range::new(3, 3), Range::new(4, 0))],
Expand Down Expand Up @@ -870,7 +868,7 @@ mod test {
vec![
(1, Range::new(0, 8), Range::new(8, 0)),
]),
]);
];

for (sample, scenario) in tests {
for (count, begin, expected_end) in scenario.into_iter() {
Expand All @@ -882,7 +880,7 @@ mod test {

#[test]
fn test_behaviour_when_moving_to_end_of_next_words() {
let tests = array::IntoIter::new([
let tests = [
("Basic forward motion from the start of a word to the end of it",
vec![(1, Range::new(0, 0), Range::new(0, 5))]),
("Basic forward motion from the end of a word to the end of the next",
Expand Down Expand Up @@ -954,7 +952,7 @@ mod test {
vec![
(1, Range::new(0, 0), Range::new(0, 5)),
]),
]);
];

for (sample, scenario) in tests {
for (count, begin, expected_end) in scenario.into_iter() {
Expand All @@ -966,7 +964,7 @@ mod test {

#[test]
fn test_behaviour_when_moving_to_end_of_previous_words() {
let tests = array::IntoIter::new([
let tests = [
("Basic backward motion from the middle of a word",
vec![(1, Range::new(9, 9), Range::new(10, 5))]),
("Starting from after boundary retreats the anchor",
Expand Down Expand Up @@ -1036,7 +1034,7 @@ mod test {
vec![
(1, Range::new(0, 10), Range::new(10, 4)),
]),
]);
];

for (sample, scenario) in tests {
for (count, begin, expected_end) in scenario.into_iter() {
Expand All @@ -1048,7 +1046,7 @@ mod test {

#[test]
fn test_behaviour_when_moving_to_end_of_next_long_words() {
let tests = array::IntoIter::new([
let tests = [
("Basic forward motion from the start of a word to the end of it",
vec![(1, Range::new(0, 0), Range::new(0, 5))]),
("Basic forward motion from the end of a word to the end of the next",
Expand Down Expand Up @@ -1118,7 +1116,7 @@ mod test {
vec![
(1, Range::new(0, 0), Range::new(0, 7)),
]),
]);
];

for (sample, scenario) in tests {
for (count, begin, expected_end) in scenario.into_iter() {
Expand Down
2 changes: 1 addition & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1938,7 +1938,7 @@ fn append_mode(cx: &mut Context) {
if !last_range.is_empty() && last_range.head == end {
let transaction = Transaction::change(
doc.text(),
std::array::IntoIter::new([(end, end, Some(doc.line_ending.as_str().into()))]),
[(end, end, Some(doc.line_ending.as_str().into()))].into_iter(),
);
doc.apply(&transaction, view.id);
}
Expand Down
2 changes: 1 addition & 1 deletion helix-term/src/ui/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl Prompt {
let mut char_position = char_indices
.iter()
.position(|(idx, _)| *idx == self.cursor)
.unwrap_or_else(|| char_indices.len());
.unwrap_or(char_indices.len());

for _ in 0..rep {
// Skip any non-whitespace characters
Expand Down

0 comments on commit 02fc52f

Please sign in to comment.