Skip to content

Commit 21eb699

Browse files
committed
Add no-std test for macro
1 parent a89028b commit 21eb699

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![Build Status][travis_badge]][travis]
77
[![Build Status][appveyor_badge]][appveyor]
88
[![Coverage Status][coveralls_badge]][coveralls]
9-
[![dependency status][dependency_badge]][dependency]
9+
[![Dependency Status][dependency_badge]][dependency]
1010

1111
This repository provides a Rust [library] and a [binary] providing efficient
1212
common and custom data-encodings.

nostd/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ license = "MIT"
77
publish = false
88

99
[features]
10-
alloc = ["data-encoding/alloc"]
10+
alloc = ["data-encoding/alloc", "data-encoding-macro"]
1111

1212
[dependencies]
1313
data-encoding = { path = "../lib", default-features = false }
14+
data-encoding-macro = { path = "../lib/macro", optional = true }
1415
libc = { version = "0.2", default-features = false }
1516

1617
[profile.release]

nostd/src/main.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
#![no_std]
33
#![no_main]
44

5-
extern crate data_encoding;
6-
extern crate libc;
7-
85
use core::fmt::Write;
9-
use data_encoding::{Encoding, BASE32, BASE64, BASE64_NOPAD, HEXLOWER_PERMISSIVE};
6+
use data_encoding::Encoding;
107

118
#[lang = "eh_personality"]
129
extern "C" fn eh_personality() {}
@@ -75,13 +72,33 @@ fn test(encoding: &Encoding, input: &[u8], output: &str, buffer: &mut [u8]) {
7572
test_decode(encoding, output, buffer, input);
7673
}
7774

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+
7892
#[no_mangle]
7993
pub extern "C" fn main(_argc: isize, _argv: *const *const u8) -> isize {
94+
use data_encoding::{BASE32, BASE64, BASE64_NOPAD, HEXLOWER_PERMISSIVE};
8095
test(&BASE32, b"hello", "NBSWY3DP", &mut [0; 8]);
8196
test(&BASE64, b"hello", "aGVsbG8=", &mut [0; 8]);
8297
test(&BASE64_NOPAD, b"hello", "aGVsbG8", &mut [0; 8]);
8398
test(&HEXLOWER_PERMISSIVE, b"hello", "68656c6c6f", &mut [0; 10]);
8499
test_decode(&HEXLOWER_PERMISSIVE, "68656C6C6F", &mut [0; 5], b"hello");
100+
#[cfg(feature = "alloc")]
101+
test_macro();
85102
let _ = writeln!(Fd(1), "All tests passed.");
86103
0
87104
}

0 commit comments

Comments
 (0)