Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/proc-macro-srv/src/tests/utils.rs')
-rw-r--r--crates/proc-macro-srv/src/tests/utils.rs26
1 files changed, 19 insertions, 7 deletions
diff --git a/crates/proc-macro-srv/src/tests/utils.rs b/crates/proc-macro-srv/src/tests/utils.rs
index 49b4d973b6..c12096d140 100644
--- a/crates/proc-macro-srv/src/tests/utils.rs
+++ b/crates/proc-macro-srv/src/tests/utils.rs
@@ -1,18 +1,18 @@
//! utils used in proc-macro tests
use expect_test::Expect;
-use std::str::FromStr;
+use proc_macro_api::msg::TokenId;
use crate::{dylib, proc_macro_test_dylib_path, ProcMacroSrv};
-fn parse_string(code: &str) -> Option<crate::server::TokenStream> {
+fn parse_string(code: &str, call_site: TokenId) -> Option<crate::server::TokenStream> {
// This is a bit strange. We need to parse a string into a token stream into
// order to create a tt::SubTree from it in fixtures. `into_subtree` is
// implemented by all the ABIs we have so we arbitrarily choose one ABI to
// write a `parse_string` function for and use that. The tests don't really
// care which ABI we're using as the `into_subtree` function isn't part of
// the ABI and shouldn't change between ABI versions.
- crate::server::TokenStream::from_str(code).ok()
+ crate::server::TokenStream::from_str(code, call_site).ok()
}
pub fn assert_expand(macro_name: &str, ra_fixture: &str, expect: Expect) {
@@ -24,12 +24,24 @@ pub fn assert_expand_attr(macro_name: &str, ra_fixture: &str, attr_args: &str, e
}
fn assert_expand_impl(macro_name: &str, input: &str, attr: Option<&str>, expect: Expect) {
+ let def_site = TokenId(0);
+ let call_site = TokenId(1);
+ let mixed_site = TokenId(2);
let path = proc_macro_test_dylib_path();
let expander = dylib::Expander::new(&path).unwrap();
- let fixture = parse_string(input).unwrap();
- let attr = attr.map(|attr| parse_string(attr).unwrap().into_subtree());
-
- let res = expander.expand(macro_name, &fixture.into_subtree(), attr.as_ref()).unwrap();
+ let fixture = parse_string(input, call_site).unwrap();
+ let attr = attr.map(|attr| parse_string(attr, call_site).unwrap().into_subtree(call_site));
+
+ let res = expander
+ .expand(
+ macro_name,
+ &fixture.into_subtree(call_site),
+ attr.as_ref(),
+ def_site,
+ call_site,
+ mixed_site,
+ )
+ .unwrap();
expect.assert_eq(&format!("{res:?}"));
}