From 41d547f3ed0497fe0125f98a163494921df38396 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Thu, 9 May 2024 15:44:32 -0500 Subject: [PATCH] Relocate the Decoder constructor hacks The special constructors can be put in an impl block in the test module instead of hanging out as dead code in the main library chunk. --- src/main.rs | 77 +++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/src/main.rs b/src/main.rs index f4f7872..9b241ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,44 +54,6 @@ where run_len: 0, } } - - // A hack to unit test the index lookup behavior. A partial test can be done - // to verify the basic indexing principles by preloading a known buffer and - // then extracting back-referenced data out of it. A complete test should - // feed in other valid operations that populate the backbuffer, and then index - // op codes to demonstrate the indexing operations. - fn new_with_backbuffer(bytes: I, back_buffer: [PixelRGBA; 64]) -> Self { - Self { - back_buffer, - prev_pixel: PixelRGBA { - r: 0, - g: 0, - b: 0, - a: 255, - }, - bytes, - run_len: 0, - } - } - - // A hack to unit test the run behavior. Same idea as the new_with_backbuffer() - // function, but for testing a run of pixels. - fn new_with_previous_pixel(bytes: I, prev_pixel: PixelRGBA) -> Self { - Self { - back_buffer: [PixelRGBA::zero(); 64], - prev_pixel, - bytes, - run_len: 0, - } - } - - pub(crate) fn peek_prev_pixel(&self) -> &PixelRGBA { - &self.prev_pixel - } - - pub(crate) fn peek_backbuffer(&self, idx: usize) -> &PixelRGBA { - &self.back_buffer[idx] - } } mod codec_utils { @@ -198,6 +160,45 @@ where #[cfg(test)] mod test { use super::*; + impl Decoder where I: Iterator { + // A hack to unit test the index lookup behavior. A partial test can be done + // to verify the basic indexing principles by preloading a known buffer and + // then extracting back-referenced data out of it. A complete test should + // feed in other valid operations that populate the backbuffer, and then index + // op codes to demonstrate the indexing operations. + fn new_with_backbuffer(bytes: I, back_buffer: [PixelRGBA; 64]) -> Self { + Self { + back_buffer, + prev_pixel: PixelRGBA { + r: 0, + g: 0, + b: 0, + a: 255, + }, + bytes, + run_len: 0, + } + } + + // A hack to unit test the run behavior. Same idea as the new_with_backbuffer() + // function, but for testing a run of pixels. + fn new_with_previous_pixel(bytes: I, prev_pixel: PixelRGBA) -> Self { + Self { + back_buffer: [PixelRGBA::zero(); 64], + prev_pixel, + bytes, + run_len: 0, + } + } + + fn peek_prev_pixel(&self) -> &PixelRGBA { + &self.prev_pixel + } + + fn peek_backbuffer(&self, idx: usize) -> &PixelRGBA { + &self.back_buffer[idx] + } + } #[test] // this is mostly just to drive the function. Make sure it wraps or crashes in debug. fn test_backref_hash_function() {