mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 14:51:48 +00:00
style: rename crates to kebab case
This commit is contained in:
parent
e025b37df6
commit
1f011fa4a3
462 changed files with 158 additions and 158 deletions
102
crates/proc-macro-srv/src/tests/mod.rs
Normal file
102
crates/proc-macro-srv/src/tests/mod.rs
Normal file
|
@ -0,0 +1,102 @@
|
|||
//! proc-macro tests
|
||||
|
||||
#[macro_use]
|
||||
mod utils;
|
||||
use expect_test::expect;
|
||||
use paths::AbsPathBuf;
|
||||
use utils::*;
|
||||
|
||||
#[test]
|
||||
fn test_derive_empty() {
|
||||
assert_expand("DeriveEmpty", r#"struct S;"#, expect![[r#"SUBTREE $"#]]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_derive_error() {
|
||||
assert_expand(
|
||||
"DeriveError",
|
||||
r#"struct S;"#,
|
||||
expect![[r##"
|
||||
SUBTREE $
|
||||
IDENT compile_error 4294967295
|
||||
PUNCH ! [alone] 4294967295
|
||||
SUBTREE () 4294967295
|
||||
LITERAL "#[derive(DeriveError)] struct S ;" 4294967295
|
||||
PUNCH ; [alone] 4294967295"##]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fn_like_macro() {
|
||||
assert_expand(
|
||||
"fn_like_noop",
|
||||
r#"ident, 0, 1, []"#,
|
||||
expect![[r#"
|
||||
SUBTREE $
|
||||
IDENT ident 4294967295
|
||||
PUNCH , [alone] 4294967295
|
||||
LITERAL 0 4294967295
|
||||
PUNCH , [alone] 4294967295
|
||||
LITERAL 1 4294967295
|
||||
PUNCH , [alone] 4294967295
|
||||
SUBTREE [] 4294967295"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fn_like_macro2() {
|
||||
assert_expand(
|
||||
"fn_like_clone_tokens",
|
||||
r#"ident, []"#,
|
||||
expect![[r#"
|
||||
SUBTREE $
|
||||
IDENT ident 4294967295
|
||||
PUNCH , [alone] 4294967295
|
||||
SUBTREE [] 4294967295"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_attr_macro() {
|
||||
// Corresponds to
|
||||
// #[proc_macro_test::attr_error(some arguments)]
|
||||
// mod m {}
|
||||
assert_expand_attr(
|
||||
"attr_error",
|
||||
r#"mod m {}"#,
|
||||
r#"some arguments"#,
|
||||
expect![[r##"
|
||||
SUBTREE $
|
||||
IDENT compile_error 4294967295
|
||||
PUNCH ! [alone] 4294967295
|
||||
SUBTREE () 4294967295
|
||||
LITERAL "#[attr_error(some arguments)] mod m {}" 4294967295
|
||||
PUNCH ; [alone] 4294967295"##]],
|
||||
);
|
||||
}
|
||||
|
||||
/// Tests that we find and classify all proc macros correctly.
|
||||
#[test]
|
||||
fn list_test_macros() {
|
||||
let res = list().join("\n");
|
||||
|
||||
expect![[r#"
|
||||
fn_like_noop [FuncLike]
|
||||
fn_like_panic [FuncLike]
|
||||
fn_like_error [FuncLike]
|
||||
fn_like_clone_tokens [FuncLike]
|
||||
attr_noop [Attr]
|
||||
attr_panic [Attr]
|
||||
attr_error [Attr]
|
||||
DeriveEmpty [CustomDerive]
|
||||
DerivePanic [CustomDerive]
|
||||
DeriveError [CustomDerive]"#]]
|
||||
.assert_eq(&res);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_version_check() {
|
||||
let path = AbsPathBuf::assert(fixtures::proc_macro_test_dylib_path());
|
||||
let info = proc_macro_api::read_dylib_info(&path).unwrap();
|
||||
assert!(info.version.1 >= 50);
|
||||
}
|
47
crates/proc-macro-srv/src/tests/utils.rs
Normal file
47
crates/proc-macro-srv/src/tests/utils.rs
Normal file
|
@ -0,0 +1,47 @@
|
|||
//! utils used in proc-macro tests
|
||||
|
||||
use crate::dylib;
|
||||
use crate::ProcMacroSrv;
|
||||
use expect_test::Expect;
|
||||
use std::str::FromStr;
|
||||
|
||||
pub mod fixtures {
|
||||
pub fn proc_macro_test_dylib_path() -> std::path::PathBuf {
|
||||
proc_macro_test::PROC_MACRO_TEST_LOCATION.into()
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_string(code: &str) -> Option<crate::abis::abi_1_48::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::abis::abi_1_48::TokenStream::from_str(code).ok()
|
||||
}
|
||||
|
||||
pub fn assert_expand(macro_name: &str, ra_fixture: &str, expect: Expect) {
|
||||
assert_expand_impl(macro_name, ra_fixture, None, expect);
|
||||
}
|
||||
|
||||
pub fn assert_expand_attr(macro_name: &str, ra_fixture: &str, attr_args: &str, expect: Expect) {
|
||||
assert_expand_impl(macro_name, ra_fixture, Some(attr_args), expect);
|
||||
}
|
||||
|
||||
fn assert_expand_impl(macro_name: &str, input: &str, attr: Option<&str>, expect: Expect) {
|
||||
let path = fixtures::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();
|
||||
expect.assert_eq(&format!("{:?}", res));
|
||||
}
|
||||
|
||||
pub(crate) fn list() -> Vec<String> {
|
||||
let dylib_path = fixtures::proc_macro_test_dylib_path();
|
||||
let mut srv = ProcMacroSrv::default();
|
||||
let res = srv.list_macros(&dylib_path).unwrap();
|
||||
res.into_iter().map(|(name, kind)| format!("{} [{:?}]", name, kind)).collect()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue