Skip to content

Commit

Permalink
feat: add more test cases for goto def with dependencies whose names …
Browse files Browse the repository at this point in the history
…contain underline (#965)

Signed-off-by: zongz <zongzhe1024@163.com>
  • Loading branch information
zong-zhe authored Dec 25, 2023
1 parent 981243a commit 793f549
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "dep-with-line"
edition = "0.0.1"
version = "0.0.1"

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The_first_kcl_program = 'Hello World dep-with-line!'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "main_pkg"
edition = "0.0.1"
version = "0.0.1"

[dependencies]
dep-with-line = { path = "../dep-with-line" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[dependencies]
[dependencies.dep-with-line]
name = "dep-with-line"
full_name = "dep-with-line_"
sum = "O2Z1djaB1lC38kNfhwUUYAlqGKE7seUqqys3DPcJfEw="
path = "../dep-with-line"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import dep_with_line as dwl

The_first_kcl_program = dwl.The_first_kcl_program
33 changes: 33 additions & 0 deletions kclvm/driver/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,39 @@ fn test_parse_key_value_pair_fail() {
assert!(parse_key_value_pair(case).is_err());
}
}
#[test]
fn test_fill_pkg_maps_for_k_file_with_line() {
let root_path = PathBuf::from(".")
.join("src")
.join("test_data")
.join("kpm_metadata_with_line");

let main_pkg_path = root_path.join("main_pkg").join("main.k");
let dep_with_line_path = root_path.join("dep-with-line");

let mut opts = LoadProgramOptions::default();
assert_eq!(format!("{:?}", opts.package_maps), "{}");

let res = fill_pkg_maps_for_k_file(main_pkg_path.clone(), &mut opts);
assert!(res.is_ok());

let pkg_maps = opts.package_maps.clone();
assert_eq!(pkg_maps.len(), 1);
assert!(pkg_maps.get("dep_with_line").is_some());

assert_eq!(
PathBuf::from(pkg_maps.get("dep_with_line").unwrap().clone())
.canonicalize()
.unwrap()
.display()
.to_string(),
dep_with_line_path
.canonicalize()
.unwrap()
.display()
.to_string()
);
}

fn test_fill_pkg_maps_for_k_file() {
let path = PathBuf::from(".")
Expand Down
31 changes: 31 additions & 0 deletions kclvm/tools/src/LSP/src/goto_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,37 @@ mod tests {
use proc_macro_crate::bench_test;
use std::path::PathBuf;

#[test]
#[bench_test]
fn goto_import_pkg_with_line_test() {
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let (file, program, _, _, gs) =
compile_test_file("src/test_data/goto_def_with_line_test/main_pkg/main.k");
let pos = KCLPos {
filename: file,
line: 1,
column: Some(15),
};

let res = goto_definition_with_gs(&program, &pos, &gs);

match res.unwrap() {
lsp_types::GotoDefinitionResponse::Scalar(loc) => {
let got_path = file_path_from_url(&loc.uri).unwrap();
let expected_path = path
.join("src/test_data/goto_def_with_line_test/dep-with-line/main.k")
.canonicalize()
.unwrap()
.display()
.to_string();
assert_eq!(got_path, expected_path)
}
_ => {
unreachable!("test error")
}
}
}

#[test]
#[bench_test]
fn goto_import_pkg_test() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "dep-with-line"
edition = "0.0.1"
version = "0.0.1"

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The_first_kcl_program = 'Hello World aa!'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "b"
edition = "0.0.1"
version = "0.0.1"

[dependencies]
dep-with-line = { path = "../dep-with-line" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[dependencies]
[dependencies.dep-with-line]
name = "dep-with-line"
full_name = "dep-with-line_"
sum = "O2Z1djaB1lC38kNfhwUUYAlqGKE7seUqqys3DPcJfEw="
path = "../dep-with-line"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import dep_with_line as dwl

The_first_kcl_program = dwl.The_first_kcl_program

0 comments on commit 793f549

Please sign in to comment.