Skip to content

Commit

Permalink
fix clippy (valence-rs#623)
Browse files Browse the repository at this point in the history
make clippy happy.
  • Loading branch information
JackCrumpLeys authored Jun 21, 2024
1 parent 83e3e29 commit 646a76e
Show file tree
Hide file tree
Showing 36 changed files with 570 additions and 501 deletions.
20 changes: 10 additions & 10 deletions benches/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 5,15 @@ use valence::block::{BlockKind, BlockState, PropName, PropValue};
use valence::ItemKind;

#[divan::bench]
pub fn from_kind(bencher: Bencher) {
pub(crate) fn from_kind(bencher: Bencher) {
bencher.bench(|| {
for kind in black_box(BlockKind::ALL) {
black_box(BlockState::from_kind(kind));
}
});
}
#[divan::bench]
pub fn to_kind(bencher: Bencher) {
pub(crate) fn to_kind(bencher: Bencher) {
let states = BlockKind::ALL.map(BlockKind::to_state);
bencher.bench(|| {
for state in black_box(states) {
Expand All @@ -22,7 22,7 @@ pub fn to_kind(bencher: Bencher) {
});
}
#[divan::bench]
pub fn get_prop(bencher: Bencher) {
pub(crate) fn get_prop(bencher: Bencher) {
let states = BlockKind::ALL.map(BlockKind::to_state);
bencher.bench(|| {
for state in black_box(states) {
Expand All @@ -31,7 31,7 @@ pub fn get_prop(bencher: Bencher) {
});
}
#[divan::bench]
pub fn set_prop(bencher: Bencher) {
pub(crate) fn set_prop(bencher: Bencher) {
let states = BlockKind::ALL.map(BlockKind::to_state);
bencher.bench(|| {
for state in black_box(states) {
Expand All @@ -40,7 40,7 @@ pub fn set_prop(bencher: Bencher) {
});
}
#[divan::bench]
pub fn is_liquid(bencher: Bencher) {
pub(crate) fn is_liquid(bencher: Bencher) {
let states = BlockKind::ALL.map(BlockKind::to_state);
bencher.bench(|| {
for state in black_box(states) {
Expand All @@ -49,7 49,7 @@ pub fn is_liquid(bencher: Bencher) {
});
}
#[divan::bench]
pub fn is_opaque(bencher: Bencher) {
pub(crate) fn is_opaque(bencher: Bencher) {
let states = BlockKind::ALL.map(BlockKind::to_state);
bencher.bench(|| {
for state in black_box(states) {
Expand All @@ -58,7 58,7 @@ pub fn is_opaque(bencher: Bencher) {
});
}
#[divan::bench]
pub fn is_replaceable(bencher: Bencher) {
pub(crate) fn is_replaceable(bencher: Bencher) {
let states = BlockKind::ALL.map(BlockKind::to_state);
bencher.bench(|| {
for state in black_box(states) {
Expand All @@ -67,7 67,7 @@ pub fn is_replaceable(bencher: Bencher) {
});
}
#[divan::bench]
pub fn luminance(bencher: Bencher) {
pub(crate) fn luminance(bencher: Bencher) {
let states = BlockKind::ALL.map(BlockKind::to_state);
bencher.bench(|| {
for state in black_box(states) {
Expand All @@ -76,15 76,15 @@ pub fn luminance(bencher: Bencher) {
});
}
#[divan::bench]
pub fn to_item_kind(bencher: Bencher) {
pub(crate) fn to_item_kind(bencher: Bencher) {
bencher.bench(|| {
for kind in black_box(BlockKind::ALL) {
black_box(kind.to_item_kind());
}
});
}
#[divan::bench]
pub fn from_item_kind(bencher: Bencher) {
pub(crate) fn from_item_kind(bencher: Bencher) {
bencher.bench(|| {
for kind in black_box(ItemKind::ALL) {
black_box(BlockKind::from_item_kind(kind));
Expand Down
4 changes: 2 additions & 2 deletions benches/decode_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 4,7 @@ use divan::Bencher;
use valence::protocol::{Decode, Encode};

#[divan::bench]
pub fn decode_small_array(bencher: Bencher) {
pub(crate) fn decode_small_array(bencher: Bencher) {
let floats = [123.0, 456.0, 789.0];
let mut buf = [0_u8; 24];

Expand All @@ -17,7 17,7 @@ pub fn decode_small_array(bencher: Bencher) {
}

#[divan::bench]
pub fn decode_large_array(bencher: Bencher) {
pub(crate) fn decode_large_array(bencher: Bencher) {
let bytes = [42; 4096];

bencher.bench(|| {
Expand Down
2 changes: 1 addition & 1 deletion benches/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 4,7 @@ use valence::prelude::*;
/// Benches the performance of a single server tick while nothing much is
/// happening.
#[divan::bench]
pub fn idle_update(bencher: Bencher) {
pub(crate) fn idle_update(bencher: Bencher) {
let mut app = App::new();

app.add_plugins(DefaultPlugins);
Expand Down
2 changes: 1 addition & 1 deletion benches/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 12,7 @@ use valence::text::IntoText;
use valence_server::protocol::Velocity;
use valence_server::CompressionThreshold;

pub fn setup<'a>() -> (
pub(crate) fn setup<'a>() -> (
PacketEncoder,
ChunkDataS2c<'a>,
PlayerListHeaderS2c<'a>,
Expand Down
147 changes: 75 additions & 72 deletions crates/valence_command/src/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,28 175,6 @@ impl<'a> ParseInput<'a> {
}
}

#[test]
fn test_parse_input() {
let mut input = ParseInput::new("The QuIck brown FOX jumps over the lazy dog");
assert_eq!(input.peek(), Some('T'));
assert_eq!(input.peek_n(0), "");
assert_eq!(input.peek_n(1), "T");
assert_eq!(input.peek_n(2), "Th");
assert_eq!(input.peek_n(3), "The");

assert_eq!(input.peek_word(), "The");
input.pop_word();
input.skip_whitespace();
assert_eq!(input.peek_word(), "QuIck");

assert!(input.match_next("quick"));
input.pop();
assert_eq!(input.peek_word(), "brown");

assert!(input.match_next("brown fox"));
assert_eq!(input.pop_all(), Some(" jumps over the lazy dog"));
}

#[derive(Debug, Error)]
pub enum CommandArgParseError {
// these should be player facing and not disclose internal information
Expand Down Expand Up @@ -249,58 227,83 @@ where
}
}

#[test]
fn test_absolute_or_relative() {
let mut input = ParseInput::new("~");
assert_eq!(
AbsoluteOrRelative::<i32>::parse_arg(&mut input).unwrap(),
AbsoluteOrRelative::Relative(0)
);
assert!(input.is_done());

let mut input = ParseInput::new("~1");
assert_eq!(
AbsoluteOrRelative::<i32>::parse_arg(&mut input).unwrap(),
AbsoluteOrRelative::Relative(1)
);
assert!(input.is_done());

let mut input = ParseInput::new("~1.5");
assert_eq!(
AbsoluteOrRelative::<f32>::parse_arg(&mut input).unwrap(),
AbsoluteOrRelative::Relative(1.5)
);
assert!(input.is_done());

let mut input = ParseInput::new("1");
assert_eq!(
AbsoluteOrRelative::<i32>::parse_arg(&mut input).unwrap(),
AbsoluteOrRelative::Absolute(1)
);
assert!(input.is_done());

let mut input = ParseInput::new("1.5 ");
assert_eq!(
AbsoluteOrRelative::<f32>::parse_arg(&mut input).unwrap(),
AbsoluteOrRelative::Absolute(1.5)
);
assert!(!input.is_done());

let mut input = ParseInput::new("1.5 2");
assert_eq!(
AbsoluteOrRelative::<f32>::parse_arg(&mut input).unwrap(),
AbsoluteOrRelative::Absolute(1.5)
);
assert!(!input.is_done());
assert_eq!(
AbsoluteOrRelative::<f32>::parse_arg(&mut input).unwrap(),
AbsoluteOrRelative::Absolute(2.0)
);
assert!(input.is_done());
}

impl<T: Default> Default for AbsoluteOrRelative<T> {
fn default() -> Self {
AbsoluteOrRelative::Absolute(T::default())
}
}

#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_parse_input() {
let mut input = ParseInput::new("The QuIck brown FOX jumps over the lazy dog");
assert_eq!(input.peek(), Some('T'));
assert_eq!(input.peek_n(0), "");
assert_eq!(input.peek_n(1), "T");
assert_eq!(input.peek_n(2), "Th");
assert_eq!(input.peek_n(3), "The");

assert_eq!(input.peek_word(), "The");
input.pop_word();
input.skip_whitespace();
assert_eq!(input.peek_word(), "QuIck");

assert!(input.match_next("quick"));
input.pop();
assert_eq!(input.peek_word(), "brown");

assert!(input.match_next("brown fox"));
assert_eq!(input.pop_all(), Some(" jumps over the lazy dog"));
}
#[test]
fn test_absolute_or_relative() {
let mut input = ParseInput::new("~");
assert_eq!(
AbsoluteOrRelative::<i32>::parse_arg(&mut input).unwrap(),
AbsoluteOrRelative::Relative(0)
);
assert!(input.is_done());

let mut input = ParseInput::new("~1");
assert_eq!(
AbsoluteOrRelative::<i32>::parse_arg(&mut input).unwrap(),
AbsoluteOrRelative::Relative(1)
);
assert!(input.is_done());

let mut input = ParseInput::new("~1.5");
assert_eq!(
AbsoluteOrRelative::<f32>::parse_arg(&mut input).unwrap(),
AbsoluteOrRelative::Relative(1.5)
);
assert!(input.is_done());

let mut input = ParseInput::new("1");
assert_eq!(
AbsoluteOrRelative::<i32>::parse_arg(&mut input).unwrap(),
AbsoluteOrRelative::Absolute(1)
);
assert!(input.is_done());

let mut input = ParseInput::new("1.5 ");
assert_eq!(
AbsoluteOrRelative::<f32>::parse_arg(&mut input).unwrap(),
AbsoluteOrRelative::Absolute(1.5)
);
assert!(!input.is_done());

let mut input = ParseInput::new("1.5 2");
assert_eq!(
AbsoluteOrRelative::<f32>::parse_arg(&mut input).unwrap(),
AbsoluteOrRelative::Absolute(1.5)
);
assert!(!input.is_done());
assert_eq!(
AbsoluteOrRelative::<f32>::parse_arg(&mut input).unwrap(),
AbsoluteOrRelative::Absolute(2.0)
);
assert!(input.is_done());
}
}
73 changes: 39 additions & 34 deletions crates/valence_command/src/parsers/block_pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 25,43 @@ impl CommandArg for BlockPos {
}
}

#[test]
fn test_block_pos() {
let mut input = ParseInput::new("~-1 2 3");
assert_eq!(
BlockPos::parse_arg(&mut input).unwrap(),
BlockPos {
x: AbsoluteOrRelative::Relative(-1),
y: AbsoluteOrRelative::Absolute(2),
z: AbsoluteOrRelative::Absolute(3)
}
);
assert!(input.is_done());

let mut input = ParseInput::new("-1 ~2 3 ");
assert_eq!(
BlockPos::parse_arg(&mut input).unwrap(),
BlockPos {
x: AbsoluteOrRelative::Absolute(-1),
y: AbsoluteOrRelative::Relative(2),
z: AbsoluteOrRelative::Absolute(3)
}
);
assert!(!input.is_done());

let mut input = ParseInput::new("-1 2 ~3 4");
assert_eq!(
BlockPos::parse_arg(&mut input).unwrap(),
BlockPos {
x: AbsoluteOrRelative::Absolute(-1),
y: AbsoluteOrRelative::Absolute(2),
z: AbsoluteOrRelative::Relative(3)
}
);
assert!(!input.is_done());
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_block_pos() {
let mut input = ParseInput::new("~-1 2 3");
assert_eq!(
BlockPos::parse_arg(&mut input).unwrap(),
BlockPos {
x: AbsoluteOrRelative::Relative(-1),
y: AbsoluteOrRelative::Absolute(2),
z: AbsoluteOrRelative::Absolute(3)
}
);
assert!(input.is_done());

let mut input = ParseInput::new("-1 ~2 3 ");
assert_eq!(
BlockPos::parse_arg(&mut input).unwrap(),
BlockPos {
x: AbsoluteOrRelative::Absolute(-1),
y: AbsoluteOrRelative::Relative(2),
z: AbsoluteOrRelative::Absolute(3)
}
);
assert!(!input.is_done());

let mut input = ParseInput::new("-1 2 ~3 4");
assert_eq!(
BlockPos::parse_arg(&mut input).unwrap(),
BlockPos {
x: AbsoluteOrRelative::Absolute(-1),
y: AbsoluteOrRelative::Absolute(2),
z: AbsoluteOrRelative::Relative(3)
}
);
assert!(!input.is_done());
}
}
Loading

0 comments on commit 646a76e

Please sign in to comment.