Skip to content

Commit d9c841b

Browse files
committed
Fix/silence various clippy warnings in test code.
Didn't realize there was an easy way to run clippy on tests. Thanks to @LittleTasteOfHeaven for making me aware!
1 parent 97be0f4 commit d9c841b

11 files changed

+82
-83
lines changed

examples/graphemes_iter.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! of a `Rope` or `RopeSlice`. This also serves as a good starting point for
33
//! iterators for other kinds of segementation, such as word boundaries.
44
5+
#![allow(clippy::redundant_field_names)]
56
#![allow(dead_code)]
67

78
extern crate ropey;

examples/search_and_replace.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
//! The file contents with the search-and-replace performed on it is sent to
88
//! stdout.
99
10+
#![allow(clippy::redundant_field_names)]
11+
1012
extern crate ropey;
1113

1214
use std::fs::File;
@@ -83,8 +85,7 @@ fn search_and_replace(rope: &mut Rope, search_pattern: &str, replacement_text: &
8385
// `Iterator::collect()` to collect the batch because we want to
8486
// re-use the same Vec to avoid unnecessary allocations.
8587
matches.clear();
86-
for m in SearchIter::from_rope_slice(&rope.slice(head..), &search_pattern).take(BATCH_SIZE)
87-
{
88+
for m in SearchIter::from_rope_slice(&rope.slice(head..), search_pattern).take(BATCH_SIZE) {
8889
matches.push(m);
8990
}
9091

@@ -102,7 +103,7 @@ fn search_and_replace(rope: &mut Rope, search_pattern: &str, replacement_text: &
102103

103104
// Do the replacement.
104105
rope.remove(start_d..end_d);
105-
rope.insert(start_d, &replacement_text);
106+
rope.insert(start_d, replacement_text);
106107

107108
// Update the index offset.
108109
let match_len = (end - start) as isize;
@@ -153,6 +154,7 @@ impl<'a> Iterator for SearchIter<'a> {
153154

154155
// Return the start/end char indices of the next match.
155156
fn next(&mut self) -> Option<(usize, usize)> {
157+
#[allow(clippy::while_let_on_iterator)]
156158
while let Some(next_char) = self.char_iter.next() {
157159
self.cur_index += 1;
158160

examples/simple_buffer.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(clippy::redundant_field_names)]
12
#![allow(dead_code)]
23

34
extern crate ropey;
@@ -24,23 +25,23 @@ impl TextBuffer {
2425
})
2526
}
2627

27-
fn get_line<'a>(&'a self, idx: usize) -> RopeSlice<'a> {
28+
fn get_line(&self, idx: usize) -> RopeSlice {
2829
self.text.line(idx)
2930
}
3031

31-
fn bytes<'a>(&'a self) -> Bytes<'a> {
32+
fn bytes(&self) -> Bytes {
3233
self.text.bytes()
3334
}
3435

35-
fn chars<'a>(&'a self) -> Chars<'a> {
36+
fn chars(&self) -> Chars {
3637
self.text.chars()
3738
}
3839

39-
fn lines<'a>(&'a self) -> Lines<'a> {
40+
fn lines(&self) -> Lines {
4041
self.text.lines()
4142
}
4243

43-
fn chunks<'a>(&'a self) -> Chunks<'a> {
44+
fn chunks(&self) -> Chunks {
4445
self.text.chunks()
4546
}
4647

src/iter.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,7 @@ impl<'a> Iterator for Chunks<'a> {
13681368

13691369
#[cfg(test)]
13701370
mod tests {
1371+
#![allow(clippy::while_let_on_iterator)]
13711372
use super::*;
13721373
use crate::Rope;
13731374

src/rope.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -2367,7 +2367,8 @@ mod tests {
23672367
#[should_panic]
23682368
fn remove_06() {
23692369
let mut r = Rope::from_str(TEXT);
2370-
r.remove(56..55); // Wrong ordering of start/end
2370+
#[allow(clippy::reversed_empty_ranges)]
2371+
r.remove(56..55); // Wrong ordering of start/end on purpose.
23712372
}
23722373

23732374
#[test]
@@ -3152,7 +3153,8 @@ mod tests {
31523153
#[should_panic]
31533154
fn slice_05() {
31543155
let r = Rope::from_str(TEXT);
3155-
r.slice(53..52);
3156+
#[allow(clippy::reversed_empty_ranges)]
3157+
r.slice(53..52); // Wrong ordering on purpose.
31563158
}
31573159

31583160
#[test]
@@ -3202,7 +3204,8 @@ mod tests {
32023204
#[should_panic]
32033205
fn byte_slice_05() {
32043206
let r = Rope::from_str(TEXT);
3205-
r.byte_slice(53..52);
3207+
#[allow(clippy::reversed_empty_ranges)]
3208+
r.byte_slice(53..52); // Wrong ordering on purpose.
32063209
}
32073210

32083211
#[test]

src/slice.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2759,7 +2759,8 @@ mod tests {
27592759
let r = Rope::from_str(TEXT);
27602760
let s = r.slice(5..43);
27612761

2762-
s.slice(21..20);
2762+
#[allow(clippy::reversed_empty_ranges)]
2763+
s.slice(21..20); // Wrong ordering on purpose.
27632764
}
27642765

27652766
#[test]
@@ -2828,7 +2829,8 @@ mod tests {
28282829
let r = Rope::from_str(TEXT);
28292830
let s = r.byte_slice(50..118);
28302831

2831-
s.byte_slice(21..20);
2832+
#[allow(clippy::reversed_empty_ranges)]
2833+
s.byte_slice(21..20); // Wrong ordering on purpose.
28322834
}
28332835

28342836
#[test]

src/str_utils.rs

+30-30
Original file line numberDiff line numberDiff line change
@@ -207,60 +207,60 @@ mod tests {
207207

208208
#[test]
209209
fn ends_with_line_break_01() {
210-
assert_eq!(true, ends_with_line_break("\n"));
210+
assert!(ends_with_line_break("\n"));
211211

212212
#[cfg(any(feature = "cr_lines", feature = "unicode_lines"))]
213-
assert_eq!(true, ends_with_line_break("\r"));
213+
assert!(ends_with_line_break("\r"));
214214

215215
#[cfg(feature = "unicode_lines")]
216216
{
217-
assert_eq!(true, ends_with_line_break("\u{000A}"));
218-
assert_eq!(true, ends_with_line_break("\u{000B}"));
219-
assert_eq!(true, ends_with_line_break("\u{000C}"));
220-
assert_eq!(true, ends_with_line_break("\u{000D}"));
221-
assert_eq!(true, ends_with_line_break("\u{0085}"));
222-
assert_eq!(true, ends_with_line_break("\u{2028}"));
223-
assert_eq!(true, ends_with_line_break("\u{2029}"));
217+
assert!(ends_with_line_break("\u{000A}"));
218+
assert!(ends_with_line_break("\u{000B}"));
219+
assert!(ends_with_line_break("\u{000C}"));
220+
assert!(ends_with_line_break("\u{000D}"));
221+
assert!(ends_with_line_break("\u{0085}"));
222+
assert!(ends_with_line_break("\u{2028}"));
223+
assert!(ends_with_line_break("\u{2029}"));
224224
}
225225
}
226226

227227
#[test]
228228
fn ends_with_line_break_02() {
229-
assert_eq!(true, ends_with_line_break("Hi there!\n"));
229+
assert!(ends_with_line_break("Hi there!\n"));
230230

231231
#[cfg(any(feature = "cr_lines", feature = "unicode_lines"))]
232-
assert_eq!(true, ends_with_line_break("Hi there!\r"));
232+
assert!(ends_with_line_break("Hi there!\r"));
233233

234234
#[cfg(feature = "unicode_lines")]
235235
{
236-
assert_eq!(true, ends_with_line_break("Hi there!\u{000A}"));
237-
assert_eq!(true, ends_with_line_break("Hi there!\u{000B}"));
238-
assert_eq!(true, ends_with_line_break("Hi there!\u{000C}"));
239-
assert_eq!(true, ends_with_line_break("Hi there!\u{000D}"));
240-
assert_eq!(true, ends_with_line_break("Hi there!\u{0085}"));
241-
assert_eq!(true, ends_with_line_break("Hi there!\u{2028}"));
242-
assert_eq!(true, ends_with_line_break("Hi there!\u{2029}"));
236+
assert!(ends_with_line_break("Hi there!\u{000A}"));
237+
assert!(ends_with_line_break("Hi there!\u{000B}"));
238+
assert!(ends_with_line_break("Hi there!\u{000C}"));
239+
assert!(ends_with_line_break("Hi there!\u{000D}"));
240+
assert!(ends_with_line_break("Hi there!\u{0085}"));
241+
assert!(ends_with_line_break("Hi there!\u{2028}"));
242+
assert!(ends_with_line_break("Hi there!\u{2029}"));
243243
}
244244
}
245245

246246
#[test]
247247
fn ends_with_line_break_03() {
248-
assert_eq!(false, ends_with_line_break(""));
249-
assert_eq!(false, ends_with_line_break("a"));
250-
assert_eq!(false, ends_with_line_break("Hi there!"));
248+
assert!(!ends_with_line_break(""));
249+
assert!(!ends_with_line_break("a"));
250+
assert!(!ends_with_line_break("Hi there!"));
251251
}
252252

253253
#[test]
254254
fn ends_with_line_break_04() {
255-
assert_eq!(false, ends_with_line_break("\na"));
256-
assert_eq!(false, ends_with_line_break("\ra"));
257-
assert_eq!(false, ends_with_line_break("\u{000A}a"));
258-
assert_eq!(false, ends_with_line_break("\u{000B}a"));
259-
assert_eq!(false, ends_with_line_break("\u{000C}a"));
260-
assert_eq!(false, ends_with_line_break("\u{000D}a"));
261-
assert_eq!(false, ends_with_line_break("\u{0085}a"));
262-
assert_eq!(false, ends_with_line_break("\u{2028}a"));
263-
assert_eq!(false, ends_with_line_break("\u{2029}a"));
255+
assert!(!ends_with_line_break("\na"));
256+
assert!(!ends_with_line_break("\ra"));
257+
assert!(!ends_with_line_break("\u{000A}a"));
258+
assert!(!ends_with_line_break("\u{000B}a"));
259+
assert!(!ends_with_line_break("\u{000C}a"));
260+
assert!(!ends_with_line_break("\u{000D}a"));
261+
assert!(!ends_with_line_break("\u{0085}a"));
262+
assert!(!ends_with_line_break("\u{2028}a"));
263+
assert!(!ends_with_line_break("\u{2029}a"));
264264
}
265265

266266
#[test]

src/tree/node.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -1023,16 +1023,11 @@ mod tests {
10231023
fn crlf_corner_case_01() {
10241024
use super::Node;
10251025
use crate::tree::{NodeChildren, NodeText, MAX_BYTES};
1026-
use std::iter;
10271026
use std::sync::Arc;
10281027

10291028
// Construct the corner case
1030-
let nodel = Node::Leaf(NodeText::from_str(
1031-
&iter::repeat("\n").take(MAX_BYTES - 1).collect::<String>(),
1032-
));
1033-
let noder = Node::Leaf(NodeText::from_str(
1034-
&iter::repeat("\n").take(MAX_BYTES).collect::<String>(),
1035-
));
1029+
let nodel = Node::Leaf(NodeText::from_str(&"\n".repeat(MAX_BYTES - 1)));
1030+
let noder = Node::Leaf(NodeText::from_str(&"\n".repeat(MAX_BYTES)));
10361031
let mut children = NodeChildren::new();
10371032
children.push((nodel.text_info(), Arc::new(nodel)));
10381033
children.push((noder.text_info(), Arc::new(noder)));
@@ -1051,16 +1046,11 @@ mod tests {
10511046
fn crlf_corner_case_02() {
10521047
use super::Node;
10531048
use crate::tree::{NodeChildren, NodeText, MAX_BYTES};
1054-
use std::iter;
10551049
use std::sync::Arc;
10561050

10571051
// Construct the corner case
1058-
let nodel = Node::Leaf(NodeText::from_str(
1059-
&iter::repeat("\r").take(MAX_BYTES).collect::<String>(),
1060-
));
1061-
let noder = Node::Leaf(NodeText::from_str(
1062-
&iter::repeat("\r").take(MAX_BYTES - 1).collect::<String>(),
1063-
));
1052+
let nodel = Node::Leaf(NodeText::from_str(&"\r".repeat(MAX_BYTES)));
1053+
let noder = Node::Leaf(NodeText::from_str(&"\r".repeat(MAX_BYTES - 1)));
10641054
let mut children = NodeChildren::new();
10651055
children.push((nodel.text_info(), Arc::new(nodel)));
10661056
children.push((noder.text_info(), Arc::new(noder)));

tests/clone_rope.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ fn clone_rope() {
2828
let matches = Iterator::zip(rope1.chars(), rope2.chars())
2929
.map(|(a, b)| a == b)
3030
.all(|n| n);
31-
assert_eq!(matches, true);
31+
assert!(matches);
3232

3333
// Insert something into the clone, and make sure they don't match
3434
// afterwards.
3535
rope2.insert(3891, "I'm doing fine, thanks!");
3636
let matches = Iterator::zip(rope1.chars(), rope2.chars())
3737
.map(|(a, b)| a == b)
3838
.all(|n| n);
39-
assert_eq!(matches, false);
39+
assert!(!matches);
4040
}

tests/clone_rope_to_thread.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn clone_rope_to_thread() {
5151
let matches = Iterator::zip(rope1.chars(), rope2.chars())
5252
.map(|(a, b)| a == b)
5353
.all(|n| n);
54-
assert_eq!(matches, true);
54+
assert!(matches);
5555

5656
// Send rope2 to the other thread again for more modifications.
5757
tx1.send(rope2).unwrap();
@@ -61,5 +61,5 @@ fn clone_rope_to_thread() {
6161
let matches = Iterator::zip(rope1.chars(), rope2.chars())
6262
.map(|(a, b)| a == b)
6363
.all(|n| n);
64-
assert_eq!(matches, false);
64+
assert!(!matches);
6565
}

0 commit comments

Comments
 (0)