mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 11:20:54 +00:00
fine grained on typed tests
This commit is contained in:
parent
d9e70e3160
commit
a1b661faec
@ -133,12 +133,18 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_on_eq_typed() {
|
fn test_on_eq_typed() {
|
||||||
fn do_check(before: &str, after: &str) {
|
fn type_eq(before: &str, after: &str) {
|
||||||
let (offset, before) = extract_offset(before);
|
let (offset, before) = extract_offset(before);
|
||||||
|
let mut edit = TextEditBuilder::default();
|
||||||
|
edit.insert(offset, "=".to_string());
|
||||||
|
let before = edit.finish().apply(&before);
|
||||||
let file = SourceFile::parse(&before);
|
let file = SourceFile::parse(&before);
|
||||||
let result = on_eq_typed(&file, offset).unwrap();
|
if let Some(result) = on_eq_typed(&file, offset) {
|
||||||
let actual = result.edit.apply(&before);
|
let actual = result.edit.apply(&before);
|
||||||
assert_eq_text!(after, &actual);
|
assert_eq_text!(after, &actual);
|
||||||
|
} else {
|
||||||
|
assert_eq_text!(&before, after)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// do_check(r"
|
// do_check(r"
|
||||||
@ -150,10 +156,10 @@ mod tests {
|
|||||||
// let foo =;
|
// let foo =;
|
||||||
// }
|
// }
|
||||||
// ");
|
// ");
|
||||||
do_check(
|
type_eq(
|
||||||
r"
|
r"
|
||||||
fn foo() {
|
fn foo() {
|
||||||
let foo <|>= 1 + 1
|
let foo <|> 1 + 1
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
r"
|
r"
|
||||||
@ -175,24 +181,27 @@ fn foo() {
|
|||||||
// ");
|
// ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn type_dot(before: &str, after: &str) {
|
||||||
|
let (offset, before) = extract_offset(before);
|
||||||
|
let mut edit = TextEditBuilder::default();
|
||||||
|
edit.insert(offset, ".".to_string());
|
||||||
|
let before = edit.finish().apply(&before);
|
||||||
|
let file = SourceFile::parse(&before);
|
||||||
|
if let Some(result) = on_dot_typed(&file, offset) {
|
||||||
|
let actual = result.edit.apply(&before);
|
||||||
|
assert_eq_text!(after, &actual);
|
||||||
|
} else {
|
||||||
|
assert_eq_text!(&before, after)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_on_dot_typed() {
|
fn indents_new_chain_call() {
|
||||||
fn do_check(before: &str, after: &str) {
|
type_dot(
|
||||||
let (offset, before) = extract_offset(before);
|
|
||||||
let file = SourceFile::parse(&before);
|
|
||||||
if let Some(result) = on_dot_typed(&file, offset) {
|
|
||||||
let actual = result.edit.apply(&before);
|
|
||||||
assert_eq_text!(after, &actual);
|
|
||||||
} else {
|
|
||||||
assert_eq_text!(&before, after)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
// indent if continuing chain call
|
|
||||||
do_check(
|
|
||||||
r"
|
r"
|
||||||
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
|
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
|
||||||
self.child_impl(db, name)
|
self.child_impl(db, name)
|
||||||
<|>.
|
<|>
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
r"
|
r"
|
||||||
@ -202,13 +211,11 @@ fn foo() {
|
|||||||
}
|
}
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
|
type_dot(
|
||||||
// do not indent if already indented
|
|
||||||
do_check(
|
|
||||||
r"
|
r"
|
||||||
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
|
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
|
||||||
self.child_impl(db, name)
|
self.child_impl(db, name)
|
||||||
<|>.
|
<|>
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
r"
|
r"
|
||||||
@ -217,15 +224,17 @@ fn foo() {
|
|||||||
.
|
.
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
);
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// indent if the previous line is already indented
|
#[test]
|
||||||
do_check(
|
fn indents_continued_chain_call() {
|
||||||
|
type_dot(
|
||||||
r"
|
r"
|
||||||
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
|
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
|
||||||
self.child_impl(db, name)
|
self.child_impl(db, name)
|
||||||
.first()
|
.first()
|
||||||
<|>.
|
<|>
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
r"
|
r"
|
||||||
@ -236,14 +245,12 @@ fn foo() {
|
|||||||
}
|
}
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
|
type_dot(
|
||||||
// don't indent if indent matches previous line
|
|
||||||
do_check(
|
|
||||||
r"
|
r"
|
||||||
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
|
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
|
||||||
self.child_impl(db, name)
|
self.child_impl(db, name)
|
||||||
.first()
|
.first()
|
||||||
<|>.
|
<|>
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
r"
|
r"
|
||||||
@ -254,12 +261,14 @@ fn foo() {
|
|||||||
}
|
}
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// don't indent if there is no method call on previous line
|
#[test]
|
||||||
do_check(
|
fn dont_indent_freestanding_dot() {
|
||||||
|
type_dot(
|
||||||
r"
|
r"
|
||||||
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
|
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
|
||||||
<|>.
|
<|>
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
r"
|
r"
|
||||||
@ -268,19 +277,15 @@ fn foo() {
|
|||||||
}
|
}
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
|
type_dot(
|
||||||
// indent to match previous expr
|
|
||||||
do_check(
|
|
||||||
r"
|
r"
|
||||||
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
|
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
|
||||||
self.child_impl(db, name)
|
<|>
|
||||||
<|>.
|
}
|
||||||
}
|
|
||||||
",
|
",
|
||||||
r"
|
r"
|
||||||
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
|
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
|
||||||
self.child_impl(db, name)
|
.
|
||||||
.
|
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user