Skip to content

Commit

Permalink
Add test case for scope completion
Browse files Browse the repository at this point in the history
  • Loading branch information
renkun-ken authored and randy3k committed Feb 19, 2020
1 parent 4d797bb commit ba701e9
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/testthat/test-completion.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,38 @@ test_that("Completion of user function works", {

})

test_that("Completion of symbols in scope works", {
skip_on_cran()
client <- language_client()

withr::local_tempfile(c("temp_file"), fileext = ".R")
writeLines(
c(
"xvar0 <- rnorm(10)",
"my_fun <- function(xvar1) {",
" xvar2 <- 1",
" for (xvar3 in 1:10) {",
" xvar",
" }",
"}"
),
temp_file
)

client %>% did_save(temp_file)

result <- client %>% respond_completion(
temp_file, c(3, 12),
retry_when = function(result) length(result) == 0 || length(result$items) == 0
)

expect_length(result$items, 4)
expect_length(result$items %>% keep(~ .$label == "xvar0"), 1)
expect_length(result$items %>% keep(~ .$label == "xvar1"), 1)
expect_length(result$items %>% keep(~ .$label == "xvar2"), 1)
expect_length(result$items %>% keep(~ .$label == "xvar3"), 1)
})

test_that("Completion inside a package works", {
skip_on_cran()
wd <- path_real(path_package("languageserver", "projects", "mypackage"))
Expand Down

0 comments on commit ba701e9

Please sign in to comment.