Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit b8655b6

Browse files
committed
Implement testcase for find impls
1 parent d417558 commit b8655b6

File tree

5 files changed

+97
-0
lines changed

5 files changed

+97
-0
lines changed

src/server.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ pub fn server_failure(id: jsonrpc::Id, error: jsonrpc::Error) -> jsonrpc::Failur
3636
#[allow(non_upper_case_globals)]
3737
pub const REQUEST__Deglob: &'static str = "rustWorkspace/deglob";
3838

39+
#[cfg(test)]
40+
#[allow(non_upper_case_globals)]
41+
pub const REQUEST__FindImpls: &'static str = "rustDocument/implementations";
42+
43+
3944
#[derive(Debug, Serialize)]
4045
pub struct Ack;
4146

src/test/mod.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,3 +581,62 @@ fn test_parse_error_on_malformed_input() {
581581

582582
assert!(failure.error.code == jsonrpc_core::ErrorCode::ParseError);
583583
}
584+
585+
#[test]
586+
fn test_find_impls() {
587+
let (mut cache, _tc) = init_env("find_impls");
588+
589+
let source_file_path = Path::new("src").join("main.rs");
590+
591+
let root_path = cache.abs_path(Path::new("."));
592+
let url = Url::from_file_path(cache.abs_path(&source_file_path))
593+
.expect("couldn't convert file path to URL");
594+
595+
let messages = vec![
596+
ServerMessage::initialize(0,root_path.as_os_str().to_str().map(|x| x.to_owned())),
597+
ServerMessage::request(1, Method::FindImpls(TextDocumentPositionParams {
598+
text_document: TextDocumentIdentifier::new(url.clone()),
599+
position: cache.mk_ls_position(src(&source_file_path, 13, "Bar"))
600+
})),
601+
ServerMessage::request(2, Method::FindImpls(TextDocumentPositionParams {
602+
text_document: TextDocumentIdentifier::new(url.clone()),
603+
position: cache.mk_ls_position(src(&source_file_path, 16, "Super"))
604+
})),
605+
ServerMessage::request(3, Method::FindImpls(TextDocumentPositionParams {
606+
text_document: TextDocumentIdentifier::new(url),
607+
position: cache.mk_ls_position(src(&source_file_path, 20, "Eq"))
608+
})),
609+
];
610+
611+
let (mut server, results) = mock_server(messages);
612+
// Initialise and build.
613+
assert_eq!(ls_server::LsService::handle_message(&mut server),
614+
ls_server::ServerStateChange::Continue);
615+
expect_messages(results.clone(),
616+
&[ExpectedMessage::new(Some(0)).expect_contains("capabilities"),
617+
ExpectedMessage::new(None).expect_contains("diagnosticsBegin"),
618+
ExpectedMessage::new(None).expect_contains("diagnosticsEnd")]);
619+
620+
assert_eq!(ls_server::LsService::handle_message(&mut server),
621+
ls_server::ServerStateChange::Continue);
622+
// TODO structural checking of result, rather than looking for a string - src(&source_file_path, 12, "world")
623+
expect_messages(results.clone(), &[
624+
ExpectedMessage::new(Some(1))
625+
.expect_contains(r#""range":{"start":{"line":18,"character":15},"end":{"line":18,"character":18}}"#)
626+
.expect_contains(r#""range":{"start":{"line":19,"character":12},"end":{"line":19,"character":15}}"#)
627+
]);
628+
assert_eq!(ls_server::LsService::handle_message(&mut server),
629+
ls_server::ServerStateChange::Continue);
630+
expect_messages(results.clone(), &[
631+
ExpectedMessage::new(Some(2))
632+
.expect_contains(r#""range":{"start":{"line":18,"character":15},"end":{"line":18,"character":18}}"#)
633+
.expect_contains(r#""range":{"start":{"line":22,"character":15},"end":{"line":22,"character":18}}"#)
634+
]);
635+
assert_eq!(ls_server::LsService::handle_message(&mut server),
636+
ls_server::ServerStateChange::Continue);
637+
expect_messages(results.clone(), &[
638+
// TODO assert that only one position is returned
639+
ExpectedMessage::new(Some(3))
640+
.expect_contains(r#""range":{"start":{"line":19,"character":12},"end":{"line":19,"character":15}}"#)
641+
]);
642+
}

test_data/find_impls/Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test_data/find_impls/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "find_impls"
3+
version = "0.1.0"
4+
authors = ["Jonas Bushart <[email protected]>"]
5+
6+
[dependencies]

test_data/find_impls/src/main.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
#![allow(dead_code)]
11+
12+
#[derive(PartialEq)]
13+
struct Bar;
14+
struct Foo;
15+
16+
trait Super{}
17+
trait Sub: Super {}
18+
19+
impl Super for Bar {}
20+
impl Eq for Bar {}
21+
22+
impl Sub for Foo {}
23+
impl Super for Foo {}

0 commit comments

Comments
 (0)