minimal encoder tests pass

This commit is contained in:
Henry Schimke
2022-10-04 19:29:03 -05:00
parent 86f6bd0c69
commit 0435e0fb7c
4 changed files with 31 additions and 23 deletions

View File

@@ -1100,9 +1100,10 @@ fn testMinimalEncoder41() {
#[test]
fn testMinimalEncoder42() {
// test halfwidth Katakana character (they are single byte encoded in Shift_JIS)
// NOTE: Changed to windows-31j because that is what is supported in encoding crate
verifyMinimalEncoding(
"Katakana:\u{FF66}\u{FF66}\u{FF66}\u{FF66}\u{FF66}\u{FF66}",
"ECI(Shift_JIS),BYTE(Katakana:......)",
"ECI(windows-31j),BYTE(Katakana:......)",
None,
false,
);
@@ -1124,9 +1125,10 @@ fn testMinimalEncoder44() {
// The character \u30A2 encodes as double byte in Shift_JIS but KANJI is not more compact in this case because
// KANJI is only more compact when it encodes pairs of characters. In the case of mixed text it can however be
// that Shift_JIS encoding is more compact as in this example
// NOTE: Changed to windows-31j because that is what is supported in encoding crate
verifyMinimalEncoding(
"Katakana:\u{30A2}a\u{30A2}a\u{30A2}a\u{30A2}a\u{30A2}a\u{30A2}",
"ECI(Shift_JIS),BYTE(Katakana:.a.a.a.a.a.)",
"ECI(windows-31j),BYTE(Katakana:.a.a.a.a.a.)",
None,
false,
);
@@ -1141,7 +1143,7 @@ fn verifyMinimalEncoding(
let result = MinimalEncoder::encode_with_details(
input,
None,
priorityCharset.unwrap_or(encoding::all::ISO_8859_1),
priorityCharset,
isGS1,
ErrorCorrectionLevel::L,
)

View File

@@ -136,11 +136,12 @@ pub fn encode_with_hints(
if hasCompactionHint {
mode = Mode::BYTE;
dbg!("consider this a huge risk, not sure if it should be defaulting to default");
let priorityEncoding = encoding; //if encoding.name() == DEFAULT_BYTE_MODE_ENCODING.name() {None} else {Some(encoding)};
let rn = MinimalEncoder::encode_with_details(
content,
None,
priorityEncoding,
Some(priorityEncoding),
hasGS1FormatHint,
ecLevel,
)?;

View File

@@ -107,7 +107,7 @@ impl MinimalEncoder {
*/
pub fn new(
stringToEncode: &str,
priorityCharset: EncodingRef,
priorityCharset: Option<EncodingRef>,
isGS1: bool,
ecLevel: ErrorCorrectionLevel,
) -> Self {
@@ -144,7 +144,7 @@ impl MinimalEncoder {
pub fn encode_with_details(
stringToEncode: &str,
version: Option<VersionRef>,
priorityCharset: EncodingRef,
priorityCharset: Option<EncodingRef>,
isGS1: bool,
ecLevel: ErrorCorrectionLevel,
) -> Result<RXingResultList, Exceptions> {
@@ -319,15 +319,15 @@ impl MinimalEncoder {
let mut start = 0;
let mut end = self.encoders.len();
let priorityEncoderIndex = self.encoders.getPriorityEncoderIndex();
if priorityEncoderIndex >= 0
if priorityEncoderIndex.is_some()
&& self.encoders.canEncode(
// self.stringToEncode.chars().nth(from as usize).unwrap() as i16,
&self.stringToEncode[from as usize],
priorityEncoderIndex,
priorityEncoderIndex.unwrap(),
)
{
start = priorityEncoderIndex;
end = priorityEncoderIndex + 1;
start = priorityEncoderIndex.unwrap();
end = priorityEncoderIndex.unwrap() + 1;
}
for i in start..end {