port writer and tests, but does not pass

This commit is contained in:
Henry Schimke
2022-11-27 12:00:35 -06:00
parent 6ccac83027
commit 07769fe154
8 changed files with 471 additions and 330 deletions

View File

@@ -305,10 +305,7 @@ fn testEncodeShiftjisNumeric() {
fn testEncodeGS1WithStringTypeHint() {
let mut hints = HashMap::new();
hints.insert(
EncodeHintType::GS1_FORMAT,
EncodeHintValue::Gs1Format("true".to_owned()),
);
hints.insert(EncodeHintType::GS1_FORMAT, EncodeHintValue::Gs1Format(true));
let qrCode = encoder::encode_with_hints("100001%11171218", ErrorCorrectionLevel::H, &hints)
.expect("encode");
verifyGS1EncodedData(&qrCode);
@@ -318,10 +315,7 @@ fn testEncodeGS1WithStringTypeHint() {
fn testEncodeGS1WithBooleanTypeHint() {
let mut hints = HashMap::new();
hints.insert(
EncodeHintType::GS1_FORMAT,
EncodeHintValue::Gs1Format("true".to_owned()),
);
hints.insert(EncodeHintType::GS1_FORMAT, EncodeHintValue::Gs1Format(true));
let qrCode = encoder::encode_with_hints("100001%11171218", ErrorCorrectionLevel::H, &hints)
.expect("encode");
verifyGS1EncodedData(&qrCode);
@@ -333,7 +327,7 @@ fn testDoesNotEncodeGS1WhenBooleanTypeHintExplicitlyFalse() {
hints.insert(
EncodeHintType::GS1_FORMAT,
EncodeHintValue::Gs1Format("false".to_owned()),
EncodeHintValue::Gs1Format(false),
);
let qrCode =
@@ -347,7 +341,7 @@ fn testDoesNotEncodeGS1WhenStringTypeHintExplicitlyFalse() {
hints.insert(
EncodeHintType::GS1_FORMAT,
EncodeHintValue::Gs1Format("false".to_owned()),
EncodeHintValue::Gs1Format(false),
);
let qrCode =
encoder::encode_with_hints("ABCDEF", ErrorCorrectionLevel::H, &hints).expect("encode");
@@ -362,10 +356,7 @@ fn testGS1ModeHeaderWithECI() {
EncodeHintType::CHARACTER_SET,
EncodeHintValue::CharacterSet("utf8".to_owned()),
);
hints.insert(
EncodeHintType::GS1_FORMAT,
EncodeHintValue::Gs1Format("true".to_owned()),
);
hints.insert(EncodeHintType::GS1_FORMAT, EncodeHintValue::Gs1Format(true));
let qrCode =
encoder::encode_with_hints("hello", ErrorCorrectionLevel::H, &hints).expect("encode");
let expected = r"<<

View File

@@ -104,11 +104,7 @@ pub fn encode_with_hints(
let has_gs1_format_hint = hints.contains_key(&EncodeHintType::GS1_FORMAT)
&& if let EncodeHintValue::Gs1Format(v) = hints.get(&EncodeHintType::GS1_FORMAT).unwrap() {
if let Ok(vb) = v.parse::<bool>() {
vb
} else {
false
}
*v
} else {
false
};