mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 04:08:19 +00:00
add tests for docs
This commit is contained in:
parent
899dbdd7ec
commit
98b454d1cf
1 changed files with 73 additions and 14 deletions
|
@ -346,23 +346,38 @@ mod tests {
|
|||
|
||||
use super::*;
|
||||
|
||||
fn completion_resp_to_labels(resp: CompletionResponse) -> Vec<String> {
|
||||
fn completion_resp_to_strings(
|
||||
resp: CompletionResponse,
|
||||
) -> Vec<(String, Option<Documentation>)> {
|
||||
match resp {
|
||||
CompletionResponse::Array(list) => list.into_iter(),
|
||||
CompletionResponse::List(list) => list.items.into_iter(),
|
||||
}
|
||||
.map(|item| item.label)
|
||||
.map(|item| (item.label, item.documentation))
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
///Gets completion and returns only the label for each completion
|
||||
async fn get_completion_labels(
|
||||
///Gets completion and returns only the label and docs for each completion
|
||||
async fn get_completion_strings(
|
||||
reg: &Registry,
|
||||
url: &Url,
|
||||
position: Position,
|
||||
) -> Option<Vec<String>> {
|
||||
) -> Option<Vec<(String, Option<Documentation>)>> {
|
||||
reg.completion_items(url, position)
|
||||
.await
|
||||
.map(completion_resp_to_labels)
|
||||
.map(completion_resp_to_strings)
|
||||
}
|
||||
|
||||
///Gets completion and returns only the label and docs for each completion
|
||||
fn comp_labels(
|
||||
completions: Option<Vec<(String, Option<Documentation>)>>,
|
||||
) -> Option<Vec<String>> {
|
||||
completions.map(|list| list.into_iter().map(|(labels, _)| labels).collect())
|
||||
}
|
||||
///Gets completion and returns only the label and docs for each completion
|
||||
fn comp_docs(
|
||||
completions: Option<Vec<(String, Option<Documentation>)>>,
|
||||
) -> Option<Vec<Option<Documentation>>> {
|
||||
completions.map(|list| list.into_iter().map(|(_, docs)| docs).collect())
|
||||
}
|
||||
|
||||
const DOC_LIT: &str = indoc! {r#"
|
||||
|
@ -391,7 +406,7 @@ mod tests {
|
|||
initial: &str,
|
||||
addition: &str,
|
||||
position: Position,
|
||||
) -> Option<std::vec::Vec<std::string::String>> {
|
||||
) -> Option<Vec<(String, Option<Documentation>)>> {
|
||||
let doc = DOC_LIT.to_string() + initial;
|
||||
let (inner, url) = test_setup(doc.clone()).await;
|
||||
let reg = &inner.registry;
|
||||
|
@ -401,7 +416,21 @@ mod tests {
|
|||
|
||||
inner.change(&url, change, 1).await.unwrap();
|
||||
|
||||
get_completion_labels(reg, &url, position).await
|
||||
get_completion_strings(reg, &url, position).await
|
||||
}
|
||||
async fn completion_test_labels(
|
||||
initial: &str,
|
||||
addition: &str,
|
||||
position: Position,
|
||||
) -> Option<Vec<String>> {
|
||||
comp_labels(completion_test(initial, addition, position).await)
|
||||
}
|
||||
async fn completion_test_docs(
|
||||
initial: &str,
|
||||
addition: &str,
|
||||
position: Position,
|
||||
) -> Option<Vec<Option<Documentation>>> {
|
||||
comp_docs(completion_test(initial, addition, position).await)
|
||||
}
|
||||
|
||||
///Test that completion works properly when we apply an "as" pattern to an identifier
|
||||
|
@ -419,11 +448,11 @@ mod tests {
|
|||
|
||||
let change = suffix.clone() + "o";
|
||||
inner.change(&url, change, 1).await.unwrap();
|
||||
let comp1 = get_completion_labels(reg, &url, position).await;
|
||||
let comp1 = comp_labels(get_completion_strings(reg, &url, position).await);
|
||||
|
||||
let c = suffix.clone() + "i";
|
||||
inner.change(&url, c, 2).await.unwrap();
|
||||
let comp2 = get_completion_labels(reg, &url, position).await;
|
||||
let comp2 = comp_labels(get_completion_strings(reg, &url, position).await);
|
||||
|
||||
let actual = [comp1, comp2];
|
||||
expect![[r#"
|
||||
|
@ -460,11 +489,11 @@ mod tests {
|
|||
|
||||
let change = doc.clone() + "o";
|
||||
inner.change(&url, change, 1).await.unwrap();
|
||||
let comp1 = get_completion_labels(reg, &url, position).await;
|
||||
let comp1 = comp_labels(get_completion_strings(reg, &url, position).await);
|
||||
|
||||
let c = doc.clone() + "t";
|
||||
inner.change(&url, c, 2).await.unwrap();
|
||||
let comp2 = get_completion_labels(reg, &url, position).await;
|
||||
let comp2 = comp_labels(get_completion_strings(reg, &url, position).await);
|
||||
let actual = [comp1, comp2];
|
||||
|
||||
expect![[r#"
|
||||
|
@ -490,7 +519,7 @@ mod tests {
|
|||
///Test that completion works properly when we apply an "as" pattern to a record
|
||||
#[tokio::test]
|
||||
async fn test_completion_fun_params() {
|
||||
let actual = completion_test(
|
||||
let actual = completion_test_labels(
|
||||
indoc! {r"
|
||||
main = \param1, param2 ->
|
||||
"},
|
||||
|
@ -511,7 +540,7 @@ mod tests {
|
|||
}
|
||||
#[tokio::test]
|
||||
async fn test_completion_closure() {
|
||||
let actual = completion_test(
|
||||
let actual = completion_test_labels(
|
||||
indoc! {r"
|
||||
main = [] |> List.map \ param1 , param2->
|
||||
"},
|
||||
|
@ -529,4 +558,34 @@ mod tests {
|
|||
"#]]
|
||||
.assert_debug_eq(&actual);
|
||||
}
|
||||
#[tokio::test]
|
||||
async fn test_completion_with_docs() {
|
||||
let actual = completion_test(
|
||||
indoc! {r"
|
||||
## This is the main function
|
||||
main = mai
|
||||
"},
|
||||
"par",
|
||||
Position::new(4, 10),
|
||||
)
|
||||
.await;
|
||||
expect![[r#"
|
||||
Some(
|
||||
[
|
||||
(
|
||||
"main",
|
||||
Some(
|
||||
MarkupContent(
|
||||
MarkupContent {
|
||||
kind: Markdown,
|
||||
value: "This is the main function",
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
"#]]
|
||||
.assert_debug_eq(&actual);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue