|
2 | 2 | #![no_std]
|
3 | 3 | #![no_main]
|
4 | 4 |
|
5 |
| -extern crate data_encoding; |
6 |
| -extern crate libc; |
7 |
| - |
8 | 5 | use core::fmt::Write;
|
9 |
| -use data_encoding::{Encoding, BASE32, BASE64, BASE64_NOPAD, HEXLOWER_PERMISSIVE}; |
| 6 | +use data_encoding::Encoding; |
10 | 7 |
|
11 | 8 | #[lang = "eh_personality"]
|
12 | 9 | extern "C" fn eh_personality() {}
|
@@ -75,13 +72,33 @@ fn test(encoding: &Encoding, input: &[u8], output: &str, buffer: &mut [u8]) {
|
75 | 72 | test_decode(encoding, output, buffer, input);
|
76 | 73 | }
|
77 | 74 |
|
| 75 | +#[cfg(feature = "alloc")] |
| 76 | +fn test_macro() { |
| 77 | + // TODO(ia0): We shouldn't need to import decode_slice. Might be fixed by #36. |
| 78 | + use data_encoding_macro::{ |
| 79 | + base64, decode_slice, internal_decode_slice, internal_new_encoding, new_encoding, |
| 80 | + }; |
| 81 | + |
| 82 | + const FOOBAR: &'static [u8] = &base64!("Zm9vYmFy"); |
| 83 | + const LETTER8: Encoding = new_encoding! { |
| 84 | + symbols: "ABCDEFGH", |
| 85 | + }; |
| 86 | + |
| 87 | + assert_eq!(FOOBAR, b"foobar"); |
| 88 | + test(&LETTER8, &[0], "AAA", &mut [0; 3]); |
| 89 | + test(&LETTER8, b"foobar", "DBEGHFFHDAEGAFGC", &mut [0; 16]); |
| 90 | +} |
| 91 | + |
78 | 92 | #[no_mangle]
|
79 | 93 | pub extern "C" fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
| 94 | + use data_encoding::{BASE32, BASE64, BASE64_NOPAD, HEXLOWER_PERMISSIVE}; |
80 | 95 | test(&BASE32, b"hello", "NBSWY3DP", &mut [0; 8]);
|
81 | 96 | test(&BASE64, b"hello", "aGVsbG8=", &mut [0; 8]);
|
82 | 97 | test(&BASE64_NOPAD, b"hello", "aGVsbG8", &mut [0; 8]);
|
83 | 98 | test(&HEXLOWER_PERMISSIVE, b"hello", "68656c6c6f", &mut [0; 10]);
|
84 | 99 | test_decode(&HEXLOWER_PERMISSIVE, "68656C6C6F", &mut [0; 5], b"hello");
|
| 100 | + #[cfg(feature = "alloc")] |
| 101 | + test_macro(); |
85 | 102 | let _ = writeln!(Fd(1), "All tests passed.");
|
86 | 103 | 0
|
87 | 104 | }
|
0 commit comments