From 6e15ea193c2fb9fb4d4ac7aacb283f67d1e83c8b Mon Sep 17 00:00:00 2001 From: Akash Date: Tue, 10 Dec 2024 20:09:56 +0530 Subject: [PATCH] refactor: replace verbose completion tests with snapshot-based macro invocations Signed-off-by: Akash --- kclvm/tools/src/LSP/src/completion.rs | 1011 ++++++------------------- 1 file changed, 237 insertions(+), 774 deletions(-) diff --git a/kclvm/tools/src/LSP/src/completion.rs b/kclvm/tools/src/LSP/src/completion.rs index 83f763f09..2d5a2093f 100644 --- a/kclvm/tools/src/LSP/src/completion.rs +++ b/kclvm/tools/src/LSP/src/completion.rs @@ -984,780 +984,6 @@ mod tests { use lsp_types::{CompletionItem, CompletionItemKind, CompletionResponse, InsertTextFormat}; use proc_macro_crate::bench_test; - #[test] - #[bench_test] - fn var_completion_test() { - let (file, program, _, gs, schema_map) = - compile_test_file("src/test_data/completion_test/dot/completion/completion.k"); - - // test completion for var - let pos = KCLPos { - filename: file.to_owned(), - line: 26, - column: Some(1), - }; - - let tool = toolchain::default(); - let got = completion(None, &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let mut got_labels: Vec = match got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - - let mut expected_labels: Vec = vec![ - "", // generate from error recovery of "pkg." - "subpkg", - "math", - "Person", - "Person1{}", - "Person{}", - "P", - "P{}", - "p", - "p1", - "p2", - "p3", - "p4", - "aaaa", - "Config", - "Config{}", - "n", - ] - .iter() - .map(|s| s.to_string()) - .collect(); - - expected_labels.extend( - BUILTIN_FUNCTIONS - .iter() - .map(|(name, func)| func_ty_complete_label(name, &func.into_func_type())), - ); - got_labels.sort(); - expected_labels.sort(); - - assert_eq!(got_labels, expected_labels); - - // test completion for schema attr - let pos = KCLPos { - filename: file.to_owned(), - line: 24, - column: Some(4), - }; - - let got = completion(None, &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let mut got_labels: Vec = match got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - - expected_labels = ["", "age", "math", "name", "subpkg"] - .iter() - .map(|s| s.to_string()) - .collect(); - got_labels.sort(); - expected_labels.sort(); - assert_eq!(got_labels, expected_labels); - } - - #[test] - #[bench_test] - fn dot_completion_test() { - let (file, program, _, gs, schema_map) = - compile_test_file("src/test_data/completion_test/dot/completion/completion.k"); - - // test completion for schema attr - let pos = KCLPos { - filename: file.to_owned(), - line: 12, - column: Some(7), - }; - - let tool = toolchain::default(); - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - - let expected_labels: Vec<&str> = vec!["name", "age"]; - assert_eq!(got_labels, expected_labels); - - let pos = KCLPos { - filename: file.to_owned(), - line: 14, - column: Some(12), - }; - - // test completion for str builtin function - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match &got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - let expected_labels: Vec = STRING_MEMBER_FUNCTIONS - .iter() - .map(|(name, ty)| func_ty_complete_label(name, &ty.into_func_type())) - .collect(); - assert_eq!(got_labels, expected_labels); - - let got_insert_text: Vec = match &got { - CompletionResponse::Array(arr) => arr - .iter() - .map(|item| item.insert_text.clone().unwrap()) - .collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - let expected_insert_text: Vec = STRING_MEMBER_FUNCTIONS - .iter() - .map(|(name, ty)| func_ty_complete_insert_text(name, &ty.into_func_type())) - .collect(); - assert_eq!(got_insert_text, expected_insert_text); - - // test completion for import pkg path - let pos = KCLPos { - filename: file.to_owned(), - line: 1, - column: Some(12), - }; - - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - - let expected_labels: Vec<&str> = vec!["file1", "file2", "subpkg"]; - assert_eq!(got_labels, expected_labels); - - // test completion for import pkg' schema - let pos = KCLPos { - filename: file.to_owned(), - line: 16, - column: Some(12), - }; - - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - - let expected_labels: Vec<&str> = vec!["Person1"]; - assert_eq!(got_labels, expected_labels); - - let pos = KCLPos { - filename: file.to_owned(), - line: 19, - column: Some(5), - }; - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - let expected_labels: Vec = MATH_FUNCTION_TYPES - .iter() - .map(|(name, ty)| func_ty_complete_label(name, &ty.into_func_type())) - .collect(); - assert_eq!(got_labels, expected_labels); - - // test completion for literal str builtin function - let pos = KCLPos { - filename: file.clone(), - line: 21, - column: Some(4), - }; - - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - - let expected_labels: Vec = STRING_MEMBER_FUNCTIONS - .iter() - .map(|(name, ty)| func_ty_complete_label(name, &ty.into_func_type())) - .collect(); - assert_eq!(got_labels, expected_labels); - - let pos = KCLPos { - filename: file.clone(), - line: 30, - column: Some(11), - }; - - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - - let expected_labels: Vec<&str> = vec!["a"]; - assert_eq!(got_labels, expected_labels); - - // test completion for string union type - let pos = KCLPos { - filename: file.clone(), - line: 36, - column: Some(30), - }; - - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - - let expected_labels: Vec = STRING_MEMBER_FUNCTIONS - .iter() - .map(|(name, ty)| func_ty_complete_label(name, &ty.into_func_type())) - .collect(); - assert_eq!(got_labels, expected_labels); - } - - #[test] - #[bench_test] - fn dot_completion_test_without_dot() { - let (file, program, _, gs, schema_map) = - compile_test_file("src/test_data/completion_test/without_dot/completion.k"); - - // test completion for schema attr - let pos = KCLPos { - filename: file.to_owned(), - line: 12, - column: Some(7), - }; - - let tool = toolchain::default(); - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - - let expected_labels: Vec<&str> = vec!["name", "age"]; - assert_eq!(got_labels, expected_labels); - - let pos = KCLPos { - filename: file.to_owned(), - line: 14, - column: Some(12), - }; - - // test completion for str builtin function - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - let expected_labels: Vec = STRING_MEMBER_FUNCTIONS - .iter() - .map(|(name, ty)| func_ty_complete_label(name, &ty.into_func_type())) - .collect(); - assert_eq!(got_labels, expected_labels); - - // test completion for import pkg path - let pos = KCLPos { - filename: file.to_owned(), - line: 1, - column: Some(12), - }; - - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - - let expected_labels: Vec<&str> = vec!["file1", "file2", "subpkg"]; - assert_eq!(got_labels, expected_labels); - - // test completion for import pkg' schema - let pos = KCLPos { - filename: file.to_owned(), - line: 16, - column: Some(12), - }; - - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - - let expected_labels: Vec<&str> = vec!["Person1"]; - assert_eq!(got_labels, expected_labels); - - let pos = KCLPos { - filename: file.to_owned(), - line: 19, - column: Some(5), - }; - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match &got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - let expected_labels: Vec = MATH_FUNCTION_TYPES - .iter() - .map(|(name, ty)| func_ty_complete_label(name, &ty.into_func_type())) - .collect(); - assert_eq!(got_labels, expected_labels); - - let got_insert_text: Vec = match &got { - CompletionResponse::Array(arr) => arr - .iter() - .map(|item| item.insert_text.clone().unwrap()) - .collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - let expected_insert_text: Vec = MATH_FUNCTION_TYPES - .iter() - .map(|(name, ty)| func_ty_complete_insert_text(name, &ty.into_func_type())) - .collect(); - assert_eq!(got_insert_text, expected_insert_text); - - // test completion for literal str builtin function - let pos = KCLPos { - filename: file.clone(), - line: 21, - column: Some(4), - }; - - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match &got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - - let expected_labels: Vec = STRING_MEMBER_FUNCTIONS - .iter() - .map(|(name, ty)| func_ty_complete_label(name, &ty.into_func_type())) - .collect(); - assert_eq!(got_labels, expected_labels); - - let got_insert_text: Vec = match &got { - CompletionResponse::Array(arr) => arr - .iter() - .map(|item| item.insert_text.clone().unwrap()) - .collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - let expected_insert_text: Vec = STRING_MEMBER_FUNCTIONS - .iter() - .map(|(name, ty)| func_ty_complete_insert_text(name, &ty.into_func_type())) - .collect(); - assert_eq!(got_insert_text, expected_insert_text); - - let pos = KCLPos { - filename: file.clone(), - line: 30, - column: Some(11), - }; - - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - - let expected_labels: Vec<&str> = vec!["a"]; - assert_eq!(got_labels, expected_labels); - - // test completion for str union types - let pos = KCLPos { - filename: file.clone(), - line: 36, - column: Some(30), - }; - - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match &got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - - let expected_labels: Vec = STRING_MEMBER_FUNCTIONS - .iter() - .map(|(name, ty)| func_ty_complete_label(name, &ty.into_func_type())) - .collect(); - assert_eq!(got_labels, expected_labels); - - let got_insert_text: Vec = match &got { - CompletionResponse::Array(arr) => arr - .iter() - .map(|item| item.insert_text.clone().unwrap()) - .collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - let expected_insert_text: Vec = STRING_MEMBER_FUNCTIONS - .iter() - .map(|(name, ty)| func_ty_complete_insert_text(name, &ty.into_func_type())) - .collect(); - assert_eq!(got_insert_text, expected_insert_text); - } - - #[test] - #[bench_test] - fn import_builtin_package() { - let (file, program, _, gs, schema_map) = - compile_test_file("src/test_data/completion_test/import/builtin/builtin_pkg.k"); - let mut items: IndexSet = IndexSet::new(); - - // test completion for builtin packages - let pos = KCLPos { - filename: file.to_owned(), - line: 1, - column: Some(8), - }; - - let tool = toolchain::default(); - let got = completion(None, &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let _got_labels: Vec = match &got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - items.extend( - [ - "collection", - "net", - "manifests", - "math", - "datetime", - "regex", - "yaml", - "json", - "crypto", - "base64", - "units", - "file", - "template", - "runtime", - ] - .iter() - .map(|name| KCLCompletionItem { - label: name.to_string(), - kind: Some(KCLCompletionItemKind::Module), - detail: None, - documentation: None, - insert_text: None, - additional_text_edits: None, - }) - .collect::>(), - ); - let expect: CompletionResponse = into_completion_items(&items).into(); - assert_eq!(got, expect); - } - - #[test] - #[bench_test] - fn attr_value_completion() { - let (file, program, _, gs, schema_map) = - compile_test_file("src/test_data/completion_test/assign/completion.k"); - - let pos = KCLPos { - filename: file.to_owned(), - line: 14, - column: Some(6), - }; - - let tool = toolchain::default(); - let got = completion(Some(':'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - let expected_labels: Vec<&str> = vec![" True", " False"]; - assert_eq!(got_labels, expected_labels); - - let pos = KCLPos { - filename: file.to_owned(), - line: 16, - column: Some(6), - }; - let got = completion(Some(':'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - let expected_labels: Vec<&str> = vec![" \"abc\"", " \"def\""]; - assert_eq!(got_labels, expected_labels); - - let pos = KCLPos { - filename: file.to_owned(), - line: 18, - column: Some(6), - }; - let got = completion(Some(':'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - let expected_labels: Vec<&str> = vec![" []"]; - assert_eq!(got_labels, expected_labels); - - let pos = KCLPos { - filename: file.to_owned(), - line: 20, - column: Some(6), - }; - let got = completion(Some(':'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - let expected_labels: Vec<&str> = vec![" 1"]; - assert_eq!(got_labels, expected_labels); - - let pos = KCLPos { - filename: file.to_owned(), - line: 22, - column: Some(6), - }; - let got = completion(Some(':'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - let expected_labels: Vec<&str> = vec![" True"]; - assert_eq!(got_labels, expected_labels); - - let pos = KCLPos { - filename: file.to_owned(), - line: 24, - column: Some(6), - }; - let got = completion(Some(':'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - let expected_labels: Vec<&str> = vec![" {}"]; - assert_eq!(got_labels, expected_labels); - - let pos = KCLPos { - filename: file.to_owned(), - line: 26, - column: Some(6), - }; - let got = completion(Some(':'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match &got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - let expected_labels: Vec<&str> = vec![" sub.Person1{}"]; - assert_eq!(got_labels, expected_labels); - - let got_insert_test: Vec = match &got { - CompletionResponse::Array(arr) => arr - .iter() - .map(|item| item.clone().insert_text.unwrap().clone()) - .collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - let expected_insert_test: Vec<&str> = vec![" {$1}"]; - assert_eq!(got_insert_test, expected_insert_test); - } - - #[test] - #[bench_test] - fn schema_sig_completion() { - let (file, program, _, gs, schema_map) = - compile_test_file("src/test_data/completion_test/schema/schema/schema.k"); - - let pos = KCLPos { - filename: file.to_owned(), - line: 7, - column: Some(5), - }; - - let tool = toolchain::default(); - let mut got = completion(None, &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - match &mut got { - CompletionResponse::Array(arr) => { - assert_eq!( - arr.iter().find(|item| item.label == "Person(b){}").unwrap(), - &CompletionItem { - label: "Person(b){}".to_string(), - kind: Some(CompletionItemKind::CLASS), - detail: Some( - "__main__\n\nschema Person[b: int](Base):\nAttributes:\nc: int" - .to_string() - ), - documentation: Some(lsp_types::Documentation::String("".to_string())), - insert_text: Some("Person(${1:b}){$0}".to_string()), - insert_text_format: Some(InsertTextFormat::SNIPPET), - ..Default::default() - } - ) - } - CompletionResponse::List(_) => panic!("test failed"), - } - } - - #[test] - fn schema_docstring_newline_completion() { - let (file, program, _, gs, schema_map) = - compile_test_file("src/test_data/completion_test/newline/docstring_newline.k"); - - let pos = KCLPos { - filename: file.to_owned(), - line: 3, - column: Some(4), - }; - let tool = toolchain::default(); - let mut got = - completion(Some('\n'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - match &mut got { - CompletionResponse::Array(arr) => { - arr.sort_by(|a, b| a.label.cmp(&b.label)); - assert_eq!( - arr[0], - CompletionItem { - label: "\n\nAttributes\n----------\nname: \nworkloadType: \nreplica: \n\nExamples\n--------\n".to_string(), - detail: Some("generate docstring".to_string()), - kind: Some(CompletionItemKind::SNIPPET), - documentation: Some(lsp_types::Documentation::String("docstring for Server".to_string())), - ..Default::default() - } - ) - } - CompletionResponse::List(_) => panic!("test failed"), - } - } - - #[test] - fn str_dot_completion() { - let (file, program, _, gs, schema_map) = - compile_test_file("src/test_data/completion_test/dot/lit_str/lit_str.k"); - - // test complete str functions when at the end of literal str - let pos = KCLPos { - filename: file.to_owned(), - line: 1, - column: Some(10), - }; - - let tool = toolchain::default(); - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - - match &got { - CompletionResponse::Array(arr) => { - assert!(arr - .iter() - .all(|item| item.kind == Some(CompletionItemKind::FUNCTION))) - } - CompletionResponse::List(_) => panic!("test failed"), - }; - - let got_labels: Vec = match &got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - - let expected_labels: Vec = STRING_MEMBER_FUNCTIONS - .iter() - .map(|(name, ty)| func_ty_complete_label(name, &ty.into_func_type())) - .collect(); - assert_eq!(got_labels, expected_labels); - - let got_insert_text: Vec = match &got { - CompletionResponse::Array(arr) => arr - .iter() - .map(|item| item.insert_text.clone().unwrap()) - .collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - let expected_insert_text: Vec = STRING_MEMBER_FUNCTIONS - .iter() - .map(|(name, ty)| func_ty_complete_insert_text(name, &ty.into_func_type())) - .collect(); - assert_eq!(got_insert_text, expected_insert_text); - - let pos = KCLPos { - filename: file.to_owned(), - line: 2, - column: Some(6), - }; - - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - let got_labels: Vec = match got { - CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(), - CompletionResponse::List(_) => panic!("test failed"), - }; - assert_eq!(got_labels, expected_labels); - - // not complete inside literal str - let pos = KCLPos { - filename: file.to_owned(), - line: 2, - column: Some(5), - }; - - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - match got { - CompletionResponse::Array(arr) => assert!(arr.is_empty()), - CompletionResponse::List(_) => panic!("test failed"), - }; - - // not complete inside literal str - let pos = KCLPos { - filename: file.to_owned(), - line: 1, - column: Some(8), - }; - - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - match got { - CompletionResponse::Array(arr) => assert!(arr.is_empty()), - CompletionResponse::List(_) => panic!("test failed"), - }; - - let pos = KCLPos { - filename: file.to_owned(), - line: 3, - column: Some(2), - }; - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - match got { - CompletionResponse::Array(arr) => { - assert!(arr - .iter() - .all(|item| item.kind == Some(CompletionItemKind::FUNCTION))) - } - CompletionResponse::List(_) => panic!("test failed"), - }; - } - - #[test] - fn schema_ty_attr_complete() { - let (file, program, _, gs, schema_map) = - compile_test_file("src/test_data/completion_test/dot/schema_ty_attr/schema_ty_attr.k"); - - let pos = KCLPos { - filename: file.to_owned(), - line: 13, - column: Some(2), - }; - - let tool = toolchain::default(); - let got = completion(Some('.'), &program, &pos, &gs, &tool, None, &schema_map).unwrap(); - match got { - CompletionResponse::Array(arr) => { - assert_eq!( - arr[0], - CompletionItem { - label: "name".to_string(), - detail: Some("name: Name".to_string()), - kind: Some(CompletionItemKind::FIELD), - ..Default::default() - } - ) - } - CompletionResponse::List(_) => panic!("test failed"), - } - } - #[test] fn schema_end_pos() { let (file, program, _, gs, schema_map) = @@ -2145,6 +1371,243 @@ mod tests { }; } + completion_label_without_builtin_func_test_snapshot!( + var_completion_labels, + "src/test_data/completion_test/dot/completion/completion.k", + 26, + 1, + None + ); + + completion_label_test_snapshot!( + schema_attr_completion_labels, + "src/test_data/completion_test/dot/completion/completion.k", + 24, + 4, + None + ); + + completion_label_test_snapshot!( + dot_schema_attr_completion, + "src/test_data/completion_test/dot/completion/completion.k", + 12, + 7, + Some('.') + ); + + completion_label_test_snapshot!( + dot_str_builtin_func_completion, + "src/test_data/completion_test/dot/completion/completion.k", + 14, + 12, + Some('.') + ); + + completion_label_test_snapshot!( + import_pkg_path_completion, + "src/test_data/completion_test/dot/completion/completion.k", + 1, + 12, + Some('.') + ); + + completion_label_test_snapshot!( + import_pkg_schema_completion, + "src/test_data/completion_test/dot/completion/completion.k", + 16, + 12, + Some('.') + ); + + completion_label_test_snapshot!( + math_func_completion, + "src/test_data/completion_test/dot/completion/completion.k", + 19, + 5, + Some('.') + ); + + completion_label_test_snapshot!( + literal_str_builtin_func_completion, + "src/test_data/completion_test/dot/completion/completion.k", + 21, + 4, + Some('.') + ); + + completion_label_test_snapshot!( + single_schema_attr_completion, + "src/test_data/completion_test/dot/completion/completion.k", + 30, + 11, + Some('.') + ); + + completion_label_test_snapshot!( + string_union_type_completion, + "src/test_data/completion_test/dot/completion/completion.k", + 36, + 30, + Some('.') + ); + + completion_label_without_builtin_func_test_snapshot!( + var_completion_labels_without_dot, + "src/test_data/completion_test/without_dot/completion.k", + 26, + 1, + None + ); + + completion_label_without_system_pkg_test_snapshot!( + system_pkg_labels, + "src/test_data/completion_test/without_dot/completion.k", + 36, + 5, + Some('.') + ); + + completion_label_test_snapshot!( + basic_completion_labels, + "src/test_data/completion_test/without_dot/completion.k", + 12, + 7, + Some('.') + ); + + completion_label_test_snapshot!( + import_builtin_package_test, + "src/test_data/completion_test/import/builtin/builtin_pkg.k", + 1, + 8, + None + ); + + completion_label_test_snapshot!( + attr_value_completion_true_false, + "src/test_data/completion_test/assign/completion.k", + 14, + 6, + Some(':') + ); + + completion_label_test_snapshot!( + attr_value_completion_strings, + "src/test_data/completion_test/assign/completion.k", + 16, + 6, + Some(':') + ); + + completion_label_test_snapshot!( + attr_value_completion_list, + "src/test_data/completion_test/assign/completion.k", + 18, + 6, + Some(':') + ); + + completion_label_test_snapshot!( + attr_value_completion_integer, + "src/test_data/completion_test/assign/completion.k", + 20, + 6, + Some(':') + ); + + completion_label_test_snapshot!( + attr_value_completion_boolean, + "src/test_data/completion_test/assign/completion.k", + 22, + 6, + Some(':') + ); + + completion_label_test_snapshot!( + attr_value_completion_dict, + "src/test_data/completion_test/assign/completion.k", + 24, + 6, + Some(':') + ); + + completion_label_test_snapshot!( + attr_value_completion_schema, + "src/test_data/completion_test/assign/completion.k", + 26, + 6, + Some(':') + ); + + completion_label_test_snapshot!( + schema_sig_completion_test, + "src/test_data/completion_test/schema/schema/schema.k", + 7, + 5, + None + ); + + completion_label_test_snapshot!( + schema_docstring_newline_test, + "src/test_data/completion_test/newline/docstring_newline.k", + 3, + 4, + Some('\n') + ); + + completion_label_test_snapshot!( + str_dot_completion_test_end_of_literal, + "src/test_data/completion_test/dot/lit_str/lit_str.k", + 1, + 10, + Some('.') + ); + + completion_label_test_snapshot!( + str_dot_completion_test_second_line_end, + "src/test_data/completion_test/dot/lit_str/lit_str.k", + 2, + 6, + Some('.') + ); + + completion_label_test_snapshot!( + str_dot_completion_test_inside_literal_1, + "src/test_data/completion_test/dot/lit_str/lit_str.k", + 2, + 5, + Some('.') + ); + + completion_label_test_snapshot!( + str_dot_completion_test_inside_literal_2, + "src/test_data/completion_test/dot/lit_str/lit_str.k", + 1, + 8, + Some('.') + ); + + completion_label_test_snapshot!( + str_dot_completion_test_third_line, + "src/test_data/completion_test/dot/lit_str/lit_str.k", + 3, + 2, + Some('.') + ); + + completion_label_test_snapshot!( + schema_ty_attr_complete_test, + "src/test_data/completion_test/dot/schema_ty_attr/schema_ty_attr.k", + 13, + 2, + Some('.') + ); + + + + + + completion_label_without_builtin_func_test_snapshot!( lambda_1, "src/test_data/completion_test/lambda/lambda_1/lambda_1.k",