Skip to content

Commit

Permalink
fix clippy and doc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed Nov 26, 2024
1 parent 5749cab commit 8ac3c65
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 49 deletions.
58 changes: 29 additions & 29 deletions benches/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,35 +109,35 @@ fn write_tests(tests: &[Testrun], num_days: usize, timestamp: u32) -> Vec<u8> {
buf
}

struct Upload {
flags: Vec<String>,
tests: Vec<Testrun>,
}

/// Generates a random set of `num_flags` flags.
fn create_random_flags(rng: &mut impl Rng, num_flags: usize) -> Vec<String> {
let flag_lens = Uniform::from(5usize..10);
(0..num_flags)
.map(|_| {
let flag_len = flag_lens.sample(rng);
Alphanumeric.sample_string(rng, flag_len)
})
.collect()
}

/// Samples random combinations of flags with length `max_flags_in_set`.
fn sample_flag_sets<'a>(
rng: &'a mut impl Rng,
flags: &'a [String],
max_flags_in_set: usize,
) -> impl Iterator<Item = Vec<String>> + 'a {
let num_flags = Uniform::from(0..max_flags_in_set);
std::iter::from_fn(move || {
let num_flags = num_flags.sample(rng);
let flags: Vec<_> = flags.choose_multiple(rng, num_flags).cloned().collect();
Some(flags)
})
}
// struct Upload {
// flags: Vec<String>,
// tests: Vec<Testrun>,
// }

// /// Generates a random set of `num_flags` flags.
// fn create_random_flags(rng: &mut impl Rng, num_flags: usize) -> Vec<String> {
// let flag_lens = Uniform::from(5usize..10);
// (0..num_flags)
// .map(|_| {
// let flag_len = flag_lens.sample(rng);
// Alphanumeric.sample_string(rng, flag_len)
// })
// .collect()
// }

// /// Samples random combinations of flags with length `max_flags_in_set`.
// fn sample_flag_sets<'a>(
// rng: &'a mut impl Rng,
// flags: &'a [String],
// max_flags_in_set: usize,
// ) -> impl Iterator<Item = Vec<String>> + 'a {
// let num_flags = Uniform::from(0..max_flags_in_set);
// std::iter::from_fn(move || {
// let num_flags = num_flags.sample(rng);
// let flags: Vec<_> = flags.choose_multiple(rng, num_flags).cloned().collect();
// Some(flags)
// })
// }

fn create_random_testcases(rng: &mut impl Rng, num_tests: usize) -> Vec<Testrun> {
let name_lens = Uniform::from(5usize..50);
Expand Down
2 changes: 1 addition & 1 deletion src/binary/flagsset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<'table> FlagsSet<'table> {
Ok(flags)
}

pub fn into_owned(&self) -> FlagsSet<'static> {
pub fn to_owned(&self) -> FlagsSet<'static> {
FlagsSet {
map: self.map.clone(),
table: self.table.clone().into_owned().into(),
Expand Down
4 changes: 2 additions & 2 deletions src/binary/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<'data> TestAnalytics<'data> {
}
}

impl<'data> fmt::Debug for TestAnalytics<'data> {
impl fmt::Debug for TestAnalytics<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("TestAnalytics")
.field("version", &self.header.version)
Expand All @@ -113,7 +113,7 @@ pub struct Test<'data, 'parsed> {
data_range: Range<usize>,
}

impl<'data, 'parsed> Test<'data, 'parsed> {
impl<'data> Test<'data, '_> {
/// Returns the testsuite of the test.
pub fn testsuite(&self) -> Result<&'data str, TestAnalyticsError> {
watto::StringTable::read(
Expand Down
28 changes: 14 additions & 14 deletions src/binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod timestamps;
mod writer;

pub use error::{TestAnalyticsError, TestAnalyticsErrorKind};
pub use format::TestAnalytics;
pub use format::{Test, TestAnalytics};
pub use writer::TestAnalyticsWriter;

#[cfg(test)]
Expand Down Expand Up @@ -151,7 +151,7 @@ mod tests {
assert!(tests.next().is_none());

// next, we re-parse one day ahead
let parsed = TestAnalytics::parse(&buf, 1 * DAY).unwrap();
let parsed = TestAnalytics::parse(&buf, DAY).unwrap();
let mut tests = parsed.tests();

let abc = tests.next().unwrap();
Expand Down Expand Up @@ -191,16 +191,16 @@ mod tests {
let mut buf = vec![];
writer.serialize(&mut buf).unwrap();

let parsed = TestAnalytics::parse(&buf, 1 * DAY).unwrap();
let parsed = TestAnalytics::parse(&buf, DAY).unwrap();
let mut writer = TestAnalyticsWriter::from_existing_format(&parsed).unwrap();
let mut session = writer.start_session(1 * DAY, &[]);
let mut session = writer.start_session(DAY, &[]);

session.insert(&test);

let mut buf = vec![];
writer.serialize(&mut buf).unwrap();

let parsed = TestAnalytics::parse(&buf, 1 * DAY).unwrap();
let parsed = TestAnalytics::parse(&buf, DAY).unwrap();
let mut tests = parsed.tests();

let abc = tests.next().unwrap();
Expand Down Expand Up @@ -240,13 +240,13 @@ mod tests {
writer.serialize(&mut buf_1).unwrap();

let mut writer = TestAnalyticsWriter::new(2);
let mut session = writer.start_session(1 * DAY, &[]);
let mut session = writer.start_session(DAY, &[]);
session.insert(&test);
let mut buf_2 = vec![];
writer.serialize(&mut buf_2).unwrap();

let parsed_1 = TestAnalytics::parse(&buf_1, 1 * DAY).unwrap();
let parsed_2 = TestAnalytics::parse(&buf_2, 1 * DAY).unwrap();
let parsed_1 = TestAnalytics::parse(&buf_1, DAY).unwrap();
let parsed_2 = TestAnalytics::parse(&buf_2, DAY).unwrap();

let merged_12 = TestAnalyticsWriter::merge(&parsed_1, &parsed_2).unwrap();
let merged_21 = TestAnalyticsWriter::merge(&parsed_2, &parsed_1).unwrap();
Expand All @@ -258,7 +258,7 @@ mod tests {

assert_eq!(buf_12, buf_21);

let parsed = TestAnalytics::parse(&buf_12, 1 * DAY).unwrap();
let parsed = TestAnalytics::parse(&buf_12, DAY).unwrap();
let mut tests = parsed.tests();

let abc = tests.next().unwrap();
Expand Down Expand Up @@ -299,19 +299,19 @@ mod tests {
let mut buf = vec![];
writer.serialize(&mut buf).unwrap();

let parsed = TestAnalytics::parse(&buf, 1 * DAY).unwrap();
let parsed = TestAnalytics::parse(&buf, DAY).unwrap();
let mut writer = TestAnalyticsWriter::from_existing_format(&parsed).unwrap();

let was_rewritten = writer.rewrite(2, 1 * DAY, Some(0)).unwrap();
let was_rewritten = writer.rewrite(2, DAY, Some(0)).unwrap();
assert!(!was_rewritten);

let was_rewritten = writer.rewrite(7, 1 * DAY, Some(0)).unwrap();
let was_rewritten = writer.rewrite(7, DAY, Some(0)).unwrap();
assert!(was_rewritten);

let mut buf = vec![];
writer.serialize(&mut buf).unwrap();

let parsed = TestAnalytics::parse(&buf, 1 * DAY).unwrap();
let parsed = TestAnalytics::parse(&buf, DAY).unwrap();
let mut tests = parsed.tests();

// nothing garbage collected yet
Expand Down Expand Up @@ -364,7 +364,7 @@ mod tests {
let mut buf = vec![];
writer.serialize(&mut buf).unwrap();

let parsed = TestAnalytics::parse(&buf, 1 * DAY).unwrap();
let parsed = TestAnalytics::parse(&buf, DAY).unwrap();
let mut tests = parsed.tests();

// we get the test twice, with two different flags
Expand Down
2 changes: 1 addition & 1 deletion src/binary/timestamps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ mod tests {

#[test]
fn test_day_offsets() {
let offset = offset_from_today(0, 1 * DAY);
let offset = offset_from_today(0, DAY);
assert_eq!(offset, 1);

let offset = offset_from_today(0, 7 * DAY);
Expand Down
4 changes: 2 additions & 2 deletions src/binary/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct InsertSession<'writer> {
flag_set_offset: u32,
}

impl<'writer> InsertSession<'writer> {
impl InsertSession<'_> {
/// Writes the data for the given [`Testrun`](testrun::Testrun) into the
/// underlying [`TestAnalyticsWriter`].
pub fn insert(&mut self, test: &testrun::Testrun) {
Expand Down Expand Up @@ -106,7 +106,7 @@ impl TestAnalyticsWriter {

let string_table = StringTable::from_bytes(data.string_bytes)
.map_err(|_| TestAnalyticsErrorKind::InvalidStringReference)?;
let flags_set = data.flags_set.into_owned();
let flags_set = data.flags_set.to_owned();

Ok(Self {
num_days: data.header.num_days as usize,
Expand Down

0 comments on commit 8ac3c65

Please sign in to comment.