Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

completion test for string union type #1408

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 54 additions & 3 deletions kclvm/tools/src/LSP/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ mod tests {
let mut expected_labels: Vec<String> = vec![
"", // generate from error recovery of "pkg."
"subpkg", "math", "Person", "Person{}", "P", "P{}", "p", "p1", "p2", "p3", "p4",
"aaaa",
"aaaa", "Config", "Config{}", "n",
]
.iter()
.map(|s| s.to_string())
Expand Down Expand Up @@ -939,7 +939,7 @@ mod tests {
assert_eq!(got_labels, expected_labels);

let pos = KCLPos {
filename: file,
filename: file.clone(),
line: 30,
column: Some(11),
};
Expand All @@ -952,6 +952,25 @@ mod tests {

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).unwrap();
let got_labels: Vec<String> = match got {
CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(),
CompletionResponse::List(_) => panic!("test failed"),
};

let expected_labels: Vec<String> = STRING_MEMBER_FUNCTIONS
.iter()
.map(|(name, ty)| func_ty_complete_label(name, &ty.into_func_type()))
.collect();
assert_eq!(got_labels, expected_labels);
}

#[test]
Expand Down Expand Up @@ -1089,7 +1108,7 @@ mod tests {
assert_eq!(got_insert_text, expected_insert_text);

let pos = KCLPos {
filename: file,
filename: file.clone(),
line: 30,
column: Some(11),
};
Expand All @@ -1102,6 +1121,38 @@ mod tests {

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).unwrap();
let got_labels: Vec<String> = match &got {
CompletionResponse::Array(arr) => arr.iter().map(|item| item.label.clone()).collect(),
CompletionResponse::List(_) => panic!("test failed"),
};

let expected_labels: Vec<String> = 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<String> = 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> = 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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ schema P:
a: int = 1

aaaa = P{}.

schema Config:
containerRuntime?: "runc" | "rund"

n = Config {
containerRuntime = "runc".
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ schema P:
a: int = 1

aaaa = P{}

schema Config:
containerRuntime?: "runc" | "rund"

n = Config {
containerRuntime = "runc"
}
Loading