|
1 | 1 | //! A higher level attributes based on TokenTree, with also some shortcuts.
|
2 | 2 |
|
3 |
| -pub mod builtin; |
4 |
| - |
5 |
| -#[cfg(test)] |
6 |
| -mod tests; |
7 |
| - |
8 | 3 | use std::{borrow::Cow, hash::Hash, ops, slice::Iter as SliceIter};
|
9 | 4 |
|
10 | 5 | use base_db::CrateId;
|
@@ -75,7 +70,7 @@ impl Attrs {
|
75 | 70 | db: &dyn DefDatabase,
|
76 | 71 | v: VariantId,
|
77 | 72 | ) -> Arc<ArenaMap<LocalFieldId, Attrs>> {
|
78 |
| - let _p = tracing::span!(tracing::Level::INFO, "fields_attrs_query").entered(); |
| 73 | + let _p = tracing::info_span!("fields_attrs_query").entered(); |
79 | 74 | // FIXME: There should be some proper form of mapping between item tree field ids and hir field ids
|
80 | 75 | let mut res = ArenaMap::default();
|
81 | 76 |
|
@@ -326,7 +321,7 @@ impl AttrsWithOwner {
|
326 | 321 | }
|
327 | 322 |
|
328 | 323 | pub(crate) fn attrs_query(db: &dyn DefDatabase, def: AttrDefId) -> Attrs {
|
329 |
| - let _p = tracing::span!(tracing::Level::INFO, "attrs_query").entered(); |
| 324 | + let _p = tracing::info_span!("attrs_query").entered(); |
330 | 325 | // FIXME: this should use `Trace` to avoid duplication in `source_map` below
|
331 | 326 | let raw_attrs = match def {
|
332 | 327 | AttrDefId::ModuleId(module) => {
|
@@ -646,3 +641,55 @@ pub(crate) fn fields_attrs_source_map(
|
646 | 641 |
|
647 | 642 | Arc::new(res)
|
648 | 643 | }
|
| 644 | + |
| 645 | +#[cfg(test)] |
| 646 | +mod tests { |
| 647 | + //! This module contains tests for doc-expression parsing. |
| 648 | + //! Currently, it tests `#[doc(hidden)]` and `#[doc(alias)]`. |
| 649 | +
|
| 650 | + use triomphe::Arc; |
| 651 | + |
| 652 | + use base_db::FileId; |
| 653 | + use hir_expand::span_map::{RealSpanMap, SpanMap}; |
| 654 | + use mbe::{syntax_node_to_token_tree, DocCommentDesugarMode}; |
| 655 | + use syntax::{ast, AstNode, TextRange}; |
| 656 | + |
| 657 | + use crate::attr::{DocAtom, DocExpr}; |
| 658 | + |
| 659 | + fn assert_parse_result(input: &str, expected: DocExpr) { |
| 660 | + let source_file = ast::SourceFile::parse(input, span::Edition::CURRENT).ok().unwrap(); |
| 661 | + let tt = source_file.syntax().descendants().find_map(ast::TokenTree::cast).unwrap(); |
| 662 | + let map = SpanMap::RealSpanMap(Arc::new(RealSpanMap::absolute(FileId::from_raw(0)))); |
| 663 | + let tt = syntax_node_to_token_tree( |
| 664 | + tt.syntax(), |
| 665 | + map.as_ref(), |
| 666 | + map.span_for_range(TextRange::empty(0.into())), |
| 667 | + DocCommentDesugarMode::ProcMacro, |
| 668 | + ); |
| 669 | + let cfg = DocExpr::parse(&tt); |
| 670 | + assert_eq!(cfg, expected); |
| 671 | + } |
| 672 | + |
| 673 | + #[test] |
| 674 | + fn test_doc_expr_parser() { |
| 675 | + assert_parse_result("#![doc(hidden)]", DocAtom::Flag("hidden".into()).into()); |
| 676 | + |
| 677 | + assert_parse_result( |
| 678 | + r#"#![doc(alias = "foo")]"#, |
| 679 | + DocAtom::KeyValue { key: "alias".into(), value: "foo".into() }.into(), |
| 680 | + ); |
| 681 | + |
| 682 | + assert_parse_result(r#"#![doc(alias("foo"))]"#, DocExpr::Alias(["foo".into()].into())); |
| 683 | + assert_parse_result( |
| 684 | + r#"#![doc(alias("foo", "bar", "baz"))]"#, |
| 685 | + DocExpr::Alias(["foo".into(), "bar".into(), "baz".into()].into()), |
| 686 | + ); |
| 687 | + |
| 688 | + assert_parse_result( |
| 689 | + r#" |
| 690 | + #[doc(alias("Bar", "Qux"))] |
| 691 | + struct Foo;"#, |
| 692 | + DocExpr::Alias(["Bar".into(), "Qux".into()].into()), |
| 693 | + ); |
| 694 | + } |
| 695 | +} |
0 commit comments