From fde23934f6c51dc40708a80ef3aa589a2ab5eee2 Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Wed, 11 Jan 2023 16:02:26 -0600 Subject: [PATCH] rename bitmatrix test cases mod --- src/barcode_format.rs | 7 ++++++- src/common/bit_matrix.rs | 16 ++++++++++++++++ ...trixTestCase.rs => bit_matrix_test_case.rs} | 2 -- src/common/mod.rs | 2 +- src/oned/coda_bar_writer.rs | 4 ++-- src/oned/code_128_writer_test_tase.rs | 18 +++++++++--------- src/oned/code_39_writer.rs | 4 ++-- src/oned/code_93_writer.rs | 4 ++-- src/oned/ean_13_writer.rs | 6 +++--- src/oned/ean_8_writer.rs | 6 +++--- src/oned/itf_writer.rs | 4 ++-- src/oned/upc_a_writer.rs | 6 +++--- src/oned/upc_e_writer.rs | 4 ++-- 13 files changed, 51 insertions(+), 32 deletions(-) rename src/common/{BitMatrixTestCase.rs => bit_matrix_test_case.rs} (99%) diff --git a/src/barcode_format.rs b/src/barcode_format.rs index 7c8d65c..50b05e0 100644 --- a/src/barcode_format.rs +++ b/src/barcode_format.rs @@ -109,7 +109,12 @@ impl Display for BarcodeFormat { } } -/// Defaults to QRCode if no proper formatting available +impl From for BarcodeFormat { + fn from(value: String) -> Self { + value.as_str().into() + } +} + impl From<&str> for BarcodeFormat { fn from(value: &str) -> Self { match value.to_lowercase().as_str() { diff --git a/src/common/bit_matrix.rs b/src/common/bit_matrix.rs index 16012eb..dcfe994 100644 --- a/src/common/bit_matrix.rs +++ b/src/common/bit_matrix.rs @@ -690,3 +690,19 @@ impl From<&BitMatrix> for image::DynamicImage { pixels.into() } } + +// impl From for Vec { +// fn from(value: BitMatrix) -> Self { +// let mut output_vector = Vec::new(); +// for y in 0..value.getHeight() { +// for col in (0..value.getWidth()).step_by(8) { +// let mut byte = 0_u8; +// for x in 0..8 { +// byte |= u8::from(value.get(col+x, y)) << x +// } +// output_vector.push(byte); +// } +// } +// output_vector +// } +// } diff --git a/src/common/BitMatrixTestCase.rs b/src/common/bit_matrix_test_case.rs similarity index 99% rename from src/common/BitMatrixTestCase.rs rename to src/common/bit_matrix_test_case.rs index b60d8b2..fa15672 100644 --- a/src/common/BitMatrixTestCase.rs +++ b/src/common/bit_matrix_test_case.rs @@ -396,5 +396,3 @@ fn get_input(width: u32, height: u32) -> BitMatrix { } result } - -// } diff --git a/src/common/mod.rs b/src/common/mod.rs index 2ea7bb2..634e1ab 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -10,7 +10,7 @@ mod StringUtilsTestCase; mod BitArrayTestCase; #[cfg(test)] -pub(crate) mod BitMatrixTestCase; +pub(crate) mod bit_matrix_test_case; #[cfg(test)] mod BitSourceTestCase; diff --git a/src/oned/coda_bar_writer.rs b/src/oned/coda_bar_writer.rs index 7a01174..1c08cf7 100644 --- a/src/oned/coda_bar_writer.rs +++ b/src/oned/coda_bar_writer.rs @@ -162,7 +162,7 @@ impl OneDimensionalCodeWriter for CodaBarWriter { #[cfg(test)] mod CodaBarWriterTestCase { use crate::{ - common::{BitMatrix, BitMatrixTestCase}, + common::{bit_matrix_test_case, BitMatrix}, BarcodeFormat, Writer, }; @@ -210,7 +210,7 @@ mod CodaBarWriterTestCase { fn doTest(input: &str, expected: &str) { let result = encode(input); - assert_eq!(expected, BitMatrixTestCase::matrix_to_string(&result)); + assert_eq!(expected, bit_matrix_test_case::matrix_to_string(&result)); } fn encode(input: &str) -> BitMatrix { diff --git a/src/oned/code_128_writer_test_tase.rs b/src/oned/code_128_writer_test_tase.rs index c1619bf..71f868f 100644 --- a/src/oned/code_128_writer_test_tase.rs +++ b/src/oned/code_128_writer_test_tase.rs @@ -37,7 +37,7 @@ use std::collections::HashMap; use once_cell::sync::Lazy; use crate::{ - common::{BitMatrix, BitMatrixTestCase}, + common::{bit_matrix_test_case, BitMatrix}, oned::{Code128Reader, OneDReader}, BarcodeFormat, EncodeHintType, EncodeHintValue, EncodingHintDictionary, Exceptions, Writer, }; @@ -65,7 +65,7 @@ fn testEncodeWithFunc3() { let result = encode(toEncode, false, "123").expect("encode"); - let actual = BitMatrixTestCase::matrix_to_string(&result); + let actual = bit_matrix_test_case::matrix_to_string(&result); assert_eq!(expected, actual); let width = result.getWidth(); @@ -93,7 +93,7 @@ fn testEncodeWithFunc2() { let result = encode(toEncode, false, "123").expect("encode"); - let actual = BitMatrixTestCase::matrix_to_string(&result); + let actual = bit_matrix_test_case::matrix_to_string(&result); assert_eq!(expected, actual); let width = result.getWidth(); @@ -121,7 +121,7 @@ fn testEncodeWithFunc1() { let result = encode(toEncode, false, "123").expect("encode"); - let actual = BitMatrixTestCase::matrix_to_string(&result); + let actual = bit_matrix_test_case::matrix_to_string(&result); assert_eq!(expected, actual); let width = result.getWidth(); @@ -222,7 +222,7 @@ fn testEncodeWithFunc4() { let result = encode(toEncode, false, "").expect("encode"); - let actual = BitMatrixTestCase::matrix_to_string(&result); + let actual = bit_matrix_test_case::matrix_to_string(&result); assert_eq!(expected, actual); let width = result.getWidth(); @@ -250,7 +250,7 @@ fn testEncodeWithFncsAndNumberInCodesetA() { let result = encode(toEncode, false, "").expect("encode"); - let actual = BitMatrixTestCase::matrix_to_string(&result); + let actual = bit_matrix_test_case::matrix_to_string(&result); assert_eq!(expected, actual); @@ -310,7 +310,7 @@ fn testEncodeSwitchBetweenCodesetsAAndB() { fn testEncode(toEncode: &str, expected: &str) { let result = encode(toEncode, false, toEncode).expect("encode"); - let actual = BitMatrixTestCase::matrix_to_string(&result); + let actual = bit_matrix_test_case::matrix_to_string(&result); assert_eq!(expected, actual, "{}", toEncode); let width = result.getWidth(); @@ -432,7 +432,7 @@ fn testEncodeWithForcedCodeSetFailureCodeSetA() { .encode_with_hints(toEncode, &BarcodeFormat::CODE_128, 0, 0, &hints) .expect("encode"); - let actual = BitMatrixTestCase::matrix_to_string(&result); + let actual = bit_matrix_test_case::matrix_to_string(&result); assert_eq!(expected, actual); } @@ -465,7 +465,7 @@ fn testEncodeWithForcedCodeSetFailureCodeSetB() { .encode_with_hints(toEncode, &BarcodeFormat::CODE_128, 0, 0, &hints) .expect("encode"); - let actual = BitMatrixTestCase::matrix_to_string(&result); + let actual = bit_matrix_test_case::matrix_to_string(&result); assert_eq!(expected, actual); } diff --git a/src/oned/code_39_writer.rs b/src/oned/code_39_writer.rs index 87e8a67..72b48be 100644 --- a/src/oned/code_39_writer.rs +++ b/src/oned/code_39_writer.rs @@ -174,7 +174,7 @@ impl Code39Writer { * Tests {@link Code39Writer}. */ mod Code39WriterTestCase { - use crate::{common::BitMatrixTestCase, oned::Code39Writer, BarcodeFormat, Writer}; + use crate::{common::bit_matrix_test_case, oned::Code39Writer, BarcodeFormat, Writer}; #[test] fn testEncode() { @@ -248,7 +248,7 @@ mod Code39WriterTestCase { .expect("must encode"); assert_eq!( expected, - BitMatrixTestCase::matrix_to_string(&result), + bit_matrix_test_case::matrix_to_string(&result), "{}", input ); diff --git a/src/oned/code_93_writer.rs b/src/oned/code_93_writer.rs index 46ed4af..d99ca56 100644 --- a/src/oned/code_93_writer.rs +++ b/src/oned/code_93_writer.rs @@ -212,7 +212,7 @@ impl Code93Writer { */ #[cfg(test)] mod Code93WriterTestCase { - use crate::{common::BitMatrixTestCase, oned::Code93Writer, BarcodeFormat, Writer}; + use crate::{common::bit_matrix_test_case, oned::Code93Writer, BarcodeFormat, Writer}; #[test] fn testEncode() { @@ -247,7 +247,7 @@ mod Code93WriterTestCase { let result = Code93Writer::default() .encode(input, &BarcodeFormat::CODE_93, 0, 0) .expect("encode"); - assert_eq!(expected, BitMatrixTestCase::matrix_to_string(&result)); + assert_eq!(expected, bit_matrix_test_case::matrix_to_string(&result)); } #[test] diff --git a/src/oned/ean_13_writer.rs b/src/oned/ean_13_writer.rs index 70943f4..01c8a49 100644 --- a/src/oned/ean_13_writer.rs +++ b/src/oned/ean_13_writer.rs @@ -135,7 +135,7 @@ const CODE_WIDTH: usize = 3 + // start guard */ #[cfg(test)] mod EAN13WriterTestCase { - use crate::{common::BitMatrixTestCase, BarcodeFormat, Writer}; + use crate::{common::bit_matrix_test_case, BarcodeFormat, Writer}; use super::EAN13Writer; @@ -151,7 +151,7 @@ mod EAN13WriterTestCase { 0, ) .expect("exist"); - assert_eq!(testStr, BitMatrixTestCase::matrix_to_string(&result)); + assert_eq!(testStr, bit_matrix_test_case::matrix_to_string(&result)); } #[test] @@ -166,7 +166,7 @@ mod EAN13WriterTestCase { 0, ) .expect("exist"); - assert_eq!(testStr, BitMatrixTestCase::matrix_to_string(&result)); + assert_eq!(testStr, bit_matrix_test_case::matrix_to_string(&result)); } #[test] diff --git a/src/oned/ean_8_writer.rs b/src/oned/ean_8_writer.rs index 70e1462..ff18a0a 100644 --- a/src/oned/ean_8_writer.rs +++ b/src/oned/ean_8_writer.rs @@ -120,7 +120,7 @@ impl OneDimensionalCodeWriter for EAN8Writer { */ #[cfg(test)] mod EAN8WriterTestCase { - use crate::{common::BitMatrixTestCase, BarcodeFormat, Writer}; + use crate::{common::bit_matrix_test_case, BarcodeFormat, Writer}; use super::EAN8Writer; @@ -136,7 +136,7 @@ mod EAN8WriterTestCase { 0, ) .expect("ok"); - assert_eq!(testStr, BitMatrixTestCase::matrix_to_string(&result)); + assert_eq!(testStr, bit_matrix_test_case::matrix_to_string(&result)); } #[test] @@ -151,7 +151,7 @@ mod EAN8WriterTestCase { 0, ) .expect("ok"); - assert_eq!(testStr, BitMatrixTestCase::matrix_to_string(&result)); + assert_eq!(testStr, bit_matrix_test_case::matrix_to_string(&result)); } #[test] diff --git a/src/oned/itf_writer.rs b/src/oned/itf_writer.rs index 5d131f7..bee2ec3 100644 --- a/src/oned/itf_writer.rs +++ b/src/oned/itf_writer.rs @@ -97,7 +97,7 @@ const PATTERNS: [[usize; 5]; 10] = [ */ #[cfg(test)] mod ITFWriterTestCase { - use crate::{common::BitMatrixTestCase, BarcodeFormat, Writer}; + use crate::{common::bit_matrix_test_case, BarcodeFormat, Writer}; use super::ITFWriter; @@ -114,7 +114,7 @@ mod ITFWriterTestCase { let result = ITFWriter::default() .encode(input, &BarcodeFormat::ITF, 0, 0) .expect("encode"); - assert_eq!(expected, BitMatrixTestCase::matrix_to_string(&result)); + assert_eq!(expected, bit_matrix_test_case::matrix_to_string(&result)); } //@Test(expected = IllegalArgumentException.class) diff --git a/src/oned/upc_a_writer.rs b/src/oned/upc_a_writer.rs index 0efa359..dd486d3 100644 --- a/src/oned/upc_a_writer.rs +++ b/src/oned/upc_a_writer.rs @@ -71,7 +71,7 @@ impl Writer for UPCAWriter { */ #[cfg(test)] mod UPCAWriterTestCase { - use crate::{common::BitMatrixTestCase, BarcodeFormat, Writer}; + use crate::{common::bit_matrix_test_case, BarcodeFormat, Writer}; use super::UPCAWriter; @@ -87,7 +87,7 @@ mod UPCAWriterTestCase { 0, ) .expect("ok"); - assert_eq!(testStr, BitMatrixTestCase::matrix_to_string(&result)); + assert_eq!(testStr, bit_matrix_test_case::matrix_to_string(&result)); } #[test] @@ -102,6 +102,6 @@ mod UPCAWriterTestCase { 0, ) .expect("ok"); - assert_eq!(testStr, BitMatrixTestCase::matrix_to_string(&result)); + assert_eq!(testStr, bit_matrix_test_case::matrix_to_string(&result)); } } diff --git a/src/oned/upc_e_writer.rs b/src/oned/upc_e_writer.rs index 0bb677f..671a0dd 100644 --- a/src/oned/upc_e_writer.rs +++ b/src/oned/upc_e_writer.rs @@ -123,7 +123,7 @@ impl OneDimensionalCodeWriter for UPCEWriter { */ #[cfg(test)] mod UPCEWriterTestCase { - use crate::{common::BitMatrixTestCase, BarcodeFormat, Writer}; + use crate::{common::bit_matrix_test_case, BarcodeFormat, Writer}; use super::UPCEWriter; @@ -160,7 +160,7 @@ mod UPCEWriterTestCase { 0, ) .expect("ok"); - assert_eq!(encoding, BitMatrixTestCase::matrix_to_string(&result)); + assert_eq!(encoding, bit_matrix_test_case::matrix_to_string(&result)); } #[test]