Skip to content

Commit

Permalink
Merge f1d87bd into 08301c0
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil authored May 30, 2022
2 parents 08301c0 + f1d87bd commit a241065
Show file tree
Hide file tree
Showing 60 changed files with 268 additions and 136 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ Suggests:
rmarkdown,
roxygen2,
rstudioapi (>= 0.7),
testthat (>= 2.1.0)
testthat (>= 3.0.0)
VignetteBuilder:
knitr
Encoding: UTF-8
Roxygen: list(markdown = TRUE, roclets = c("rd", "namespace", "collate",
"pkgapi::api_roclet"))
RoxygenNote: 7.1.2
Config/testthat/edition: 3
Collate:
'addins.R'
'communicate.R'
Expand Down
30 changes: 30 additions & 0 deletions tests/testthat/_snaps/cache-with-r-cache.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# cached expressions are displayed propperly

Code
cache_info[, c("n", "size", "last_modified", "activated")]
Output
# A tibble: 1 x 4
n size last_modified activated
<int> <dbl> <dttm> <lgl>
1 0 0 -Inf -Inf FALSE

---

Code
cache_info[, c("n", "size", "activated")]
Output
# A tibble: 1 x 3
n size activated
<int> <dbl> <lgl>
1 1 0 TRUE

---

Code
cache_info[, c("n", "size", "activated")]
Output
# A tibble: 1 x 3
n size activated
<int> <dbl> <lgl>
1 2 0 TRUE

28 changes: 28 additions & 0 deletions tests/testthat/_snaps/escaping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# escaping of characters works

<text>:2:7: unexpected '{'
1:
2: fun() {
^

---

<text>:3:0: unexpected end of input
1:
2: x <-
^

---

<text>:2:3: unexpected input
1:
2: 1 _
^

---

<text>:6:0: unexpected end of input
4:
5:
^

15 changes: 15 additions & 0 deletions tests/testthat/_snaps/helpers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# can construct and print vertical

Code
construct_vertical(c("1 + 1", "nw"))
Output
1 + 1
nw

# can lookup tokens

Code
lookup_new_special()
Output
[1] "SPECIAL-PIPE" "SPECIAL-IN" "SPECIAL-OTHER"

54 changes: 54 additions & 0 deletions tests/testthat/_snaps/public_api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# messages (via cat()) of style_file are correct

Code
cat(catch_style_file_output(file.path("public-api", "xyzdir-dirty",
"dirty-sample-with-scope-tokens.R")), sep = "\n")
Output
Styling 1 files:
dirty-sample-with-scope-tokens.R i
----------------------------------------
Status Count Legend
v 0 File unchanged.
i 1 File changed.
x 0 Styling threw an error.
----------------------------------------
Please review the changes carefully!

---

Code
cat(catch_style_file_output(file.path("public-api", "xyzdir-dirty",
"clean-sample-with-scope-tokens.R")), sep = "\n")
Output
Styling 1 files:
clean-sample-with-scope-tokens.R v
----------------------------------------
Status Count Legend
v 1 File unchanged.
i 0 File changed.
x 0 Styling threw an error.
----------------------------------------

---

Code
cat(catch_style_file_output(file.path("public-api", "xyzdir-dirty",
"dirty-sample-with-scope-spaces.R")), sep = "\n")
Output
Styling 1 files:
dirty-sample-with-scope-spaces.R i
----------------------------------------
Status Count Legend
v 0 File unchanged.
i 1 File changed.
x 0 Styling threw an error.
----------------------------------------
Please review the changes carefully!

# No sensitive to decimal option

Code
style_text("1")
Output
1

9 changes: 9 additions & 0 deletions tests/testthat/_snaps/roundtrip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# correct styling does not give an error

Code
verify_roundtrip("1+1", "1 + 1")

# corrupt styling does give an error

The expression evaluated before the styling is not the same as the expression after styling. This should not happen. Please file a bug report on GitHub (https://github.com/r-lib/styler/issues) using a reprex.

24 changes: 24 additions & 0 deletions tests/testthat/_snaps/utils.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# files with and without blank EOF line are read correctly

Code
read_utf8(test_path("reference-objects/missing-blank-at-EOF.R"))
Output
$text
[1] "x"
$missing_EOF_line_break
[1] TRUE

---

Code
read_utf8(test_path("reference-objects/non-missing-blank-at-EOF.R"))
Output
$text
[1] "x"
$missing_EOF_line_break
[1] FALSE

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("testing styler on package")


test_that("hi there", {
I(am(a(package(x))))
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("testing styler on package")


test_that("hi there", {
I(am(a(package(x))))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("testing styler on package")


test_that("hi there", {
I(am(a(package(x))))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("testing styler on package")


test_that("hi there", {
I(am(a(package(x))))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("testing styler on package")


test_that("hi there", {
I(am(a(package(x))))
Expand Down
32 changes: 14 additions & 18 deletions tests/testthat/test-cache-with-r-cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ test_that("Cache management works", {
local_test_setup(cache = TRUE)
# at fresh startup
expect_s3_class(cache_info(format = "tabular"), "tbl_df")
expect_error(capture.output(cache_info()), NA)
expect_output(cache_info())
expect_equal(basename(cache_activate()), styler_version)
expect_equal(basename(cache_activate("xyz")), "xyz")
expect_equal(getOption("styler.cache_name"), "xyz")
# when cache xyz is activated, cache_info() shows deactivated for other caches
expect_false(cache_info(styler_version, format = "tabular")$activated)
expect_error(capture.output(cache_info(format = "lucid")), NA)
expect_output(cache_info(format = "lucid"))
# cache_info() defaults to the currently active cache
expect_equal(basename(cache_info(format = "tabular")$location), "xyz")

Expand All @@ -22,7 +22,7 @@ test_that("Cache management works", {
)
expect_false(cache_info(format = "tabular")$activated)
expect_equal(getOption("styler.cache_location"), NULL)
expect_error(cache_clear("testthat", ask = FALSE), NA)
expect_silent(cache_clear("testthat", ask = FALSE))
})

test_that("top-level test: Caches top-level expressions efficiently on style_text()", {
Expand Down Expand Up @@ -57,30 +57,26 @@ test_that("top-level test: Caches top-level expressions efficiently on style_tex


test_that("cached expressions are displayed propperly", {
skip_if(getRversion() < "4.2")

cache_info <- cache_info("testthat", format = "tabular")
expect_known_value(
cache_info[, c("n", "size", "last_modified", "activated")],
file = test_path("reference-objects/cache-info-1"),
update = getOption("styler.test_dir_writable", TRUE)
)
expect_snapshot({
cache_info[, c("n", "size", "last_modified", "activated")]
})

local_test_setup(cache = TRUE)
style_text("1+1")
cache_info <- cache_info(format = "tabular")
cache_info$size <- round(cache_info$size, -2)
expect_known_value(
cache_info[, c("n", "size", "activated")],
file = test_path("reference-objects/cache-info-2"),
update = getOption("styler.test_dir_writable", TRUE)
)
expect_snapshot({
cache_info[, c("n", "size", "activated")]
})
style_text("a <-function() NULL")
cache_info <- cache_info(format = "tabular")
cache_info$size <- round(cache_info$size, -2)
expect_known_value(
cache_info[, c("n", "size", "activated")],
file = test_path("reference-objects/cache-info-3"),
update = getOption("styler.test_dir_writable", TRUE)
)
expect_snapshot({
cache_info[, c("n", "size", "activated")]
})
})


Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-create_token.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("token insertion")


test_that("can create a token that has relevant columns", {
pd_names <- c(
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-create_tree.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("test tree creation")


test_that("create_trees outputs identical structure if trees have same structure", {
skip_if_not_installed("DiagrammeR")
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-curly-curly.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("curly-curly")


test_that("curly-culry", {
expect_warning(test_collection("curly-curly",
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-encoding.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("non-ASCII characters are handled properly")


test_that("non-ASCII characters are handled properly for text styling", {
expect_equal(
Expand Down
24 changes: 12 additions & 12 deletions tests/testthat/test-escaping.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ test_that("escaping of characters works", {
transformer = style_text
), NA)

expect_error(test_collection("escaping", "fail-parsing-1",
transformer = style_text
), "<text>:2:7: unexpected ")
expect_snapshot_error(
test_collection("escaping", "fail-parsing-1", transformer = style_text)
)

expect_error(test_collection("escaping", "fail-parsing-2",
transformer = style_text
), "x <-")
expect_snapshot_error(
test_collection("escaping", "fail-parsing-2", transformer = style_text)
)

expect_error(test_collection("escaping", "fail-parsing-3",
transformer = style_text
))
expect_snapshot_error(
test_collection("escaping", "fail-parsing-3", transformer = style_text)
)

expect_error(test_collection("escaping", "fail-parsing-4",
transformer = style_text
), "<text>:6:0:")
expect_snapshot_error(
test_collection("escaping", "fail-parsing-4", transformer = style_text)
)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-exception_handling.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("Exception handling")


test_that("style_text returns custom error", {
expect_error(style_text("a <- 3 4"), "unexpected numeric constant")
Expand Down
9 changes: 3 additions & 6 deletions tests/testthat/test-helpers.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
context("various helpers")


test_that("can construct and print vertical", {
expect_error(construct_vertical(c("1 + 1", "nw")), NA)
capture.output(
expect_error(construct_vertical(c("1 + 1", "nw")) %>% print(), NA)
)
expect_snapshot({construct_vertical(c("1 + 1", "nw"))})
})


Expand All @@ -13,7 +10,7 @@ test_that("file types can be asserted", {
})

test_that("can lookup tokens", {
expect_error(lookup_new_special(), NA)
expect_snapshot({lookup_new_special()})
})

test_that("can extend non-comment", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-identify-roxygen-examples.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("test-roxygen-examples-identify.R")


#' Things to consider:
#' * one function declaration or many
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-indention_curly.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("indent curly brackets")


test_that("indention on one-liner curley only is not changed", {
expect_warning(test_collection("indention_curly_brackets",
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-indention_fun_calls.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("test-indention_fun_calls.R")


test_that("edge cases work", {
expect_warning(test_collection("indention_fun_calls",
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-indention_multiple.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("test indent multiple")


test_that("multiple round brackets don't cause extraindention", {
expect_warning(test_collection("indention_multiple",
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-indention_operators.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("indention operators")


test_that("pipe is indended correctly", {
expect_warning(test_collection("indention_operators",
Expand Down
Loading

0 comments on commit a241065

Please sign in to comment.