| 1 | #[macro_use] |
| 2 | extern crate quickcheckrust-analyzer cargo zbase32 0.1.2 quickcheck/; |
| 3 | extern crate zbase32rust-analyzer cargo zbase32 0.1.2 zbase32/; |
| 4 | |
| 5 | mod commonrust-analyzer cargo zbase32 0.1.2 common/; |
| 6 | use commonrust-analyzer cargo zbase32 0.1.2 common/::*; |
| 7 | |
| 8 | use quickcheckrust-analyzer cargo quickcheck 0.7.2 crate/::TestResultrust-analyzer cargo quickcheck 0.7.2 tester/TestResult#; |
| 9 | |
| 10 | quickcheckrust-analyzer cargo quickcheck 0.7.2 quickcheck!! { |
| 11 | fn test_recoderust-analyzer cargo zbase32 0.1.2 test_recode().(data: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> bool { |
| 12 | let encoded = zbase32rust-analyzer cargo zbase32 0.1.2 crate/::encoderust-analyzer cargo zbase32 0.1.2 encode().(&data, data.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() as u64 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). 8); |
| 13 | let encoded_bytes = zbase32rust-analyzer cargo zbase32 0.1.2 crate/::encode_full_bytesrust-analyzer cargo zbase32 0.1.2 encode_full_bytes().(&data); |
| 14 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(encoded, encoded_bytes); |
| 15 | |
| 16 | let decoded = zbase32rust-analyzer cargo zbase32 0.1.2 crate/::decoderust-analyzer cargo zbase32 0.1.2 decode().(&encoded.as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().(), data.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() as u64 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). 8).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 17 | let decoded_bytes = zbase32rust-analyzer cargo zbase32 0.1.2 crate/::decode_full_bytesrust-analyzer cargo zbase32 0.1.2 decode_full_bytes().(&encoded.as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 18 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(decoded, decoded_bytes); |
| 19 | data == decoded |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | quickcheckrust-analyzer cargo quickcheck 0.7.2 quickcheck!! { |
| 24 | fn try_decode_okrust-analyzer cargo zbase32 0.1.2 try_decode_ok().(data: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> TestResultrust-analyzer cargo quickcheck 0.7.2 tester/TestResult# { |
| 25 | if zbase32rust-analyzer cargo zbase32 0.1.2 crate/::validaterust-analyzer cargo zbase32 0.1.2 validate().(&data) { |
| 26 | TestResultrust-analyzer cargo quickcheck 0.7.2 tester/TestResult#::from_boolrust-analyzer cargo quickcheck 0.7.2 tester/impl#[TestResult]from_bool().(zbase32rust-analyzer cargo zbase32 0.1.2 crate/::decode_full_bytesrust-analyzer cargo zbase32 0.1.2 decode_full_bytes().(&data).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()) |
| 27 | } else { |
| 28 | TestResultrust-analyzer cargo quickcheck 0.7.2 tester/TestResult#::discardrust-analyzer cargo quickcheck 0.7.2 tester/impl#[TestResult]discard().() |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | quickcheckrust-analyzer cargo quickcheck 0.7.2 quickcheck!! { |
| 34 | fn try_decode_errrust-analyzer cargo zbase32 0.1.2 try_decode_err().(data: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> TestResultrust-analyzer cargo quickcheck 0.7.2 tester/TestResult# { |
| 35 | if zbase32rust-analyzer cargo zbase32 0.1.2 crate/::validaterust-analyzer cargo zbase32 0.1.2 validate().(&data) { |
| 36 | TestResultrust-analyzer cargo quickcheck 0.7.2 tester/TestResult#::discardrust-analyzer cargo quickcheck 0.7.2 tester/impl#[TestResult]discard().() |
| 37 | } else { |
| 38 | TestResultrust-analyzer cargo quickcheck 0.7.2 tester/TestResult#::from_boolrust-analyzer cargo quickcheck 0.7.2 tester/impl#[TestResult]from_bool().(zbase32rust-analyzer cargo zbase32 0.1.2 crate/::decode_full_bytesrust-analyzer cargo zbase32 0.1.2 decode_full_bytes().(&data).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()) |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | quickcheckrust-analyzer cargo quickcheck 0.7.2 quickcheck!! { |
| 44 | fn data_len_exceeds_bits_when_encodingrust-analyzer cargo zbase32 0.1.2 data_len_exceeds_bits_when_encoding().(data: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, arbitrary: u8) -> TestResultrust-analyzer cargo quickcheck 0.7.2 tester/TestResult# { |
| 45 | let len = data.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() as u64 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). 8 +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). 1 +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). arbitrary as u64; |
| 46 | TestResultrust-analyzer cargo quickcheck 0.7.2 tester/TestResult#::must_failrust-analyzer cargo quickcheck 0.7.2 tester/impl#[TestResult]must_fail().(move || { |
| 47 | zbase32rust-analyzer cargo zbase32 0.1.2 crate/::encoderust-analyzer cargo zbase32 0.1.2 encode().(&data, len); |
| 48 | }) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | quickcheckrust-analyzer cargo quickcheck 0.7.2 quickcheck!! { |
| 53 | fn data_len_exceeds_bits_when_ecodingrust-analyzer cargo zbase32 0.1.2 data_len_exceeds_bits_when_ecoding().(data: ZBaseEncodedDatarust-analyzer cargo zbase32 0.1.2 common/ZBaseEncodedData#, arbitrary: u8) -> TestResultrust-analyzer cargo quickcheck 0.7.2 tester/TestResult# { |
| 54 | let len = data.as_bytesrust-analyzer cargo zbase32 0.1.2 common/impl#[ZBaseEncodedData]as_bytes().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as u64 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). 5 +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). 1 +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). arbitrary as u64; |
| 55 | TestResultrust-analyzer cargo quickcheck 0.7.2 tester/TestResult#::must_failrust-analyzer cargo quickcheck 0.7.2 tester/impl#[TestResult]must_fail().(move || { |
| 56 | let _ = zbase32rust-analyzer cargo zbase32 0.1.2 crate/::decoderust-analyzer cargo zbase32 0.1.2 decode().(data.as_bytesrust-analyzer cargo zbase32 0.1.2 common/impl#[ZBaseEncodedData]as_bytes().(), len); |
| 57 | }) |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | quickcheckrust-analyzer cargo quickcheck 0.7.2 quickcheck!! { |
| 62 | fn encode_too_longrust-analyzer cargo zbase32 0.1.2 encode_too_long().(data: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> () { |
| 63 | let rand_bits = rand_bit_lengthrust-analyzer cargo zbase32 0.1.2 common/rand_bit_length().(data.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 8); |
| 64 | zbase32rust-analyzer cargo zbase32 0.1.2 crate/::encoderust-analyzer cargo zbase32 0.1.2 encode().(&data, rand_bits); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | quickcheckrust-analyzer cargo quickcheck 0.7.2 quickcheck!! { |
| 69 | fn recode_partialrust-analyzer cargo zbase32 0.1.2 recode_partial().(data: ZBaseEncodedDatarust-analyzer cargo zbase32 0.1.2 common/ZBaseEncodedData#) -> bool { |
| 70 | let rand_bits = rand_bit_lengthrust-analyzer cargo zbase32 0.1.2 common/rand_bit_length().(data.lenrust-analyzer cargo zbase32 0.1.2 common/impl#[ZBaseEncodedData]len().(), 5); |
| 71 | let decoded1 = zbase32rust-analyzer cargo zbase32 0.1.2 crate/::decoderust-analyzer cargo zbase32 0.1.2 decode().(&data.as_bytesrust-analyzer cargo zbase32 0.1.2 common/impl#[ZBaseEncodedData]as_bytes().(), rand_bits).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 72 | let encoded = zbase32rust-analyzer cargo zbase32 0.1.2 crate/::encoderust-analyzer cargo zbase32 0.1.2 encode().(&decoded1, rand_bits); |
| 73 | let decoded2 = zbase32rust-analyzer cargo zbase32 0.1.2 crate/::decode_strrust-analyzer cargo zbase32 0.1.2 decode_str().(&encoded, rand_bits).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 74 | decoded1 == decoded2 |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | quickcheckrust-analyzer cargo quickcheck 0.7.2 quickcheck!! { |
| 79 | fn decoderust-analyzer cargo zbase32 0.1.2 decode().(data: ZBaseEncodedDatarust-analyzer cargo zbase32 0.1.2 common/ZBaseEncodedData#) -> bool { |
| 80 | zbase32rust-analyzer cargo zbase32 0.1.2 crate/::decode_full_bytesrust-analyzer cargo zbase32 0.1.2 decode_full_bytes().(&data.as_bytesrust-analyzer cargo zbase32 0.1.2 common/impl#[ZBaseEncodedData]as_bytes().()).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().() |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | quickcheckrust-analyzer cargo quickcheck 0.7.2 quickcheck!! { |
| 85 | fn validaterust-analyzer cargo zbase32 0.1.2 validate().(data: ZBaseEncodedDatarust-analyzer cargo zbase32 0.1.2 common/ZBaseEncodedData#) -> bool { |
| 86 | zbase32rust-analyzer cargo zbase32 0.1.2 crate/::validaterust-analyzer cargo zbase32 0.1.2 validate().(&data.as_bytesrust-analyzer cargo zbase32 0.1.2 common/impl#[ZBaseEncodedData]as_bytes().()) |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | quickcheckrust-analyzer cargo quickcheck 0.7.2 quickcheck!! { |
| 91 | fn validate_strrust-analyzer cargo zbase32 0.1.2 validate_str().(data: ZBaseEncodedDatarust-analyzer cargo zbase32 0.1.2 common/ZBaseEncodedData#) -> bool { |
| 92 | let data = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8().(data.into_bytesrust-analyzer cargo zbase32 0.1.2 common/impl#[ZBaseEncodedData]into_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 93 | zbase32rust-analyzer cargo zbase32 0.1.2 crate/::validate_strrust-analyzer cargo zbase32 0.1.2 validate_str().(&data) |
| 94 | } |
| 95 | } |