Skip to content

Commit

Permalink
test: fix lsp test and add import_pkg hover test case (#976)
Browse files Browse the repository at this point in the history
Signed-off-by: he1pa <[email protected]>
  • Loading branch information
He1pa authored Jan 10, 2024
1 parent 3bd2f23 commit 36c49bc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
24 changes: 24 additions & 0 deletions kclvm/tools/src/LSP/src/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,28 @@ mod tests {
_ => unreachable!("test error"),
}
}

#[test]
#[bench_test]
fn import_pkg_hover() {
let (file, program, _, _, gs) = compile_test_file("src/test_data/hover_test/import_pkg.k");
let pos = KCLPos {
filename: file.clone(),
line: 3,
column: Some(7),
};
let got = hover(&program, &pos, &gs).unwrap();
match got.contents {
lsp_types::HoverContents::Array(vec) => {
assert_eq!(vec.len(), 2);
if let MarkedString::String(s) = vec[0].clone() {
assert_eq!(s, "fib\n\nschema Fib");
}
if let MarkedString::String(s) = vec[1].clone() {
assert_eq!(s, "Attributes:\n\nn: int\n\nvalue: int");
}
}
_ => unreachable!("test error"),
}
}
}
3 changes: 3 additions & 0 deletions kclvm/tools/src/LSP/src/test_data/hover_test/import_pkg.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import .fib

fib.Fib{}
3 changes: 2 additions & 1 deletion kclvm/tools/src/LSP/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ use std::time::Duration;
use kclvm_ast::ast::Program;
use kclvm_error::Diagnostic as KCLDiagnostic;
use kclvm_error::Position as KCLPos;
use kclvm_parser::KCLModuleCache;
use kclvm_sema::resolver::scope::ProgramScope;

use lsp_types::Diagnostic;
Expand Down Expand Up @@ -125,7 +126,7 @@ pub(crate) fn compile_test_file(
let (program, prog_scope, diags, gs) = parse_param_and_compile(
Param {
file: file.clone(),
module_cache: None,
module_cache: Some(KCLModuleCache::default()),
},
Some(Arc::new(RwLock::new(Default::default()))),
)
Expand Down

0 comments on commit 36c49bc

Please sign in to comment.