| 1 | #![cfg(feature = "python_tests")] |
| 2 | |
| 3 | extern crate cpythonrust-analyzer cargo zbase32 0.1.2 cpython/; |
| 4 | #[macro_use] |
| 5 | extern crate quickcheckrust-analyzer cargo zbase32 0.1.2 quickcheck/; |
| 6 | extern crate zbase32rust-analyzer cargo zbase32 0.1.2 zbase32/; |
| 7 | |
| 8 | mod commonrust-analyzer cargo zbase32 0.1.2 common/; |
| 9 | use commonrust-analyzer cargo zbase32 0.1.2 common/::*; |
| 10 | |
| 11 | use cpythonrust-analyzer cargo cpython 0.2.1 crate/::{Pythonrust-analyzer cargo cpython 0.2.1 python/Python#, PyDictrust-analyzer cargo cpython 0.2.1 objects/dict/PyDict#, PyResultrust-analyzer cargo cpython 0.2.1 err/PyResult#, PyBytesrust-analyzer cargo cpython 0.2.1 objects/string/PyBytes#}; |
| 12 | |
| 13 | quickcheckrust-analyzer cargo quickcheck 0.7.2 quickcheck!! { |
| 14 | fn encoderust-analyzer cargo zbase32 0.1.2 encode().(input: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> bool { |
| 15 | let bits = rand_bit_lengthrust-analyzer cargo zbase32 0.1.2 common/rand_bit_length().(input.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 8); |
| 16 | let rust = zbase32rust-analyzer cargo zbase32 0.1.2 crate/::encoderust-analyzer cargo zbase32 0.1.2 encode().(&input, bits); |
| 17 | let python = py_encoderust-analyzer cargo zbase32 0.1.2 py_encode().(&input[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(bits)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 18 | rust == python |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | quickcheckrust-analyzer cargo quickcheck 0.7.2 quickcheck!! { |
| 23 | fn decoderust-analyzer cargo zbase32 0.1.2 decode().(input: ZBaseEncodedDatarust-analyzer cargo zbase32 0.1.2 common/ZBaseEncodedData#) -> bool { |
| 24 | let bits = rand_bit_lengthrust-analyzer cargo zbase32 0.1.2 common/rand_bit_length().(input.lenrust-analyzer cargo zbase32 0.1.2 common/impl#[ZBaseEncodedData]len().(), 5); |
| 25 | let rust = zbase32rust-analyzer cargo zbase32 0.1.2 crate/::decoderust-analyzer cargo zbase32 0.1.2 decode().(input.as_bytesrust-analyzer cargo zbase32 0.1.2 common/impl#[ZBaseEncodedData]as_bytes().(), bits).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 26 | let python = py_decoderust-analyzer cargo zbase32 0.1.2 py_decode().(&input.as_bytesrust-analyzer cargo zbase32 0.1.2 common/impl#[ZBaseEncodedData]as_bytes().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(bits)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 27 | rust == python |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | quickcheckrust-analyzer cargo quickcheck 0.7.2 quickcheck!! { |
| 32 | fn encode_bytesrust-analyzer cargo zbase32 0.1.2 encode_bytes().(input: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> bool { |
| 33 | let rust = zbase32rust-analyzer cargo zbase32 0.1.2 crate/::encode_full_bytesrust-analyzer cargo zbase32 0.1.2 encode_full_bytes().(&input); |
| 34 | let python = py_encoderust-analyzer cargo zbase32 0.1.2 py_encode().(&input[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 35 | rust == python |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | quickcheckrust-analyzer cargo quickcheck 0.7.2 quickcheck!! { |
| 40 | fn decode_bytesrust-analyzer cargo zbase32 0.1.2 decode_bytes().(input: ZBaseEncodedDatarust-analyzer cargo zbase32 0.1.2 common/ZBaseEncodedData#) -> bool { |
| 41 | let rust = zbase32rust-analyzer cargo zbase32 0.1.2 crate/::decode_full_bytesrust-analyzer cargo zbase32 0.1.2 decode_full_bytes().(input.as_bytesrust-analyzer cargo zbase32 0.1.2 common/impl#[ZBaseEncodedData]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 42 | let python = py_decoderust-analyzer cargo zbase32 0.1.2 py_decode().(&input.as_bytesrust-analyzer cargo zbase32 0.1.2 common/impl#[ZBaseEncodedData]as_bytes().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 43 | rust == python |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | fn py_encoderust-analyzer cargo zbase32 0.1.2 py_encode().(input: &[u8], bits: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u64>) -> PyResultrust-analyzer cargo cpython 0.2.1 err/PyResult#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 48 | let gil = Pythonrust-analyzer cargo cpython 0.2.1 python/Python#::acquire_gilrust-analyzer cargo cpython 0.2.1 python/impl#[`Python<'p>`]acquire_gil().(); |
| 49 | let py = gil.pythonrust-analyzer cargo cpython 0.2.1 pythonrun/impl#[GILGuard]python().(); |
| 50 | let locals = PyDictrust-analyzer cargo cpython 0.2.1 objects/dict/PyDict#::newrust-analyzer cargo cpython 0.2.1 objects/dict/impl#[PyDict]new().(py); |
| 51 | locals.set_itemrust-analyzer cargo cpython 0.2.1 objects/dict/impl#[PyDict]set_item().(py, "pyzbase32", py.importrust-analyzer cargo cpython 0.2.1 python/impl#[`Python<'p>`]import().("pyzbase32")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 52 | locals.set_itemrust-analyzer cargo cpython 0.2.1 objects/dict/impl#[PyDict]set_item().(py, "input", PyBytesrust-analyzer cargo cpython 0.2.1 objects/string/PyBytes#::newrust-analyzer cargo cpython 0.2.1 objects/string/impl#[PyBytes]new().(py, input))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 53 | let result: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(bits) = bits { |
| 54 | locals.set_itemrust-analyzer cargo cpython 0.2.1 objects/dict/impl#[PyDict]set_item().(py, "bits", bits)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 55 | py.evalrust-analyzer cargo cpython 0.2.1 python/impl#[`Python<'p>`]eval().( |
| 56 | "pyzbase32.encode(input, bits).decode()", |
| 57 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 58 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&locals), |
| 59 | ) |
| 60 | } else { |
| 61 | py.evalrust-analyzer cargo cpython 0.2.1 python/impl#[`Python<'p>`]eval().( |
| 62 | "pyzbase32.encode_bytes(input).decode()", |
| 63 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 64 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&locals), |
| 65 | ) |
| 66 | }?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 67 | .extractrust-analyzer cargo cpython 0.2.1 objects/object/impl#[PyObject]extract().(py)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 68 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(result) |
| 69 | } |
| 70 | |
| 71 | fn py_decoderust-analyzer cargo zbase32 0.1.2 py_decode().(input: &[u8], bits: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u64>) -> PyResultrust-analyzer cargo cpython 0.2.1 err/PyResult#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> { |
| 72 | let gil = Pythonrust-analyzer cargo cpython 0.2.1 python/Python#::acquire_gilrust-analyzer cargo cpython 0.2.1 python/impl#[`Python<'p>`]acquire_gil().(); |
| 73 | let py = gil.pythonrust-analyzer cargo cpython 0.2.1 pythonrun/impl#[GILGuard]python().(); |
| 74 | let locals = PyDictrust-analyzer cargo cpython 0.2.1 objects/dict/PyDict#::newrust-analyzer cargo cpython 0.2.1 objects/dict/impl#[PyDict]new().(py); |
| 75 | locals.set_itemrust-analyzer cargo cpython 0.2.1 objects/dict/impl#[PyDict]set_item().(py, "pyzbase32", py.importrust-analyzer cargo cpython 0.2.1 python/impl#[`Python<'p>`]import().("pyzbase32")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 76 | locals.set_itemrust-analyzer cargo cpython 0.2.1 objects/dict/impl#[PyDict]set_item().(py, "input", PyBytesrust-analyzer cargo cpython 0.2.1 objects/string/PyBytes#::newrust-analyzer cargo cpython 0.2.1 objects/string/impl#[PyBytes]new().(py, input))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 77 | let result: PyBytesrust-analyzer cargo cpython 0.2.1 objects/string/PyBytes# = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(bits) = bits { |
| 78 | locals.set_itemrust-analyzer cargo cpython 0.2.1 objects/dict/impl#[PyDict]set_item().(py, "bits", bits)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 79 | py.evalrust-analyzer cargo cpython 0.2.1 python/impl#[`Python<'p>`]eval().("pyzbase32.decode(input, bits)", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&locals)) |
| 80 | } else { |
| 81 | py.evalrust-analyzer cargo cpython 0.2.1 python/impl#[`Python<'p>`]eval().("pyzbase32.decode_bytes(input)", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&locals)) |
| 82 | }?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 83 | .extractrust-analyzer cargo cpython 0.2.1 objects/object/impl#[PyObject]extract().(py)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 84 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`][`From<&[T]>`]from().(result.datarust-analyzer cargo cpython 0.2.1 objects/string/impl#[PyBytes]data().(py))) |
| 85 | } |