5323: Rewrite item_tree tests to expect r=matklad a=matklad

insta review wouldn't update the test, so ...



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-07-11 20:13:07 +00:00 committed by GitHub
commit 2653440f1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 117 additions and 110 deletions

1
Cargo.lock generated
View file

@ -1059,6 +1059,7 @@ dependencies = [
"anymap",
"drop_bomb",
"either",
"expect",
"fst",
"indexmap",
"insta",

View file

@ -33,3 +33,4 @@ tt = { path = "../ra_tt", package = "ra_tt" }
[dev-dependencies]
insta = "0.16.0"
expect = { path = "../expect" }

View file

@ -546,6 +546,7 @@ impl Ctx {
let id: ModItem = match item {
ast::ExternItem::FnDef(ast) => {
let func = self.lower_function(&ast)?;
self.data().functions[func.index].is_unsafe = true;
func.into()
}
ast::ExternItem::StaticDef(ast) => {

View file

@ -1,13 +1,15 @@
use super::{ItemTree, ModItem, ModKind};
use crate::{db::DefDatabase, test_db::TestDB};
use expect::{expect, Expect};
use hir_expand::{db::AstDatabase, HirFileId, InFile};
use insta::assert_snapshot;
use ra_db::fixture::WithFixture;
use ra_syntax::{ast, AstNode};
use rustc_hash::FxHashSet;
use std::sync::Arc;
use stdx::format_to;
use crate::{db::DefDatabase, test_db::TestDB};
use super::{ItemTree, ModItem, ModKind};
fn test_inner_items(ra_fixture: &str) {
let (db, file_id) = TestDB::with_single_file(ra_fixture);
let file_id = HirFileId::from(file_id);
@ -162,9 +164,15 @@ fn fmt_mod_item(out: &mut String, tree: &ItemTree, item: ModItem) {
}
}
fn check(ra_fixture: &str, expect: Expect) {
let actual = print_item_tree(ra_fixture);
expect.assert_eq(&actual);
}
#[test]
fn smoke() {
assert_snapshot!(print_item_tree(r"
check(
r"
#![attr]
#[attr_on_use]
@ -214,7 +222,8 @@ fn smoke() {
#[union_fld]
fld: u16,
}
"), @r###"
",
expect![[r##"
inner attrs: Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr"))] }, input: None }]) }
top-level items:
@ -244,12 +253,13 @@ Struct { name: Name(Text("Struct2")), visibility: RawVisibilityId("pub(self)"),
Enum { name: Name(Text("En")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), variants: IdRange::<ra_hir_def::item_tree::Variant>(0..1), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::EnumDef>(6) }
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("un"))] }, input: None }]) }]
Union { name: Name(Text("Un")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), fields: Record(IdRange::<ra_hir_def::item_tree::Field>(3..4)), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::UnionDef>(7) }
"###);
"##]],
);
}
#[test]
fn simple_inner_items() {
let tree = print_item_tree(
check(
r"
impl<T:A> D for Response<T> {
fn foo() {
@ -260,9 +270,7 @@ fn simple_inner_items() {
}
}
",
);
assert_snapshot!(tree, @r###"
expect![[r#"
inner attrs: Attrs { entries: None }
top-level items:
@ -274,12 +282,13 @@ inner items:
for AST FileAstId::<ra_syntax::ast::generated::nodes::ModuleItem>(2):
Function { name: Name(Text("end")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(1), has_self_param: false, is_unsafe: false, params: [], ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(2) }
"###);
"#]],
);
}
#[test]
fn extern_attrs() {
let tree = print_item_tree(
check(
r#"
#[block_attr]
extern "C" {
@ -289,22 +298,21 @@ fn extern_attrs() {
fn b() {}
}
"#,
);
assert_snapshot!(tree, @r###"
expect![[r##"
inner attrs: Attrs { entries: None }
top-level items:
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }, Attr { path: ModPath { kind: Plain, segments: [Name(Text("block_attr"))] }, input: None }]) }]
Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(1) }
Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: true, params: [], ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(1) }
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }, Attr { path: ModPath { kind: Plain, segments: [Name(Text("block_attr"))] }, input: None }]) }]
Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(2) }
"###);
Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: true, params: [], ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(2) }
"##]],
);
}
#[test]
fn trait_attrs() {
let tree = print_item_tree(
check(
r#"
#[trait_attr]
trait Tr {
@ -314,9 +322,7 @@ fn trait_attrs() {
fn b() {}
}
"#,
);
assert_snapshot!(tree, @r###"
expect![[r##"
inner attrs: Attrs { entries: None }
top-level items:
@ -326,12 +332,13 @@ Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generi
> Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(1) }
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }]) }]
> Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(2) }
"###);
"##]],
);
}
#[test]
fn impl_attrs() {
let tree = print_item_tree(
check(
r#"
#[impl_attr]
impl Ty {
@ -341,9 +348,7 @@ fn impl_attrs() {
fn b() {}
}
"#,
);
assert_snapshot!(tree, @r###"
expect![[r##"
inner attrs: Attrs { entries: None }
top-level items:
@ -353,7 +358,8 @@ Impl { generic_params: GenericParamsId(4294967295), target_trait: None, target_t
> Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(1) }
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }]) }]
> Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(2) }
"###);
"##]],
);
}
#[test]
@ -391,16 +397,14 @@ fn cursed_inner_items() {
#[test]
fn inner_item_attrs() {
let tree = print_item_tree(
check(
r"
fn foo() {
#[on_inner]
fn inner() {}
}
",
);
assert_snapshot!(tree, @r###"
expect![[r##"
inner attrs: Attrs { entries: None }
top-level items:
@ -412,24 +416,24 @@ for AST FileAstId::<ra_syntax::ast::generated::nodes::ModuleItem>(1):
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_inner"))] }, input: None }]) }]
Function { name: Name(Text("inner")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(1) }
"###);
"##]],
);
}
#[test]
fn assoc_item_macros() {
let tree = print_item_tree(
check(
r"
impl S {
items!();
}
",
);
assert_snapshot!(tree, @r###"
expect![[r#"
inner attrs: Attrs { entries: None }
top-level items:
Impl { generic_params: GenericParamsId(4294967295), target_trait: None, target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("S"))] }, generic_args: [None] }), is_negative: false, items: [MacroCall(Idx::<MacroCall>(0))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::ImplDef>(0) }
> MacroCall { name: None, path: ModPath { kind: Plain, segments: [Name(Text("items"))] }, is_export: false, is_local_inner: false, is_builtin: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::MacroCall>(1) }
"###);
"#]],
);
}