aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/tests/heavy_tests/support.rs
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2018-12-06 20:07:31 +0000
committerFlorian Diebold <[email protected]>2018-12-06 20:32:15 +0000
commit1dfd06fc8aadd5d621112716fe0e59aed5dfc767 (patch)
treeed92a2a5c5f3666cd68b04abc653fe455f83d49e /crates/ra_lsp_server/tests/heavy_tests/support.rs
parent8e60e751cbcfa47c7bed788dfe2ab5cebfcb78b3 (diff)
Use json comparison code from cargo for heavy tests
Diffstat (limited to 'crates/ra_lsp_server/tests/heavy_tests/support.rs')
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/support.rs27
1 files changed, 14 insertions, 13 deletions
diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs
index 019048a3a..4b75be3ee 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/support.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs
@@ -15,9 +15,9 @@ use languageserver_types::{
15 DidOpenTextDocumentParams, TextDocumentIdentifier, TextDocumentItem, Url, 15 DidOpenTextDocumentParams, TextDocumentIdentifier, TextDocumentItem, Url,
16}; 16};
17use serde::Serialize; 17use serde::Serialize;
18use serde_json::{from_str, to_string_pretty, Value}; 18use serde_json::{to_string_pretty, Value};
19use tempdir::TempDir; 19use tempdir::TempDir;
20use test_utils::parse_fixture; 20use test_utils::{parse_fixture, find_mismatch};
21 21
22use ra_lsp_server::{ 22use ra_lsp_server::{
23 main_loop, req, 23 main_loop, req,
@@ -88,23 +88,24 @@ impl Server {
88 } 88 }
89 } 89 }
90 90
91 pub fn request<R>(&self, params: R::Params, expected_resp: &str) 91 pub fn request<R>(&self, params: R::Params, expected_resp: Value)
92 where 92 where
93 R: Request, 93 R: Request,
94 R::Params: Serialize, 94 R::Params: Serialize,
95 { 95 {
96 let id = self.req_id.get(); 96 let id = self.req_id.get();
97 self.req_id.set(id + 1); 97 self.req_id.set(id + 1);
98 let expected_resp: Value = from_str(expected_resp).unwrap();
99 let actual = self.send_request::<R>(id, params); 98 let actual = self.send_request::<R>(id, params);
100 assert_eq!( 99 match find_mismatch(&expected_resp, &actual) {
101 expected_resp, 100 Some((expected_part, actual_part)) => panic!(
102 actual, 101 "JSON mismatch\nExpected:\n{}\nWas:\n{}\nExpected part:\n{}\nActual part:\n{}\n",
103 "Expected:\n{}\n\ 102 to_string_pretty(&expected_resp).unwrap(),
104 Actual:\n{}\n", 103 to_string_pretty(&actual).unwrap(),
105 to_string_pretty(&expected_resp).unwrap(), 104 to_string_pretty(expected_part).unwrap(),
106 to_string_pretty(&actual).unwrap(), 105 to_string_pretty(actual_part).unwrap(),
107 ); 106 ),
107 None => {}
108 }
108 } 109 }
109 110
110 fn send_request<R>(&self, id: u64, params: R::Params) -> Value 111 fn send_request<R>(&self, id: u64, params: R::Params) -> Value
@@ -139,7 +140,7 @@ impl Server {
139 pub fn wait_for_feedback_n(&self, feedback: &str, n: usize) { 140 pub fn wait_for_feedback_n(&self, feedback: &str, n: usize) {
140 let f = |msg: &RawMessage| match msg { 141 let f = |msg: &RawMessage| match msg {
141 RawMessage::Notification(n) if n.method == "internalFeedback" => { 142 RawMessage::Notification(n) if n.method == "internalFeedback" => {
142 return n.clone().cast::<req::InternalFeedback>().unwrap() == feedback 143 return n.clone().cast::<req::InternalFeedback>().unwrap() == feedback;
143 } 144 }
144 _ => false, 145 _ => false,
145 }; 146 };