diff --git a/tests/test.rs b/tests/test.rs index bc2919b..6ff1402 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -12,6 +12,7 @@ use proc_macro2::{Delimiter, Group, Ident, Span, TokenStream}; use quote::{format_ident, quote, quote_spanned, TokenStreamExt}; use std::borrow::Cow; use std::collections::BTreeSet; +use std::ffi::{CStr, CString}; struct X; @@ -232,6 +233,22 @@ fn test_string() { assert_eq!(expected, tokens.to_string()); } +#[test] +fn test_c_str() { + let s = CStr::from_bytes_with_nul(b"\x01 a 'b \" c\0").unwrap(); + let tokens = quote!(#s); + let expected = "c\"\\u{1} a 'b \\\" c\""; + assert_eq!(expected, tokens.to_string()); +} + +#[test] +fn test_c_string() { + let s = CString::new(&b"\x01 a 'b \" c"[..]).unwrap(); + let tokens = quote!(#s); + let expected = "c\"\\u{1} a 'b \\\" c\""; + assert_eq!(expected, tokens.to_string()); +} + #[test] fn test_interpolated_literal() { macro_rules! m {