From 0cf00851dc88ed8013a35747c803b6c83db83761 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 5 Feb 2023 14:09:08 -0500 Subject: clippy --- tests/helpers/fixtures.rs | 19 ++++++++----------- tests/helpers/mod.rs | 4 ++-- tests/quickcheck.rs | 5 ++--- tests/split-escapes.rs | 8 +++----- tests/window_contents.rs | 2 +- 5 files changed, 16 insertions(+), 22 deletions(-) (limited to 'tests') diff --git a/tests/helpers/fixtures.rs b/tests/helpers/fixtures.rs index c0f8b75..bc39926 100644 --- a/tests/helpers/fixtures.rs +++ b/tests/helpers/fixtures.rs @@ -96,7 +96,7 @@ impl FixtureScreen { let cell = screen.cell(row, col).unwrap(); if cell != &vt100::Cell::default() { cells.insert( - format!("{},{}", row, col), + format!("{row},{col}"), FixtureCell::from_cell(cell), ); } @@ -159,8 +159,8 @@ where { let s = match color { vt100::Color::Default => unreachable!(), - vt100::Color::Idx(n) => format!("{}", n), - vt100::Color::Rgb(r, g, b) => format!("#{:02x}{:02x}{:02x}", r, g, b), + vt100::Color::Idx(n) => format!("{n}"), + vt100::Color::Rgb(r, g, b) => format!("#{r:02x}{g:02x}{b:02x}"), }; serializer.serialize_str(&s) } @@ -231,8 +231,7 @@ where fn load_input(name: &str, i: usize) -> Option> { let mut file = std::fs::File::open(format!( - "tests/data/fixtures/{}/{}.typescript", - name, i + "tests/data/fixtures/{name}/{i}.typescript" )) .ok()?; let mut input = vec![]; @@ -241,11 +240,9 @@ fn load_input(name: &str, i: usize) -> Option> { } fn load_screen(name: &str, i: usize) -> Option { - let mut file = std::fs::File::open(format!( - "tests/data/fixtures/{}/{}.json", - name, i - )) - .ok()?; + let mut file = + std::fs::File::open(format!("tests/data/fixtures/{name}/{i}.json")) + .ok()?; Some(FixtureScreen::load(&mut file)) } @@ -281,7 +278,7 @@ fn assert_produces(input: &[u8], expected: &FixtureScreen) { for col in 0..cols { let expected_cell = expected .cells - .get(&format!("{},{}", row, col)) + .get(&format!("{row},{col}")) .cloned() .unwrap_or_default(); let got_cell = parser.screen().cell(row, col).unwrap(); diff --git a/tests/helpers/mod.rs b/tests/helpers/mod.rs index dc08ce5..67bb1f4 100644 --- a/tests/helpers/mod.rs +++ b/tests/helpers/mod.rs @@ -46,7 +46,7 @@ impl<'a> std::fmt::Debug for Bytes<'a> { 13 => f.write_str("\\r")?, 92 => f.write_str("\\\\")?, 32..=126 => f.write_str(&char::from(*c).to_string())?, - _ => f.write_fmt(format_args!("\\x{:02x}", c))?, + _ => f.write_fmt(format_args!("\\x{c:02x}"))?, } } f.write_str("\"")?; @@ -267,7 +267,7 @@ pub fn format_bytes(bytes: &[u8]) -> String { 13 => v.extend(b"\\r"), 27 => v.extend(b"\\e"), c if c < 32 || c == 127 => { - v.extend(format!("\\x{:02x}", c).as_bytes()) + v.extend(format!("\\x{c:02x}").as_bytes()) } b => v.push(b), } diff --git a/tests/quickcheck.rs b/tests/quickcheck.rs index efb6f63..3591285 100644 --- a/tests/quickcheck.rs +++ b/tests/quickcheck.rs @@ -13,8 +13,7 @@ impl quickcheck::Arbitrary for TerminalInput { }; TerminalInput( (0..size) - .map(|_| choose_terminal_input_fragment(g)) - .flatten() + .flat_map(|_| choose_terminal_input_fragment(g)) .collect(), ) } @@ -59,7 +58,7 @@ fn choose_terminal_input_fragment(g: &mut G) -> Vec { let c: Result = std::convert::TryFrom::try_from(u); let c = match c { Ok(c) => c, - Err(e) => panic!("failed to create char from {}: {}", u, e), + Err(e) => panic!("failed to create char from {u}: {e}"), }; let mut b = [0; 4]; let s = c.encode_utf8(&mut b); diff --git a/tests/split-escapes.rs b/tests/split-escapes.rs index fa5b6b1..36fb647 100644 --- a/tests/split-escapes.rs +++ b/tests/split-escapes.rs @@ -7,7 +7,7 @@ fn get_file_contents(name: &str) -> Vec { buf } -fn write_to_parser(chunks: &mut Vec>) -> (String, Vec) { +fn write_to_parser(chunks: &mut [Vec]) -> (String, Vec) { let mut parser = vt100::Parser::new(37, 193, 0); for chunk in chunks.iter_mut() { parser.process(chunk); @@ -21,7 +21,7 @@ fn write_to_parser(chunks: &mut Vec>) -> (String, Vec) { fn test_splits(filename: &str, limit: Option) { let bytes = get_file_contents(filename); let len = bytes.len(); - let expected = write_to_parser(&mut vec![bytes.clone()]); + let expected = write_to_parser(&mut [bytes.clone()]); for i in 0..(len - 1) { if let Some(limit) = limit { if i > limit { @@ -34,9 +34,7 @@ fn test_splits(filename: &str, limit: Option) { let got = write_to_parser(&mut chunks); assert!( got == expected, - "failed to render {} when split at byte {}", - filename, - i + "failed to render {filename} when split at byte {i}" ); } } diff --git a/tests/window_contents.rs b/tests/window_contents.rs index a300438..a3df341 100644 --- a/tests/window_contents.rs +++ b/tests/window_contents.rs @@ -556,7 +556,7 @@ fn diff_crawl(i: usize) { let screens: Vec<_> = (1..=i) .map(|i| { let mut file = - std::fs::File::open(format!("tests/data/crawl/crawl{}", i)) + std::fs::File::open(format!("tests/data/crawl/crawl{i}")) .unwrap(); let mut frame = vec![]; file.read_to_end(&mut frame).unwrap(); -- cgit v1.2.3-54-g00ecf