Skip to content

Commit

Permalink
Add a test for warning class
Browse files Browse the repository at this point in the history
Signed-off-by: Ramona Łuczkiewicz <[email protected]>
  • Loading branch information
Ramona Łuczkiewicz authored and ramonacat committed Dec 21, 2022
1 parent 533f880 commit 5643b98
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 8 deletions.
71 changes: 69 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tremor-script = { version = "0.13.0-rc.11", features = [
"arena-delete",
"allow-non-simd",
] }
tracing-subscriber="0.3.16"

[dev-dependencies]
tower-test = "0.4.0"
Expand Down
74 changes: 74 additions & 0 deletions src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ impl LanguageServer for Backend {

async fn initialized(&self, _: InitializedParams) {
file_dbg("initialized", "initialized");

// TODO check this from clients
//self.client.show_message(MessageType::Info, "Initialized Trill!").await;
self.client
Expand Down Expand Up @@ -357,6 +358,7 @@ pub(crate) fn file_dbg(name: &str, content: &str) {

#[cfg(test)]
mod tests {
use async_std::prelude::{FutureExt, StreamExt};
use serde_json::json;
use tower::Service;
use tower_lsp::jsonrpc::{Id, Request};
Expand Down Expand Up @@ -405,4 +407,76 @@ mod tests {
);
Ok(())
}

#[async_std::test]
async fn warning_class() {
tracing_subscriber::fmt::init();

let lang = language::lookup("tremor-deploy").unwrap();
let (mut service, mut socket) = LspService::new(|client| Backend::new(client, lang));

let join_handle = async_std::task::spawn(async move {
while let Some(x) = socket.next().await {
if x.method() == "textDocument/publishDiagnostics" {
let params = x.params();

if let Some(params) = params {
let message = params.get("diagnostics").unwrap().as_array().unwrap()[0]
.get("message")
.unwrap()
.as_str()
.unwrap()
.to_string();

return Some(message);
}
}
}

return None;
});

let initialize_req = Request::build("initialize")
.params(json!({"capabilities":{
"textDocument": {
"synchronization": {
"dynamicRegistration": true,
}
}}}))
.id(1)
.finish();

let _initialize_res = service
.call(initialize_req)
.await
.expect("Expect request to be executed");

let initialized_req = Request::build("initialized").params(json!({})).finish();
let _initialized_res = service
.call(initialized_req)
.await
.expect("Expect request to be executed");

let req = Request::build("textDocument/didOpen")
.params(json!({"textDocument": {
"uri": format!("file://{}/{}", env!("CARGO_MANIFEST_DIR"), "tests/warning_class.tremor"),
"languageId": "tremor-deploy",
"version": 1,
"text": ""
}}))
.finish();
let _res = service
.call(req)
.await
.expect("Expect request to be executed");

let result = join_handle.timeout(std::time::Duration::from_secs(5)).await;

assert_eq!(
result,
Ok(Some(
"consistency: const's are canonically written in UPPER_CASE".to_string()
))
);
}
}
7 changes: 1 addition & 6 deletions src/lsp_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,9 @@ pub(crate) fn get_token(tokens: &[language::TokenSpan], position: Position) -> O
let line = position.line as usize;
let column = position.character as usize;

//file_dbg("get_token_location_line", &location.line.to_string());
//file_dbg("get_token_location_column", &location.column.to_string());

let mut token = None;
for (i, t) in tokens.iter().enumerate() {
if t.span.end().line() == line && t.span.end().column() > column {
//file_dbg("get_token_span_end", &token.span.end.line.to_string());
//file_dbg("get_token_location_end", &location.line.to_string());
file_dbg("get_token_t_value", &t.value.to_string());

token = match t.value {
Expand Down Expand Up @@ -87,6 +82,6 @@ pub(crate) fn get_token(tokens: &[language::TokenSpan], position: Position) -> O
break;
}
}
//file_dbg("get_token_return", &token.clone().unwrap_or_default());

token
}
11 changes: 11 additions & 0 deletions tests/warning_class.tremor
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
define flow test
flow
define pipeline test_pline
pipeline
define script test_scr
script
const a = "";
end
end

end

0 comments on commit 5643b98

Please sign in to comment.