Skip to content

Commit

Permalink
Use const cairo_project.toml where possible (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
Draggu authored Jan 13, 2025
1 parent 822cd16 commit f0bf826
Show file tree
Hide file tree
Showing 26 changed files with 48 additions and 172 deletions.
6 changes: 2 additions & 4 deletions tests/e2e/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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() {}",
}
};
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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(),
}
};
Expand Down
10 changes: 2 additions & 8 deletions tests/e2e/goto_definition.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/macro_expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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(),
}
};
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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;
Expand Down
9 changes: 2 additions & 7 deletions tests/e2e/semantic_tokens.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 _ = "
Expand Down
27 changes: 27 additions & 0 deletions tests/e2e/support/cairo_project_toml.rs
Original file line number Diff line number Diff line change
@@ -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"
"#
);
1 change: 1 addition & 0 deletions tests/e2e/support/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod cairo_project_toml;
pub mod client_capabilities;
pub mod cursor;
pub mod fixture;
Expand Down
7 changes: 2 additions & 5 deletions tests/e2e/workspace_configuration.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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!({
Expand Down
14 changes: 0 additions & 14 deletions tests/test_data/completions/methods_text_edits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
Expand Down Expand Up @@ -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 {

Expand Down
7 changes: 0 additions & 7 deletions tests/test_data/completions/module_items.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
Expand Down
7 changes: 0 additions & 7 deletions tests/test_data/completions/structs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 4 additions & 11 deletions tests/test_data/hover/basic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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<caret> = 5;
Expand All @@ -23,9 +16,9 @@ fn main() {
}

/// `add_two` documentation.
fn add_t<caret>wo(x: u32) -> u32 {
fn add_t<caret>wo(x: u32) -> u32 {
//! Adds 2 to an unsigned argument.
x + 2
x + 2
}

/// Rectangle struct.
Expand Down Expand Up @@ -283,9 +276,9 @@ Calculate the area of the rectangle.

//! > hover #14
// = source context
fn add_t<caret>wo(x: u32) -> u32 {
fn add_t<caret>wo(x: u32) -> u32 {
// = highlight
fn <sel>add_two</sel>(x: u32) -> u32 {
fn <sel>add_two</sel>(x: u32) -> u32 {
// = popover
```cairo
hello
Expand Down
7 changes: 0 additions & 7 deletions tests/test_data/hover/literals.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 0x<caret>123;
const WRONG_TYPE_CONST: u8 = 123_<caret>felt252;
Expand Down
7 changes: 0 additions & 7 deletions tests/test_data/hover/missing_module.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
//! > test_runner_name
test_hover

//! > cairo_project.toml
[crate_roots]
hello = "src"

[config.global]
edition = "2023_11"

//! > cairo_code
m<caret>od<caret> mis<caret>sing;

Expand Down
7 changes: 0 additions & 7 deletions tests/test_data/hover/partial.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 xy<caret>z = unkn<caret>own_function();
Expand Down
7 changes: 0 additions & 7 deletions tests/test_data/hover/paths.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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_<caret>module {
Expand Down
7 changes: 0 additions & 7 deletions tests/test_data/hover/starknet.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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::contr<caret>act_state_for_testing;

Expand Down
7 changes: 0 additions & 7 deletions tests/test_data/hover/structs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 0 additions & 7 deletions tests/test_data/hover/variables.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ab<caret>c: felt252 = 0;
Expand Down
7 changes: 0 additions & 7 deletions tests/test_data/macro_expand/attribute.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit f0bf826

Please sign in to comment.