From f0bf82669c266d975254b0f5fc5aaffa181beae9 Mon Sep 17 00:00:00 2001 From: Piotr Figiela <77412592+Draggu@users.noreply.github.com> Date: Mon, 13 Jan 2025 13:37:58 +0100 Subject: [PATCH] Use const `cairo_project.toml` where possible (#163) --- tests/e2e/analysis.rs | 6 ++-- tests/e2e/completions.rs | 3 +- tests/e2e/goto_definition.rs | 10 ++----- tests/e2e/hover.rs | 3 +- tests/e2e/macro_expand.rs | 3 +- tests/e2e/references.rs | 3 +- tests/e2e/semantic_tokens.rs | 9 ++---- tests/e2e/support/cairo_project_toml.rs | 27 ++++++++++++++++++ tests/e2e/support/mod.rs | 1 + tests/e2e/workspace_configuration.rs | 7 ++--- .../completions/methods_text_edits.txt | 14 ---------- tests/test_data/completions/module_items.txt | 7 ----- tests/test_data/completions/structs.txt | 7 ----- tests/test_data/hover/basic.txt | 15 +++------- tests/test_data/hover/literals.txt | 7 ----- tests/test_data/hover/missing_module.txt | 7 ----- tests/test_data/hover/partial.txt | 7 ----- tests/test_data/hover/paths.txt | 7 ----- tests/test_data/hover/starknet.txt | 7 ----- tests/test_data/hover/structs.txt | 7 ----- tests/test_data/hover/variables.txt | 7 ----- tests/test_data/macro_expand/attribute.txt | 7 ----- tests/test_data/macro_expand/derive.txt | 7 ----- tests/test_data/macro_expand/empty.txt | 7 ----- .../test_data/macro_expand/simple_inline.txt | 7 ----- tests/test_data/references/fns.txt | 28 ------------------- 26 files changed, 48 insertions(+), 172 deletions(-) create mode 100644 tests/e2e/support/cairo_project_toml.rs diff --git a/tests/e2e/analysis.rs b/tests/e2e/analysis.rs index 7f1aa402..f464be5d 100644 --- a/tests/e2e/analysis.rs +++ b/tests/e2e/analysis.rs @@ -3,6 +3,7 @@ use indoc::indoc; use lsp_types::{ExecuteCommandParams, lsp_request}; use pretty_assertions::assert_eq; +use crate::support::cairo_project_toml::CAIRO_PROJECT_TOML; use crate::support::normalize::normalize; use crate::support::sandbox; @@ -110,10 +111,7 @@ fn cairo_projects() { fn test_reload() { let mut ls = sandbox! { files { - "cairo_project.toml" => indoc! {r#" - [crate_roots] - hello = "src" - "#}, + "cairo_project.toml" => CAIRO_PROJECT_TOML, "src/lib.cairo" => "fn main() {}", } }; diff --git a/tests/e2e/completions.rs b/tests/e2e/completions.rs index 7392f1a2..31cb4efa 100644 --- a/tests/e2e/completions.rs +++ b/tests/e2e/completions.rs @@ -2,6 +2,7 @@ use cairo_lang_test_utils::parse_test_file::TestRunnerResult; use cairo_lang_utils::ordered_hash_map::OrderedHashMap; use lsp_types::{CompletionParams, TextDocumentPositionParams, lsp_request}; +use crate::support::cairo_project_toml::CAIRO_PROJECT_TOML_2024_07; use crate::support::cursor::peek_caret; use crate::support::{cursors, sandbox}; @@ -38,7 +39,7 @@ fn test_completions_text_edits( let mut ls = sandbox! { files { - "cairo_project.toml" => inputs["cairo_project.toml"].clone(), + "cairo_project.toml" => CAIRO_PROJECT_TOML_2024_07, "src/lib.cairo" => cairo.clone(), } }; diff --git a/tests/e2e/goto_definition.rs b/tests/e2e/goto_definition.rs index 355398d6..30f811e3 100644 --- a/tests/e2e/goto_definition.rs +++ b/tests/e2e/goto_definition.rs @@ -1,11 +1,11 @@ use cairo_lang_test_utils::parse_test_file::TestRunnerResult; use cairo_lang_utils::ordered_hash_map::OrderedHashMap; -use indoc::indoc; use lsp_types::{ ClientCapabilities, GotoCapability, GotoDefinitionParams, GotoDefinitionResponse, TextDocumentClientCapabilities, TextDocumentPositionParams, lsp_request, }; +use crate::support::cairo_project_toml::CAIRO_PROJECT_TOML_2024_07; use crate::support::cursor::{peek_caret, peek_selection}; use crate::support::{cursors, sandbox}; @@ -46,13 +46,7 @@ fn test_goto_definition( let mut ls = sandbox! { files { - "cairo_project.toml" => indoc! {r#" - [crate_roots] - hello = "src" - - [config.global] - edition = "2024_07" - "#}, + "cairo_project.toml" => CAIRO_PROJECT_TOML_2024_07, "src/lib.cairo" => cairo.clone(), } client_capabilities = caps; diff --git a/tests/e2e/hover.rs b/tests/e2e/hover.rs index d8d2c511..20c82f51 100644 --- a/tests/e2e/hover.rs +++ b/tests/e2e/hover.rs @@ -5,6 +5,7 @@ use lsp_types::{ MarkupKind, TextDocumentClientCapabilities, TextDocumentPositionParams, lsp_request, }; +use crate::support::cairo_project_toml::CAIRO_PROJECT_TOML_2023_11; use crate::support::cursor::{peek_caret, peek_selection}; use crate::support::{cursors, sandbox}; @@ -53,7 +54,7 @@ fn test_hover( let mut ls = sandbox! { files { - "cairo_project.toml" => inputs["cairo_project.toml"].clone(), + "cairo_project.toml" => CAIRO_PROJECT_TOML_2023_11, "src/lib.cairo" => cairo.clone(), } client_capabilities = caps; diff --git a/tests/e2e/macro_expand.rs b/tests/e2e/macro_expand.rs index 73a7bff1..410f2f76 100644 --- a/tests/e2e/macro_expand.rs +++ b/tests/e2e/macro_expand.rs @@ -3,6 +3,7 @@ use cairo_lang_utils::ordered_hash_map::OrderedHashMap; use cairo_language_server::lsp::ext::ExpandMacro; use lsp_types::{TextDocumentIdentifier, TextDocumentPositionParams}; +use crate::support::cairo_project_toml::CAIRO_PROJECT_TOML_2024_07; use crate::support::cursor::peek_caret; use crate::support::{cursors, sandbox}; @@ -26,7 +27,7 @@ fn test_macro_expand( let mut ls = sandbox! { files { - "cairo_project.toml" => inputs["cairo_project.toml"].clone(), + "cairo_project.toml" => CAIRO_PROJECT_TOML_2024_07, "src/lib.cairo" => cairo.clone(), } }; diff --git a/tests/e2e/references.rs b/tests/e2e/references.rs index 0a3b14da..f7fda71e 100644 --- a/tests/e2e/references.rs +++ b/tests/e2e/references.rs @@ -5,6 +5,7 @@ use lsp_types::{ TextDocumentClientCapabilities, TextDocumentPositionParams, lsp_request, }; +use crate::support::cairo_project_toml::CAIRO_PROJECT_TOML_2024_07; use crate::support::cursor::{peek_caret, peek_selection}; use crate::support::{cursors, sandbox}; @@ -37,7 +38,7 @@ fn test_references( let mut ls = sandbox! { files { - "cairo_project.toml" => inputs["cairo_project.toml"].clone(), + "cairo_project.toml" => CAIRO_PROJECT_TOML_2024_07, "src/lib.cairo" => cairo.clone(), } client_capabilities = caps; diff --git a/tests/e2e/semantic_tokens.rs b/tests/e2e/semantic_tokens.rs index f77b3ef4..e76ca3a8 100644 --- a/tests/e2e/semantic_tokens.rs +++ b/tests/e2e/semantic_tokens.rs @@ -1,5 +1,6 @@ use lsp_types::lsp_request; +use crate::support::cairo_project_toml::CAIRO_PROJECT_TOML_2023_11; use crate::support::sandbox; fn caps(base: lsp_types::ClientCapabilities) -> lsp_types::ClientCapabilities { @@ -25,13 +26,7 @@ fn caps(base: lsp_types::ClientCapabilities) -> lsp_types::ClientCapabilities { fn highlights_multiline_tokens() { let mut ls = sandbox! { files { - "cairo_project.toml" => r#" -[crate_roots] -hello = "src" - -[config.global] -edition = "2023_11" -"#, + "cairo_project.toml" => CAIRO_PROJECT_TOML_2023_11, "src/lib.cairo" => r#" fn main() { let _ = " diff --git a/tests/e2e/support/cairo_project_toml.rs b/tests/e2e/support/cairo_project_toml.rs new file mode 100644 index 00000000..b5e1c984 --- /dev/null +++ b/tests/e2e/support/cairo_project_toml.rs @@ -0,0 +1,27 @@ +use indoc::indoc; + +pub const CAIRO_PROJECT_TOML: &str = indoc!( + r#" + [crate_roots] + hello = "src" + "# +); + +pub const CAIRO_PROJECT_TOML_2024_07: &str = indoc!( + r#" + [crate_roots] + hello = "src" + + [config.global] + edition = "2024_07" + "# +); +pub const CAIRO_PROJECT_TOML_2023_11: &str = indoc!( + r#" + [crate_roots] + hello = "src" + + [config.global] + edition = "2023_11" + "# +); diff --git a/tests/e2e/support/mod.rs b/tests/e2e/support/mod.rs index d2139ddf..3ba83acb 100644 --- a/tests/e2e/support/mod.rs +++ b/tests/e2e/support/mod.rs @@ -1,3 +1,4 @@ +pub mod cairo_project_toml; pub mod client_capabilities; pub mod cursor; pub mod fixture; diff --git a/tests/e2e/workspace_configuration.rs b/tests/e2e/workspace_configuration.rs index 117234d2..9db2ec08 100644 --- a/tests/e2e/workspace_configuration.rs +++ b/tests/e2e/workspace_configuration.rs @@ -1,9 +1,9 @@ -use indoc::indoc; use lsp_server::Message; use lsp_types::lsp_request; use lsp_types::request::Request as _; use serde_json::json; +use crate::support::cairo_project_toml::CAIRO_PROJECT_TOML; use crate::support::sandbox; use crate::support::scarb::scarb_core_path; @@ -28,10 +28,7 @@ fn relative_path_to_core() { let mut ls = sandbox! { files { - "cairo_project.toml" => indoc! {r#" - [crate_roots] - hello = "src" - "#}, + "cairo_project.toml" => CAIRO_PROJECT_TOML, "src/lib.cairo" => r#"fn main() -> u8 { 42 }"#, } workspace_configuration = json!({ diff --git a/tests/test_data/completions/methods_text_edits.txt b/tests/test_data/completions/methods_text_edits.txt index 47072631..dcf36dc4 100644 --- a/tests/test_data/completions/methods_text_edits.txt +++ b/tests/test_data/completions/methods_text_edits.txt @@ -3,13 +3,6 @@ //! > test_runner_name test_completions_text_edits(edit: true, insert: true) -//! > cairo_project.toml -[crate_roots] -hello = "src" - -[config.global] -edition = "2024_07" - //! > cairo_code mod hidden_trait { pub trait ATrait1 { @@ -141,13 +134,6 @@ Text edit: use super::ATrait1; //! > test_runner_name test_completions_text_edits(edit: true, insert: true) -//! > cairo_project.toml -[crate_roots] -hello = "src" - -[config.global] -edition = "2024_07" - //! > cairo_code mod hidden_trait { diff --git a/tests/test_data/completions/module_items.txt b/tests/test_data/completions/module_items.txt index 8704e4c1..d951496e 100644 --- a/tests/test_data/completions/module_items.txt +++ b/tests/test_data/completions/module_items.txt @@ -3,13 +3,6 @@ //! > test_runner_name test_completions_text_edits -//! > cairo_project.toml -[crate_roots] -hello = "src" - -[config.global] -edition = "2024_07" - //! > cairo_code mod helper_module { pub trait Trait1 { diff --git a/tests/test_data/completions/structs.txt b/tests/test_data/completions/structs.txt index f7aeab48..9da649cc 100644 --- a/tests/test_data/completions/structs.txt +++ b/tests/test_data/completions/structs.txt @@ -3,13 +3,6 @@ //! > test_runner_name test_completions_text_edits(detail: true) -//! > cairo_project.toml -[crate_roots] -hello = "src" - -[config.global] -edition = "2024_07" - //! > cairo_code mod some_module { pub struct Struct { diff --git a/tests/test_data/hover/basic.txt b/tests/test_data/hover/basic.txt index 52117fa5..89b6b30c 100644 --- a/tests/test_data/hover/basic.txt +++ b/tests/test_data/hover/basic.txt @@ -3,13 +3,6 @@ //! > test_runner_name test_hover -//! > cairo_project.toml -[crate_roots] -hello = "src" - -[config.global] -edition = "2023_11" - //! > cairo_code fn main() { let mut x = 5; @@ -23,9 +16,9 @@ fn main() { } /// `add_two` documentation. -fn add_two(x: u32) -> u32 { +fn add_two(x: u32) -> u32 { //! Adds 2 to an unsigned argument. - x + 2 + x + 2 } /// Rectangle struct. @@ -283,9 +276,9 @@ Calculate the area of the rectangle. //! > hover #14 // = source context -fn add_two(x: u32) -> u32 { +fn add_two(x: u32) -> u32 { // = highlight -fn add_two(x: u32) -> u32 { +fn add_two(x: u32) -> u32 { // = popover ```cairo hello diff --git a/tests/test_data/hover/literals.txt b/tests/test_data/hover/literals.txt index 93e4f5cd..fcd82428 100644 --- a/tests/test_data/hover/literals.txt +++ b/tests/test_data/hover/literals.txt @@ -3,13 +3,6 @@ //! > test_runner_name test_hover -//! > cairo_project.toml -[crate_roots] -hello = "src" - -[config.global] -edition = "2023_11" - //! > cairo_code const SOME_CONST: felt252 = 0x123; const WRONG_TYPE_CONST: u8 = 123_felt252; diff --git a/tests/test_data/hover/missing_module.txt b/tests/test_data/hover/missing_module.txt index 9e113f68..2f8fdb29 100644 --- a/tests/test_data/hover/missing_module.txt +++ b/tests/test_data/hover/missing_module.txt @@ -3,13 +3,6 @@ //! > test_runner_name test_hover -//! > cairo_project.toml -[crate_roots] -hello = "src" - -[config.global] -edition = "2023_11" - //! > cairo_code mod missing; diff --git a/tests/test_data/hover/partial.txt b/tests/test_data/hover/partial.txt index c543e7ab..97d3dc77 100644 --- a/tests/test_data/hover/partial.txt +++ b/tests/test_data/hover/partial.txt @@ -3,13 +3,6 @@ //! > test_runner_name test_hover -//! > cairo_project.toml -[crate_roots] -hello = "src" - -[config.global] -edition = "2023_11" - //! > cairo_code fn main() { let mut xyz = unknown_function(); diff --git a/tests/test_data/hover/paths.txt b/tests/test_data/hover/paths.txt index 994677ba..00e5d62f 100644 --- a/tests/test_data/hover/paths.txt +++ b/tests/test_data/hover/paths.txt @@ -3,13 +3,6 @@ //! > test_runner_name test_hover -//! > cairo_project.toml -[crate_roots] -hello = "src" - -[config.global] -edition = "2023_11" - //! > cairo_code /// some_module docstring. mod some_module { diff --git a/tests/test_data/hover/starknet.txt b/tests/test_data/hover/starknet.txt index 075e5648..21bc3260 100644 --- a/tests/test_data/hover/starknet.txt +++ b/tests/test_data/hover/starknet.txt @@ -3,13 +3,6 @@ //! > test_runner_name test_hover -//! > cairo_project.toml -[crate_roots] -hello = "src" - -[config.global] -edition = "2023_11" - //! > cairo_code use Balance::contract_state_for_testing; diff --git a/tests/test_data/hover/structs.txt b/tests/test_data/hover/structs.txt index a8b88c2c..33b46246 100644 --- a/tests/test_data/hover/structs.txt +++ b/tests/test_data/hover/structs.txt @@ -3,13 +3,6 @@ //! > test_runner_name test_hover -//! > cairo_project.toml -[crate_roots] -hello = "src" - -[config.global] -edition = "2023_11" - //! > cairo_code /// Docstring of Struct. struct Struct { diff --git a/tests/test_data/hover/variables.txt b/tests/test_data/hover/variables.txt index 73855b4f..d93c2582 100644 --- a/tests/test_data/hover/variables.txt +++ b/tests/test_data/hover/variables.txt @@ -3,13 +3,6 @@ //! > test_runner_name test_hover -//! > cairo_project.toml -[crate_roots] -hello = "src" - -[config.global] -edition = "2023_11" - //! > cairo_code fn main() { let abc: felt252 = 0; diff --git a/tests/test_data/macro_expand/attribute.txt b/tests/test_data/macro_expand/attribute.txt index f4f5bb1a..ddc0c2e1 100644 --- a/tests/test_data/macro_expand/attribute.txt +++ b/tests/test_data/macro_expand/attribute.txt @@ -3,13 +3,6 @@ //! > test_runner_name test_macro_expand -//! > cairo_project.toml -[crate_roots] -hello = "src" - -[config.global] -edition = "2024_07" - //! > cairo_code struct A { a: felt252 diff --git a/tests/test_data/macro_expand/derive.txt b/tests/test_data/macro_expand/derive.txt index 0bb27eb9..4d690645 100644 --- a/tests/test_data/macro_expand/derive.txt +++ b/tests/test_data/macro_expand/derive.txt @@ -3,13 +3,6 @@ //! > test_runner_name test_macro_expand -//! > cairo_project.toml -[crate_roots] -hello = "src" - -[config.global] -edition = "2024_07" - //! > cairo_code #[derive(Drop, Serde)] struct A { diff --git a/tests/test_data/macro_expand/empty.txt b/tests/test_data/macro_expand/empty.txt index f7bcdb0c..0e3d78cd 100644 --- a/tests/test_data/macro_expand/empty.txt +++ b/tests/test_data/macro_expand/empty.txt @@ -3,13 +3,6 @@ //! > test_runner_name test_macro_expand -//! > cairo_project.toml -[crate_roots] -hello = "src" - -[config.global] -edition = "2024_07" - //! > cairo_code fn main() -> u32 { // comments diff --git a/tests/test_data/macro_expand/simple_inline.txt b/tests/test_data/macro_expand/simple_inline.txt index c4011376..5aeaf2bb 100644 --- a/tests/test_data/macro_expand/simple_inline.txt +++ b/tests/test_data/macro_expand/simple_inline.txt @@ -3,13 +3,6 @@ //! > test_runner_name test_macro_expand -//! > cairo_project.toml -[crate_roots] -hello = "src" - -[config.global] -edition = "2024_07" - //! > cairo_code fn fib(mut n: u32) -> u32 { println!("some text"); diff --git a/tests/test_data/references/fns.txt b/tests/test_data/references/fns.txt index c34414a0..77667690 100644 --- a/tests/test_data/references/fns.txt +++ b/tests/test_data/references/fns.txt @@ -3,13 +3,6 @@ //! > test_runner_name test_references(include_declaration: false) -//! > cairo_project.toml -[crate_roots] -hello = "src" - -[config.global] -edition = "2024_07" - //! > cairo_code fn pow2(x: felt252) -> felt252 { x * x } @@ -32,13 +25,6 @@ fn pow2(x: felt252) -> felt252 { x * x } //! > test_runner_name test_references(include_declaration: true) -//! > cairo_project.toml -[crate_roots] -hello = "src" - -[config.global] -edition = "2024_07" - //! > cairo_code fn pow2(x: felt252) -> felt252 { x * x } @@ -63,13 +49,6 @@ fn pow2(x: felt252) -> felt252 { x * x } //! > test_runner_name test_references(include_declaration: false) -//! > cairo_project.toml -[crate_roots] -hello = "src" - -[config.global] -edition = "2024_07" - //! > cairo_code fn pow2(x: felt252) -> felt252 { x * x } @@ -89,13 +68,6 @@ fn pow2(x: felt252) -> felt252 { x * x } //! > test_runner_name test_references(include_declaration: false) -//! > cairo_project.toml -[crate_roots] -hello = "src" - -[config.global] -edition = "2024_07" - //! > cairo_code fn pow2(x: felt252) -> felt252 { x * x }