-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LS: Add first tests for the new project model
commit-id:7caaac0c
- Loading branch information
Showing
13 changed files
with
179 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//! This module contains definitions of custom methods (aka requests or notifications) for the | ||
//! Language Server Protocol that are provided by the Cairo Language Server. | ||
|
||
use tower_lsp::lsp_types::request::Request; | ||
|
||
#[cfg(feature = "testing")] | ||
pub mod test { | ||
use super::*; | ||
|
||
pub struct DebugProjects; | ||
impl Request for DebugProjects { | ||
type Params = (); | ||
type Result = String; | ||
const METHOD: &'static str = "test/debugProjects"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod client_capabilities; | ||
pub(crate) mod client_capabilities; | ||
pub mod methods; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod hover; | ||
mod project; | ||
mod semantic_tokens; | ||
mod support; | ||
mod workspace_configuration; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use cairo_lang_language_server::lsp; | ||
use indoc::indoc; | ||
|
||
use crate::support::normalize::assert_normalized_eq; | ||
use crate::support::sandbox; | ||
|
||
#[test] | ||
fn cairo_projects() { | ||
let mut ls = sandbox! { | ||
files { | ||
"project1/cairo_project.toml" => indoc! {r#" | ||
[crate_roots] | ||
project1 = "src" | ||
[config.global] | ||
edition = "2023_11" | ||
"#}, | ||
"project1/src/lib.cairo" => r#"fn main() {}"#, | ||
|
||
"project2/cairo_project.toml" => indoc! {r#" | ||
[crate_roots] | ||
project2 = "src" | ||
[config.global] | ||
edition = "2023_11" | ||
"#}, | ||
"project2/src/lib.cairo" => r#"fn main() {}"#, | ||
|
||
"project2/subproject/cairo_project.toml" => indoc! {r#" | ||
[crate_roots] | ||
subproject = "src" | ||
[config.global] | ||
edition = "2023_11" | ||
"#}, | ||
"project2/subproject/src/lib.cairo" => r#"fn main() {}"#, | ||
} | ||
}; | ||
|
||
ls.open_and_wait_for_diagnostics("project1/src/lib.cairo"); | ||
ls.open_and_wait_for_diagnostics("project2/src/lib.cairo"); | ||
ls.open_and_wait_for_diagnostics("project2/subproject/src/lib.cairo"); | ||
|
||
let projects = ls.send_request::<lsp::methods::test::DebugProjects>(()); | ||
assert_normalized_eq!( | ||
&ls, | ||
projects, | ||
indoc! {r#"[ | ||
CairoProject { | ||
project_path: "[ROOT]/project2/subproject/cairo_project.toml", | ||
}, | ||
CairoProject { | ||
project_path: "[ROOT]/project2/cairo_project.toml", | ||
}, | ||
CairoProject { | ||
project_path: "[ROOT]/project1/cairo_project.toml", | ||
}, | ||
]"#} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
crates/cairo-lang-language-server/tests/e2e/support/normalize.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use std::path::Path; | ||
|
||
use crate::support::fixture::Fixture; | ||
|
||
/// Like [`assert_eq`], but performs normalization of the left side. | ||
macro_rules! assert_normalized_eq { | ||
($fixture:expr, $actual:expr, $expected:expr $(,)?) => { | ||
assert_eq!($crate::support::normalize::normalize($fixture, $actual), $expected,); | ||
}; | ||
} | ||
|
||
pub(crate) use assert_normalized_eq; | ||
|
||
/// Performs various normalization steps of the input data, to remove any runtime-specific artifacts | ||
/// and make comparisons in test assertions deterministic. | ||
pub fn normalize(fixture: impl AsRef<Fixture>, data: impl ToString) -> String { | ||
return inner(fixture.as_ref(), data.to_string()); | ||
|
||
fn inner(fixture: &Fixture, data: String) -> String { | ||
normalize_well_known_paths(fixture, normalize_paths(data)) | ||
} | ||
} | ||
|
||
/// Replace all well-known paths/urls for a fixture with placeholders. | ||
fn normalize_well_known_paths(fixture: &Fixture, data: String) -> String { | ||
let mut data = data | ||
.replace(&fixture.root_url().to_string(), "[ROOT_URL]") | ||
.replace(&normalize_path(fixture.root_path()), "[ROOT]"); | ||
|
||
if let Ok(pwd) = std::env::current_dir() { | ||
data = data.replace(&normalize_path(&pwd), "[PWD]"); | ||
} | ||
|
||
data | ||
} | ||
|
||
/// Normalizes path separators. | ||
fn normalize_paths(data: String) -> String { | ||
data.replace('\\', "/") | ||
} | ||
|
||
/// Normalize a path to a consistent format. | ||
fn normalize_path(path: &Path) -> String { | ||
normalize_paths(path.to_string_lossy().to_string()) | ||
} |