Skip to content

Commit

Permalink
Add C string tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Aug 22, 2024
1 parent 9fb0591 commit 6ac4328
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6ac4328

Please sign in to comment.