|
| 1 | +test_that("styler can style R, Rmd and Rmarkdown files via style_dir()", { |
| 2 | + msg <- capture_output( |
| 3 | + style_dir(testthat_file("public-api", "xyz-r-and-rmd-dir"), |
| 4 | + filetype = c("R", "Rmd", "Rmarkdown") |
| 5 | + ) |
| 6 | + ) |
| 7 | + expect_true(any(grepl("random-script-in-sub-dir.R", msg, fixed = TRUE))) |
| 8 | + expect_true(any(grepl("random-rmd-script.Rmd", msg, fixed = TRUE))) |
| 9 | + expect_true(any(grepl("random-rmd-script.Rmarkdown", msg, fixed = TRUE))) |
| 10 | +}) |
| 11 | + |
| 12 | +test_that("styler can style Rmd files only via style_dir()", { |
| 13 | + msg <- capture_output( |
| 14 | + style_dir(testthat_file("public-api", "xyz-r-and-rmd-dir"), |
| 15 | + filetype = "Rmd" |
| 16 | + ) |
| 17 | + ) |
| 18 | + expect_true(any(grepl("random-rmd-script.Rmd", msg, fixed = TRUE))) |
| 19 | + expect_false(any(grepl("random-script-in-sub-dir.R", msg, fixed = TRUE))) |
| 20 | + expect_false(any(grepl("random-rmd-script.Rmarkdown", msg, fixed = TRUE))) |
| 21 | +}) |
| 22 | + |
| 23 | +test_that("styler can style .r and .rmd files only via style_dir()", { |
| 24 | + msg <- capture_output( |
| 25 | + style_dir(testthat_file("public-api", "xyz-r-and-rmd-dir"), |
| 26 | + filetype = c(".r", ".rmd") |
| 27 | + ) |
| 28 | + ) |
| 29 | + expect_true(any(grepl("random-script-in-sub-dir.R", msg, fixed = TRUE))) |
| 30 | + expect_true(any(grepl("random-rmd-script.Rmd", msg, fixed = TRUE))) |
| 31 | + expect_false(any(grepl("random-rmd-script.Rmarkdown", msg, fixed = TRUE))) |
| 32 | +}) |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +test_that("styler can style R and Rmd files via style_pkg()", { |
| 37 | + msg <- capture_output( |
| 38 | + style_pkg(testthat_file("public-api", "xyzpackage-rmd"), |
| 39 | + filetype = c("R", "Rmd", "Rmarkdown") |
| 40 | + ) |
| 41 | + ) |
| 42 | + expect_true(any(grepl("hello-world.R", msg, fixed = TRUE))) |
| 43 | + expect_true(any(grepl("test-package-xyz.R", msg, fixed = TRUE))) |
| 44 | + expect_true(any(grepl("random.Rmd", msg, fixed = TRUE))) |
| 45 | + expect_true(any(grepl("random.Rmarkdown", msg, fixed = TRUE))) |
| 46 | + expect_true(any(grepl("README.Rmd", msg, fixed = TRUE))) |
| 47 | + expect_false(any(grepl("RcppExports.R", msg, fixed = TRUE))) |
| 48 | +}) |
| 49 | + |
| 50 | +test_that("style_pkg() styles qmd files by default", { |
| 51 | + msg <- capture_output( |
| 52 | + style_pkg(testthat_file("public-api", "xyzpackage-qmd")) |
| 53 | + ) |
| 54 | + expect_true(any(grepl("hello-world.R", msg, fixed = TRUE))) |
| 55 | + expect_true(any(grepl("test-package-xyz.R", msg, fixed = TRUE))) |
| 56 | + expect_true(any(grepl("random.Rmd", msg, fixed = TRUE))) |
| 57 | + expect_true(any(grepl("random.Rmarkdown", msg, fixed = TRUE))) |
| 58 | + expect_true(any(grepl("README.Rmd", msg, fixed = TRUE))) |
| 59 | + expect_false(any(grepl("RcppExports.R", msg, fixed = TRUE))) |
| 60 | + expect_true(any(grepl("new.qmd", msg, fixed = TRUE))) |
| 61 | +}) |
| 62 | + |
| 63 | +test_that("style_pkg() can find qmd anywhere", { |
| 64 | + msg <- capture_output( |
| 65 | + style_pkg(testthat_file("public-api", "xyzpackage-qmd"), |
| 66 | + filetype = ".Qmd" |
| 67 | + ) |
| 68 | + ) |
| 69 | + expect_no_match(msg, "hello-world.R", fixed = TRUE) |
| 70 | + expect_no_match(msg, "test-package-xyz.R", fixed = TRUE) |
| 71 | + expect_no_match(msg, "random.Rmd", fixed = TRUE) |
| 72 | + expect_no_match(msg, "random.Rmarkdown", fixed = TRUE) |
| 73 | + expect_no_match(msg, "README.Rmd", fixed = TRUE) |
| 74 | + expect_no_match(msg, "RcppExports.R", fixed = TRUE) |
| 75 | + expect_match(msg, "new.qmd", fixed = TRUE) |
| 76 | +}) |
| 77 | + |
| 78 | + |
| 79 | +test_that("styler can style Rmd files only via style_pkg()", { |
| 80 | + msg <- capture_output( |
| 81 | + style_pkg(testthat_file("public-api", "xyzpackage-rmd"), |
| 82 | + filetype = "Rmd" |
| 83 | + ) |
| 84 | + ) |
| 85 | + expect_false(any(grepl("hello-world.R", msg, fixed = TRUE))) |
| 86 | + expect_false(any(grepl("test-package-xyz.R", msg, fixed = TRUE))) |
| 87 | + expect_true(any(grepl("random.Rmd", msg, fixed = TRUE))) |
| 88 | + expect_false(any(grepl("random.Rmarkdown", msg, fixed = TRUE))) |
| 89 | + expect_true(any(grepl("README.Rmd", msg, fixed = TRUE))) |
| 90 | + expect_false(any(grepl("RcppExports.R", msg, fixed = TRUE))) |
| 91 | +}) |
| 92 | + |
| 93 | +test_that("styler can style Rmarkdown files only via style_pkg()", { |
| 94 | + msg <- capture_output( |
| 95 | + style_pkg(testthat_file("public-api", "xyzpackage-rmd"), |
| 96 | + filetype = "Rmarkdown" |
| 97 | + ) |
| 98 | + ) |
| 99 | + expect_false(any(grepl("hello-world.R", msg, fixed = TRUE))) |
| 100 | + expect_false(any(grepl("test-package-xyz.R", msg, fixed = TRUE))) |
| 101 | + expect_false(any(grepl("random.Rmd", msg, fixed = TRUE))) |
| 102 | + expect_true(any(grepl("random.Rmarkdown", msg, fixed = TRUE))) |
| 103 | + expect_false(any(grepl("README.Rmd", msg, fixed = TRUE))) |
| 104 | + expect_false(any(grepl("RcppExports.R", msg, fixed = TRUE))) |
| 105 | +}) |
| 106 | + |
| 107 | +test_that("insufficient R version returns error", { |
| 108 | + expect_error(stop_insufficient_r_version()) |
| 109 | +}) |
0 commit comments