-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
64 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,11 @@ jobs: | |
- name: Install Rust toolchain | ||
uses: dtolnay/[email protected] # MSRV | ||
- name: Check (-std -alloc) | ||
run: cargo check --lib --no-default-features | ||
run: cargo check --no-default-features | ||
- name: Check (-std +alloc) | ||
run: cargo check --lib --no-default-features --features alloc | ||
run: cargo check --no-default-features --features alloc | ||
- name: Check (+std +alloc) | ||
run: cargo check --lib --no-default-features --features alloc,std | ||
run: cargo check --no-default-features --features alloc,std | ||
|
||
tests: | ||
name: Tests | ||
|
@@ -29,7 +29,7 @@ jobs: | |
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
- name: Install Rust toolchain | ||
uses: dtolnay/rust-toolchain@1.72 # MSRV | ||
uses: dtolnay/rust-toolchain | ||
- name: Build tests | ||
run: cargo test --no-run | ||
- name: Run tests | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,9 @@ mod buf; | |
|
||
mod slice; | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
|
||
#[cfg(feature = "alloc")] | ||
pub use self::buf::*; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use { | ||
crate::{cstr8, CStr8}, | ||
core::ffi::CStr, | ||
}; | ||
|
||
#[test] | ||
fn test_cstr8_macro() { | ||
const STR_LITERAL: &CStr8 = cstr8!("literal"); | ||
assert_eq!(STR_LITERAL, "literal"); | ||
assert_eq!(STR_LITERAL.as_bytes_with_nul(), b"literal\0"); | ||
|
||
const STR_CONSTANT: &str = "constant"; | ||
const STR_WITH_NUL: &CStr8 = cstr8!(STR_CONSTANT); | ||
assert_eq!(STR_WITH_NUL, "constant"); | ||
assert_eq!(STR_WITH_NUL.as_bytes_with_nul(), b"constant\0"); | ||
|
||
const BYTES_CONSTANT: &[u8] = b"bytes constant"; | ||
const BYTES_WITH_NUL: &CStr8 = cstr8!(BYTES_CONSTANT); | ||
assert_eq!(BYTES_WITH_NUL, "bytes constant"); | ||
assert_eq!(BYTES_WITH_NUL.as_bytes_with_nul(), b"bytes constant\0"); | ||
|
||
const BYTE_ARRAY_REF_LITERAL: &CStr8 = cstr8!(b"bytes literal"); | ||
assert_eq!(BYTE_ARRAY_REF_LITERAL, "bytes literal"); | ||
assert_eq!( | ||
BYTE_ARRAY_REF_LITERAL.as_bytes_with_nul(), | ||
b"bytes literal\0" | ||
); | ||
|
||
const BYTE_ARRAY_REF_CONSTANT: &[u8; 14] = b"bytes constant"; | ||
const BYTE_ARRAY_REF_WITH_NUL: &CStr8 = cstr8!(BYTE_ARRAY_REF_CONSTANT); | ||
assert_eq!(BYTE_ARRAY_REF_WITH_NUL, "bytes constant"); | ||
assert_eq!( | ||
BYTE_ARRAY_REF_WITH_NUL.as_bytes_with_nul(), | ||
b"bytes constant\0" | ||
); | ||
|
||
const BYTE_ARRAY_LITERAL: &CStr8 = cstr8!([b'h', b'i']); | ||
assert_eq!(BYTE_ARRAY_LITERAL, "hi"); | ||
assert_eq!(BYTE_ARRAY_LITERAL.as_bytes_with_nul(), b"hi\0"); | ||
|
||
const BYTE_ARRAY_CONSTANT: [u8; 19] = *b"byte array constant"; | ||
const BYTE_ARRAY_WITH_NUL: &CStr8 = cstr8!(BYTE_ARRAY_CONSTANT); | ||
assert_eq!(BYTE_ARRAY_WITH_NUL, "byte array constant"); | ||
assert_eq!( | ||
BYTE_ARRAY_WITH_NUL.as_bytes_with_nul(), | ||
b"byte array constant\0" | ||
); | ||
|
||
const CSTR_LITERAL: &CStr8 = cstr8!(c"cstr literal"); | ||
assert_eq!(CSTR_LITERAL, "cstr literal"); | ||
assert_eq!(CSTR_LITERAL.as_bytes_with_nul(), b"cstr literal\0"); | ||
|
||
const CSTR_CONSTANT: &CStr = c"cstr constant"; | ||
const CSTR_UTF8: &CStr8 = cstr8!(CSTR_CONSTANT); | ||
assert_eq!(CSTR_UTF8, "cstr constant"); | ||
assert_eq!(CSTR_UTF8.as_bytes_with_nul(), b"cstr constant\0"); | ||
} |