Clean up test and bench macro syntax

This commit is contained in:
David Tolnay 2021-12-11 21:03:51 -08:00
parent 6b06fb04f7
commit 42cb96a975
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 21 additions and 20 deletions

View File

@ -5,9 +5,10 @@
extern crate test;
macro_rules! benches {
($($name:ident($value:expr)),*) => {
($($name:ident($value:expr))*) => {
mod bench_itoa_format {
use test::{Bencher, black_box};
$(
#[bench]
fn $name(b: &mut Bencher) {
@ -22,12 +23,12 @@ macro_rules! benches {
}
mod bench_std_fmt {
use std::io::Write;
use test::{Bencher, black_box};
$(
#[bench]
fn $name(b: &mut Bencher) {
use std::io::Write;
let mut buf = Vec::with_capacity(40);
b.iter(|| {
@ -42,13 +43,13 @@ macro_rules! benches {
}
benches! {
bench_u64_0(0u64),
bench_u64_half(<u32>::max_value() as u64),
bench_u64_max(<u64>::max_value()),
bench_u64_0(0u64)
bench_u64_half(u32::max_value() as u64)
bench_u64_max(u64::max_value())
bench_i16_0(0i16),
bench_i16_min(<i16>::min_value()),
bench_i16_0(0i16)
bench_i16_min(i16::min_value())
bench_u128_0(0u128),
bench_u128_max(<u128>::max_value())
bench_u128_0(0u128)
bench_u128_max(u128::max_value())
}

View File

@ -2,7 +2,7 @@
#![allow(clippy::cast_lossless, clippy::unseparated_literal_suffix)]
macro_rules! test {
($($name:ident($value:expr, $expected:expr)),*) => {
($($name:ident($value:expr, $expected:expr))*) => {
$(
#[test]
fn $name() {
@ -15,15 +15,15 @@ macro_rules! test {
}
test! {
test_u64_0(0u64, "0"),
test_u64_half(<u32>::max_value() as u64, "4294967295"),
test_u64_max(<u64>::max_value(), "18446744073709551615"),
test_i64_min(<i64>::min_value(), "-9223372036854775808"),
test_u64_0(0u64, "0")
test_u64_half(u32::max_value() as u64, "4294967295")
test_u64_max(u64::max_value(), "18446744073709551615")
test_i64_min(i64::min_value(), "-9223372036854775808")
test_i16_0(0i16, "0"),
test_i16_min(<i16>::min_value(), "-32768"),
test_i16_0(0i16, "0")
test_i16_min(i16::min_value(), "-32768")
test_u128_0(0u128, "0"),
test_u128_max(<u128>::max_value(), "340282366920938463463374607431768211455"),
test_i128_min(<i128>::min_value(), "-170141183460469231731687303715884105728")
test_u128_0(0u128, "0")
test_u128_max(u128::max_value(), "340282366920938463463374607431768211455")
test_i128_min(i128::min_value(), "-170141183460469231731687303715884105728")
}