use proc_macro2::TokenStream;
use quote_into::quote_into;
#[test]
fn interpolation_variable() {
let world = "world";
let mut s = TokenStream::new();
quote_into!(s += hello #world);
assert_eq!(s.to_string(), "hello \"world\"");
}
#[test]
fn interpolate_in_loop() {
let mut s = TokenStream::new();
quote_into!(s += [#{
for i in 0..3 {
quote_into!(s += #i, );
}
}]);
assert_eq!(s.to_string(), "[0i32 , 1i32 , 2i32 ,]");
}
#[test]
fn interpolation_block() {
fn world(t: &mut TokenStream) {
quote_into! {t += world }
}
let mut s = TokenStream::new();
quote_into!(s += hello #{ world(s) } );
assert_eq!(s.to_string(), "hello world");
}
#[test]
fn loop_with_nest() {
let mut s = TokenStream::new();
quote_into! {s +=
#{
for _ in 0..3 {
quote_into!(s +=
hi
);
}
}
};
assert_eq!(s.to_string(), "hi hi hi");
}
#[test]
fn interpolation_expression() {
let mut s = TokenStream::new();
quote_into!(s += const ANSWER: u32 = #(7 * 6););
assert_eq!(s.to_string(), "const ANSWER : u32 = 42i32 ;");
}
#[test]
fn attribute() {
let mut s = TokenStream::new();
quote_into! {s +=
#[allow(unused)]
fn main() {}
};
assert_eq!(s.to_string(), "# [allow (unused)] fn main () { }");
}