cleaned up many warnings

This commit is contained in:
Henry Schimke
2022-10-17 10:50:18 -05:00
parent 8c102cab8f
commit 111fe47566
71 changed files with 2553 additions and 2528 deletions

View File

@@ -23,10 +23,10 @@ use crate::common::BitArray;
fn getUnsignedInt(v: &BitArray) -> u64 {
let mut result = 0u64;
const offset: usize = 0;
const OFFSET: usize = 0;
for i in 0..32 {
// for (int i = 0, offset = 0; i < 32; i++) {
if v.get(offset + i) {
if v.get(OFFSET + i) {
result |= 1 << (31 - i);
}
}
@@ -82,15 +82,15 @@ fn testAppendBit() {
#[test]
fn testAppendBits() {
let mut v = BitArray::new();
v.appendBits(0x1, 1);
v.appendBits(0x1, 1).expect("append");
assert_eq!(1, v.getSize());
assert_eq!(0x80000000, getUnsignedInt(&v));
let mut v = BitArray::new();
v.appendBits(0xff, 8);
v.appendBits(0xff, 8).expect("append");
assert_eq!(8, v.getSize());
assert_eq!(0xff000000, getUnsignedInt(&v));
let mut v = BitArray::new();
v.appendBits(0xff7, 12);
v.appendBits(0xff7, 12).expect("append");
assert_eq!(12, v.getSize());
assert_eq!(0xff700000, getUnsignedInt(&v));
}
@@ -102,11 +102,11 @@ fn testNumBytes() {
v.appendBit(false);
// 1 bit was added in the vector, so 1 byte should be consumed.
assert_eq!(1, v.getSizeInBytes());
v.appendBits(0, 7);
v.appendBits(0, 7).expect("append");
assert_eq!(1, v.getSizeInBytes());
v.appendBits(0, 8);
v.appendBits(0, 8).expect("append");
assert_eq!(2, v.getSizeInBytes());
v.appendBits(0, 1);
v.appendBits(0, 1).expect("append");
// We now have 17 bits, so 3 bytes should be consumed.
assert_eq!(3, v.getSizeInBytes());
}
@@ -114,9 +114,9 @@ fn testNumBytes() {
#[test]
fn testAppendBitVector() {
let mut v1 = BitArray::new();
v1.appendBits(0xbe, 8);
v1.appendBits(0xbe, 8).expect("append");
let mut v2 = BitArray::new();
v2.appendBits(0xef, 8);
v2.appendBits(0xef, 8).expect("append");
v1.appendBitArray(v2);
// beef = 1011 1110 1110 1111
assert_eq!(" X.XXXXX. XXX.XXXX", v1.to_string());
@@ -125,9 +125,9 @@ fn testAppendBitVector() {
#[test]
fn testXOR() {
let mut v1 = BitArray::new();
v1.appendBits(0x5555aaaa, 32);
v1.appendBits(0x5555aaaa, 32).expect("append");
let mut v2 = BitArray::new();
v2.appendBits(0xaaaa5555, 32);
v2.appendBits(0xaaaa5555, 32).expect("append");
v1.xor(&v2);
assert_eq!(0xffffffff, getUnsignedInt(&v1));
}
@@ -135,7 +135,7 @@ fn testXOR() {
#[test]
fn testXOR2() {
let mut v1 = BitArray::new();
v1.appendBits(0x2a, 7); // 010 1010
v1.appendBits(0x2a, 7).expect("append"); // 010 1010
let mut v2 = BitArray::new();
v2.appendBits(0x55, 7); // 101 0101
v1.xor(&v2);
@@ -145,7 +145,7 @@ fn testXOR2() {
#[test]
fn testAt() {
let mut v = BitArray::new();
v.appendBits(0xdead, 16); // 1101 1110 1010 1101
v.appendBits(0xdead, 16).expect("append"); // 1101 1110 1010 1101
assert!(v.get(0));
assert!(v.get(1));
assert!(!v.get(2));
@@ -170,6 +170,6 @@ fn testAt() {
#[test]
fn testToString() {
let mut v = BitArray::new();
v.appendBits(0xdead, 16); // 1101 1110 1010 1101
v.appendBits(0xdead, 16).expect("append"); // 1101 1110 1010 1101
assert_eq!(" XX.XXXX. X.X.XX.X", v.to_string());
}

View File

@@ -686,23 +686,23 @@ fn testInterleaveWithECBytes() {
fn testAppendNumericBytes() {
// 1 = 01 = 0001 in 4 bits.
let mut bits = BitArray::new();
encoder::appendNumericBytes("1", &mut bits);
encoder::appendNumericBytes("1", &mut bits).expect("append");
assert_eq!(" ...X", bits.to_string());
// 12 = 0xc = 0001100 in 7 bits.
let mut bits = BitArray::new();
encoder::appendNumericBytes("12", &mut bits);
encoder::appendNumericBytes("12", &mut bits).expect("append");
assert_eq!(" ...XX..", bits.to_string());
// 123 = 0x7b = 0001111011 in 10 bits.
let mut bits = BitArray::new();
encoder::appendNumericBytes("123", &mut bits);
encoder::appendNumericBytes("123", &mut bits).expect("append");
assert_eq!(" ...XXXX. XX", bits.to_string());
// 1234 = "123" + "4" = 0001111011 + 0100
let mut bits = BitArray::new();
encoder::appendNumericBytes("1234", &mut bits);
encoder::appendNumericBytes("1234", &mut bits).expect("append");
assert_eq!(" ...XXXX. XX.X..", bits.to_string());
// Empty.
let mut bits = BitArray::new();
encoder::appendNumericBytes("", &mut bits);
encoder::appendNumericBytes("", &mut bits).expect("append");
assert_eq!("", bits.to_string());
}
@@ -710,19 +710,19 @@ fn testAppendNumericBytes() {
fn testAppendAlphanumericBytes() {
// A = 10 = 0xa = 001010 in 6 bits
let mut bits = BitArray::new();
encoder::appendAlphanumericBytes("A", &mut bits);
encoder::appendAlphanumericBytes("A", &mut bits).expect("append");
assert_eq!(" ..X.X.", bits.to_string());
// AB = 10 * 45 + 11 = 461 = 0x1cd = 00111001101 in 11 bits
let mut bits = BitArray::new();
encoder::appendAlphanumericBytes("AB", &mut bits);
encoder::appendAlphanumericBytes("AB", &mut bits).expect("append");
assert_eq!(" ..XXX..X X.X", bits.to_string());
// ABC = "AB" + "C" = 00111001101 + 001100
let mut bits = BitArray::new();
encoder::appendAlphanumericBytes("ABC", &mut bits);
encoder::appendAlphanumericBytes("ABC", &mut bits).expect("append");
assert_eq!(" ..XXX..X X.X..XX. .", bits.to_string());
// Empty.
let mut bits = BitArray::new();
encoder::appendAlphanumericBytes("", &mut bits);
encoder::appendAlphanumericBytes("", &mut bits).expect("append");
assert_eq!("", bits.to_string());
// Invalid data.
// try {
@@ -738,11 +738,11 @@ fn testAppendAlphanumericBytes() {
fn testAppend8BitBytes() {
// 0x61, 0x62, 0x63
let mut bits = BitArray::new();
encoder::append8BitBytes("abc", &mut bits, encoder::DEFAULT_BYTE_MODE_ENCODING);
encoder::append8BitBytes("abc", &mut bits, encoder::DEFAULT_BYTE_MODE_ENCODING).expect("append");
assert_eq!(" .XX....X .XX...X. .XX...XX", bits.to_string());
// Empty.
let mut bits = BitArray::new();
encoder::append8BitBytes("", &mut bits, encoder::DEFAULT_BYTE_MODE_ENCODING);
encoder::append8BitBytes("", &mut bits, encoder::DEFAULT_BYTE_MODE_ENCODING).expect("append");
assert_eq!("", bits.to_string());
}
@@ -750,9 +750,9 @@ fn testAppend8BitBytes() {
#[test]
fn testAppendKanjiBytes() {
let mut bits = BitArray::new();
encoder::appendKanjiBytes(&shiftJISString(&[0x93, 0x5f]), &mut bits);
encoder::appendKanjiBytes(&shiftJISString(&[0x93, 0x5f]), &mut bits).expect("append");
assert_eq!(" .XX.XX.. XXXXX", bits.to_string());
encoder::appendKanjiBytes(&shiftJISString(&[0xe4, 0xaa]), &mut bits);
encoder::appendKanjiBytes(&shiftJISString(&[0xe4, 0xaa]), &mut bits).expect("append");
assert_eq!(" .XX.XX.. XXXXXXX. X.X.X.X. X.", bits.to_string());
}
@@ -826,7 +826,7 @@ fn testBugInBitVectorNumBytes() {
// 11745 bits = 1468.125 bytes are needed (i.e. cannot fit in 1468
// bytes).
let mut builder = String::with_capacity(3518);
for x in 0..3518 {
for _x in 0..3518 {
// for (int x = 0; x < 3518; x++) {
builder.push('0');
}

View File

@@ -209,7 +209,7 @@ fn testEmbedDataBits() {
)
.expect("op ok");
let bits = BitArray::new();
matrix_util::embedDataBits(&bits, -1, &mut matrix);
matrix_util::embedDataBits(&bits, -1, &mut matrix).expect("append");
let expected = r" 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1
1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1
1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1
@@ -254,7 +254,7 @@ fn testBuildMatrix() {
Version::getVersionForNumber(1).expect("version"), // Version 1
3, // Mask pattern 3
&mut matrix,
);
).expect("append");
let expected = r" 1 1 1 1 1 1 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1
1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1
1 0 1 1 1 0 1 0 0 0 0 1 0 0 1 0 1 1 1 0 1
@@ -344,6 +344,6 @@ fn testMakeVersionInfoBits() {
fn testMakeTypeInfoInfoBits() {
// From Appendix C in JISX0510:2004 (p 65)
let mut bits = BitArray::new();
matrix_util::makeTypeInfoBits(&ErrorCorrectionLevel::M, 5, &mut bits);
matrix_util::makeTypeInfoBits(&ErrorCorrectionLevel::M, 5, &mut bits).expect("append");
assert_eq!(" X......X X..XXX.", bits.to_string());
}

View File

@@ -43,7 +43,7 @@ use unicode_segmentation::UnicodeSegmentation;
use crate::{
common::{
reedsolomon::{get_predefined_genericgf, PredefinedGenericGF, ReedSolomonEncoder},
BitArray, CharacterSetECI, StringUtils,
BitArray, CharacterSetECI,
},
qrcode::decoder::{ErrorCorrectionLevel, Mode, Version, VersionRef},
EncodeHintType, EncodeHintValue, EncodingHintDictionary, Exceptions,

View File

@@ -24,7 +24,7 @@ use crate::{
Exceptions,
};
use unicode_segmentation::{Graphemes, UnicodeSegmentation};
use unicode_segmentation::{ UnicodeSegmentation};
use super::encoder;