1test_that("empty file gives empty list", { 2 out <- roc_proc_text(rd_roclet(), "") 3 expect_identical(out, list()) 4}) 5 6test_that("NULL gives empty list", { 7 out <- roc_proc_text(rd_roclet(), "NULL") 8 expect_identical(out, list()) 9}) 10 11test_that("@noRd inhibits documentation", { 12 out <- roc_proc_text(rd_roclet(), " 13 #' Would be title 14 #' @title Overridden title 15 #' @name a 16 #' @noRd 17 NULL") 18 19 expect_equal(length(out), 0) 20}) 21 22test_that("deleted objects not documented", { 23 out <- roc_proc_text(rd_roclet(), " 24 f <- function(){ 25 .a <- 0 26 function(x = 1){ 27 .a <<- .a + x 28 .a 29 } 30 } 31 32 #' Addition function. 33 f2 <- f() 34 rm(f) 35 ") 36 expect_equal(names(out), "f2.Rd") 37}) 38 39test_that("documenting unknown function requires name", { 40 expect_warning( 41 roc_proc_text(rd_roclet(), " 42 #' Virtual Class To Enforce Max Slot Length 43 setClass('A') 44 45 #' Validity function. 46 setValidity('A', function(object) TRUE)" 47 ), 48 "Missing name" 49 ) 50}) 51 52test_that("documenting NA gives useful error message (#194)", { 53 expect_warning( 54 roc_proc_text(rd_roclet(), " 55 #' Missing value 56 NA" 57 ), 58 "Missing name" 59 ) 60}) 61 62test_that("@description NULL", { 63 # Just ignore in this case 64 out <- roxygen2::roc_proc_text(roxygen2::rd_roclet(), " 65 #' Title 66 #' 67 #' @description NULL 68 #' @format NULL 69 foobar <- 1:10 70 ") 71 expect_identical(out[[1]]$get_value("description"), "Title") 72 73 # Still ignore 74 out <- roxygen2::roc_proc_text(roxygen2::rd_roclet(), " 75 #' Title 76 #' @description NULL 77 #' @description desc 78 #' @format NULL 79 foobar <- 1:10 80 ") 81 expect_identical(out[[1]]$get_value("description"), "desc") 82 83 # Still ignore for objects as well 84 out <- roxygen2::roc_proc_text(roxygen2::rd_roclet(), " 85 #' Title 86 #' @description NULL 87 #' @format NULL 88 foobar <- 1:10 89 ") 90 expect_identical(out[[1]]$get_value("description"), "Title") 91 92 # But drop for package docs 93 with_mock( 94 `roxygen2::read.description` = function(...) 95 list(Package = "roxygen_devtest", 96 Title = "Package Title", 97 Description = "Package description."), 98 out <- roxygen2::roc_proc_text(roxygen2::rd_roclet(), " 99 #' Title 100 #' 101 #' @docType package 102 #' @description NULL 103 #' @name pkg 104 '_PACKAGE' 105 ") 106 ) 107 expect_null(out[[1]]$get_value("description")) 108}) 109 110test_that("@details NULL", { 111 # Just ignore in this case 112 out <- roxygen2::roc_proc_text(roxygen2::rd_roclet(), " 113 #' Title 114 #' 115 #' @details NULL 116 #' @format NULL 117 foobar <- 1:10 118 ") 119 expect_null(out[[1]]$get_value("details")) 120 121 # Still ignore 122 out <- roxygen2::roc_proc_text(roxygen2::rd_roclet(), " 123 #' Title 124 #' @details NULL 125 #' @details desc 126 #' @format NULL 127 foobar <- 1:10 128 ") 129 expect_identical(out[[1]]$get_value("details"), "desc") 130 131 # Still ignore for objects as well 132 out <- roxygen2::roc_proc_text(roxygen2::rd_roclet(), " 133 #' Title 134 #' @details NULL 135 #' @format NULL 136 foobar <- 1:10 137 ") 138 expect_null(out[[1]]$get_value("details")) 139}) 140 141# UTF-8 ------------------------------------------------------------------- 142 143test_that("can generate nonASCII document", { 144 test_pkg <- temp_copy_pkg(test_path('testNonASCII')) 145 on.exit(unlink(test_pkg, recursive = TRUE), add = TRUE) 146 147 expect_output(roxygenise(test_pkg, roclets = "rd"), "printChineseMsg[.]Rd") 148 149 rd_path <- file.path(test_pkg, "man", "printChineseMsg.Rd") 150 expect_true(file.exists(rd_path)) 151 rd <- read_lines(rd_path) 152 153 expect_true(any(grepl("\u6211\u7231\u4e2d\u6587", rd))) 154 expect_true(any(grepl("\u4e2d\u6587\u6ce8\u91ca", rd))) 155 156 # Shouldn't change again 157 expect_output(roxygenise(test_pkg, roclets = "rd"), NA) 158}) 159 160test_that("unicode escapes are ok", { 161 test_pkg <- temp_copy_pkg(test_path('testUtf8Escape')) 162 on.exit(unlink(test_pkg, recursive = TRUE), add = TRUE) 163 164 expect_output(roxygenise(test_pkg, roclets = "rd"), "a[.]Rd") 165 166 rd_path <- file.path(test_pkg, "man", "a.Rd") 167 expect_true(file.exists(rd_path)) 168 rd <- read_lines(rd_path) 169 170 expect_true(any(grepl("7\u00b0C", rd))) 171 172 # Shouldn't change again 173 expect_output(roxygenise(test_pkg, roclets = "rd"), NA) 174}) 175 176test_that("write_lines writes unix-style line endings.", { 177 path <- test_path("escapes.Rd") 178 179 # skip if checked on windows with autocrlf = true 180 skip_if(detect_line_ending(path) == "\r\n") 181 182 temp_filename <- tempfile() 183 old_binary <- readBin(path, "raw", n = file.info(path)$size) 184 old_text <- read_lines(path) 185 write_lines(old_text, temp_filename) 186 on.exit(unlink(temp_filename), add = TRUE) 187 new_binary <- readBin(temp_filename, "raw", n = file.info(temp_filename)$size) 188 expect_identical(new_binary, old_binary) 189}) 190