Add quote_spanned smoke test to test suite

This commit is contained in:
David Tolnay 2020-06-07 11:07:02 -07:00
parent 2f191555c9
commit c00eda5d49
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -4,7 +4,7 @@ use std::borrow::Cow;
use std::collections::BTreeSet;
use proc_macro2::{Ident, Span, TokenStream};
use quote::{format_ident, quote, TokenStreamExt};
use quote::{format_ident, quote, quote_spanned, TokenStreamExt};
struct X;
@ -35,6 +35,28 @@ fn test_quote_impl() {
assert_eq!(expected, tokens.to_string());
}
#[test]
fn test_quote_spanned_impl() {
let span = Span::call_site();
let tokens = quote_spanned! {span=>
impl<'a, T: ToTokens> ToTokens for &'a T {
fn to_tokens(&self, tokens: &mut TokenStream) {
(**self).to_tokens(tokens)
}
}
};
let expected = concat!(
"impl < 'a , T : ToTokens > ToTokens for & 'a T { ",
"fn to_tokens ( & self , tokens : & mut TokenStream ) { ",
"( * * self ) . to_tokens ( tokens ) ",
"} ",
"}"
);
assert_eq!(expected, tokens.to_string());
}
#[test]
fn test_substitution() {
let x = X;