1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
|
R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin17.0 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> NAME <- "diffPrint"
> source(file.path('_helper', 'init.R'))
>
> # Note, atomic prints happen in different test file
>
> # - Matrices -------------------------------------------------------------------
>
> mx.2 <- matrix(1:100, ncol=2)
> mx.4 <- mx.3 <- mx.2
> mx.3[31, 2] <- 111L
>
> mx.3a <- mx.3[-31, ]
> set.seed(2)
> mx.4[cbind(sample(1:50, 6), sample(1:2, 6, replace=TRUE))] <-
+ sample(-(1:50), 6)
>
> mx.5 <- matrix(1:9, 3)
> mx.6 <- matrix(12:1, 4)
> mx.6[4,] <- c(3L, 6L, 9L)
>
> # single value difference
> all.equal(as.character(diffPrint(mx.2, mx.3)), rdsf(100))
[1] TRUE
> # single value unified
> all.equal(as.character(diffPrint(mx.2, mx.3, mode="unified")), rdsf(150))
[1] TRUE
> # single value context
> all.equal(as.character(diffPrint(mx.2, mx.3, mode="context")), rdsf(175))
[1] TRUE
> # missing row
> all.equal(as.character(diffPrint(mx.2, mx.3a)), rdsf(200))
[1] TRUE
> all.equal(as.character(diffPrint(mx.2, mx.3a, mode="unified")), rdsf(300))
[1] TRUE
> # More differences
>
> all.equal(as.character(diffPrint(mx.2, mx.4)), rdsf(400))
[1] TRUE
> all.equal(as.character(diffPrint(mx.2, mx.4, mode="unified")), rdsf(500))
[1] TRUE
> # Testing alignments
> all.equal(as.character(diffPrint(mx.5, mx.6)), rdsf(600))
[1] TRUE
> all.equal(as.character(diffPrint(mx.5, mx.6, mode="unified")), rdsf(700))
[1] TRUE
> all.equal(as.character(diffPrint(mx.5, mx.6, mode="context")), rdsf(800))
[1] TRUE
> # More complex matrix
> set.seed(2)
> A <- B <- matrix(sample(1:80), nrow=16)
> B[cbind(sample(5:16, 4), sample(1:5, 4))] <- sample(30:80, 4)
>
> all.equal(as.character(diffPrint(A, B)), rdsf(900))
[1] TRUE
> all.equal(as.character(diffPrint(A, B, mode="unified")), rdsf(1000))
[1] TRUE
> all.equal(as.character(diffPrint(A, B, mode="context")), rdsf(1100))
[1] TRUE
> # Style matrices
>
> all.equal(as.character(diffPrint(diffobj:::.mx1, diffobj:::.mx2)), rdsf(1200))
[1] TRUE
>
> # - Lists ----------------------------------------------------------------------
>
> all.equal(as.character(diffPrint(lst.1, lst.3)), rdsf(1300))
[1] TRUE
> all.equal(as.character(diffPrint(lst.1, lst.3, mode="unified")), rdsf(1400))
[1] TRUE
> all.equal(as.character(diffPrint(lst.4, lst.5)), rdsf(1500))
[1] TRUE
> all.equal(as.character(diffPrint(lst.4, lst.5, mode="context")), rdsf(1600))
[1] TRUE
> # Nested first element (https://github.com/brodieG/diffobj/issues/46)
> all.equal(
+ as.character(diffPrint(list(1, list(2, list(1:3))), list(list(list(1:3))))),
+ rdsf(1650)
+ )
[1] TRUE
> # Interesting but relatively slow example so we don't actually run it in
> # tests
>
> # diffPrint(unclass(mdl1), unclass(mdl2))
> # diffPrint(unclass(mdl1), unclass(mdl2), mode="unified")
>
> # - Data Frames ----------------------------------------------------------------
>
> all.equal(as.character(diffPrint(iris.s, iris.2)), rdsf(1700))
[1] TRUE
> all.equal(
+ as.character(diffPrint(iris.s, iris.2, mode="sidebyside")), rdsf(1800)
+ )
[1] TRUE
> all.equal(as.character(diffPrint(iris.s, iris.c)), rdsf(1900))
[1] TRUE
> all.equal(as.character(diffPrint(iris.s, iris.3)), rdsf(2000))
[1] TRUE
>
> all.equal(
+ as.character(diffPrint(iris.s, iris.3, mode="sidebyside")), rdsf(2100)
+ )
[1] TRUE
> all.equal(as.character(diffPrint(iris.s, iris.4, mode="unified")), rdsf(2150))
[1] TRUE
> all.equal(
+ as.character(diffPrint(iris.s, iris.4, mode="sidebyside")), rdsf(2200)
+ )
[1] TRUE
> all.equal(
+ as.character(diffPrint(iris.5, iris.4, mode="sidebyside")), rdsf(2250)
+ )
[1] TRUE
> all.equal(as.character(diffPrint(iris.3a, iris.4a)), rdsf(2300))
[1] TRUE
> all.equal(
+ as.character(diffPrint(iris.s, iris.3, mode="sidebyside")), rdsf(2350)
+ )
[1] TRUE
> all.equal(as.character(diffPrint(iris.s, iris.s[-2])), rdsf(2370))
[1] TRUE
> # This one is interesting because the input is pathological because there
> # is one line that matches exactly between the two and as such creates a
> # matching hunk, but it really is matching by coincidence.
>
> all.equal(
+ as.character(diffPrint(iris.s, iris.s[-2], mode="sidebyside")), rdsf(2383)
+ )
[1] TRUE
> # Possible example where we may not want to trim the row headers (Issue #39)
> all.equal(
+ as.character(diffPrint(cars[1:5,], mtcars[1:5,], mode="sidebyside")),
+ rdsf(2380)
+ )
[1] TRUE
>
> # - Guides ---------------------------------------------------------------------
>
> # Most guides tests are in the guides file, but this confirms interface works
> # when starting at `diffPrint` instead of internally
>
> all.equal(
+ as.character(
+ diffPrint(
+ iris.s, iris.4, mode="sidebyside", guides=function(x, y) integer()
+ ) ),
+ rdsf(2400)
+ )
[1] TRUE
> all.equal(
+ as.character(diffPrint(iris.s, iris.4, mode="sidebyside", guides=FALSE)),
+ rdsf(2500)
+ )
[1] TRUE
>
> # - Arrays
> arr.1 <- arr.2 <- array(1:24, c(4, 2, 3))
> arr.2[c(3, 20)] <- 99L
> all.equal(as.character(diffPrint(arr.1, arr.2)), rdsf(2600))
[1] TRUE
>
> # - Mixed
> all.equal(
+ as.character(diffPrint(list(1, 2, 3), matrix(1:9, 3))),
+ rdsf(2700)
+ )
[1] TRUE
> all.equal(
+ as.character(diffPrint(list(25, 2, 3), matrix(1:9, 3))),
+ rdsf(2800)
+ )
[1] TRUE
> all.equal(
+ as.character(
+ diffPrint(list(c(1, 4, 7), c(2, 5, 8), c(3, 6, 9)), matrix(1:9, 3))
+ ),
+ rdsf(2900)
+ )
[1] TRUE
> # - `unitizer` corner case -----------------------------------------------------
>
> res1 <- structure(
+ c(-1717, 101, 0.938678984853783),
+ .Names = c("intercept", "slope", "rsq"), class = "fastlm"
+ )
> res2 <- structure(
+ c(-3.541306e+13, 701248600000, 0.938679),
+ .Names = c("intercept", "slope", "rsq"), class = "fastlm"
+ )
> all.equal(as.character(diffPrint(res1, res2)), rdsf(3000))
[1] TRUE
> all.equal(
+ as.character(diffPrint(unname(res1), unname(res2))), rdsf(3100)
+ )
[1] TRUE
>
> # - factors and other meta -----------------------------------------------------
>
> # Thanks Frank
>
> all.equal(
+ as.character(diffPrint(factor(1:100), factor(c(1:99, 101)))), rdsf(3200)
+ )
[1] TRUE
> f1 <- factor(1:100)
> f2 <- factor(c(1:20, 22:99, 101))
> all.equal(capture.output(diffPrint(f1, f2)), txtf(100))
[1] TRUE
>
> f3 <- factor(letters[1:10])
> f4 <- factor(letters[1:10], levels=letters[1:11])
> all.equal(capture.output(diffPrint(f3, f4)), txtf(150))
[1] TRUE
>
> # time series
>
> nhtemp2 <- nhtemp
> nhtemp2[c(5, 30)] <- -999
> all.equal(capture.output(diffPrint(nhtemp, nhtemp2)), txtf(175))
[1] TRUE
>
> # Meta on both sides
>
> print.diffobj_test_c1 <- function(x, ...) {
+ writeLines(c("Header row 1", "header row 2"))
+ print(c(x))
+ writeLines(c("", "Footer row 1", "", "footer row2"))
+ }
> m1 <- structure(1:30, class='diffobj_test_c1')
> m2 <- structure(2:51, class='diffobj_test_c1')
> all.equal(capture.output(diffPrint(m1, m2)), txtf(200), print=TRUE)
[1] TRUE
>
> # - Raw output -----------------------------------------------------------------
>
> all.equal(
+ as.character(diffPrint(letters, LETTERS, format="raw", pager="off")),
+ rdsf(3300)
+ )
[1] TRUE
> # - Varying Widths -------------------------------------------------------------
>
> all.equal(
+ as.character(diffPrint(letters, LETTERS, format="raw", disp.width=40)),
+ rdsf(3400)
+ )
[1] TRUE
> try(diffPrint(letters, LETTERS, disp.width=5))
Error in diffPrint(target = letters, current = LETTERS, disp.width = 5) :
Arugment `disp.width` must be integer(1L) and 0, or between 10 and 10000
>
> # - covr workaround ------------------------------------------------------------
>
> # Needed so that the function definition stuff is marked as covered; really
> # it shouldn't even be eligible for coverage, need to discuss further with
> # jhester
>
> invisible(diffobj:::make_diff_fun())
>
> # - Encoding Issues ------------------------------------------------------------
>
> # issue81, mixed UTF-8 ASCII, encoding a-acute in hex to avoid cross platform
> # issues
>
> a <- "G\xc3\xa1bor Cs\xc3\xa1rdi"
> b <- sprintf("%s wow", a)
> Encoding(a) <- 'UTF-8'
> Encoding(b) <- 'UTF-8'
>
> # No error
>
> new <- (as.character(diffPrint(list(hell=a, b=NULL), list(hell=b, b=list()))))
>
> # can't store this in RDS b/c otherwise won't run properly on oses with
> # different encoding (e.g. windows)
>
> ref <- structure(
+ c("\033[33m<\033[39m \033[33mlist(hell = a, b = N..\033[39m \033[34m>\033[39m \033[34mlist(hell = b, b = l..\033[39m",
+ "\033[36m@@ 1,6 @@ \033[39m \033[36m@@ 1,6 @@ \033[39m",
+ " \033[90m\033[39m$hell\033[90m\033[39m \033[90m\033[39m$hell\033[90m\033[39m ",
+ "\033[33m<\033[39m \033[90m[1] \033[39m\033[33m\"G\xc3\xa1bor Cs\xc3\xa1rdi\"\033[39m\033[90m\033[39m \033[34m>\033[39m \033[90m[1] \033[39m\033[34m\"G\xc3\xa1bor Cs\xc3\xa1rdi wow\"\033[39m\033[90m\033[39m",
+ " ", " \033[90m\033[39m$b\033[90m\033[39m \033[90m\033[39m$b\033[90m\033[39m ",
+ "\033[33m<\033[39m \033[90m\033[39m\033[33mNULL\033[39m\033[90m\033[39m \033[34m>\033[39m \033[90m\033[39m\033[34mlist\033[39m\033[34m()\033[39m\033[90m\033[39m ",
+ " "
+ ),
+ len = 8L
+ )
> Encoding(ref) <- 'UTF-8'
> all.equal(new, ref)
[1] TRUE
>
> # issue 106, this used to fail when trying to check for an RDS with a bytes
> # encoded file name
>
> bytes <- "\x81"
> Encoding(bytes) <- "bytes"
> isTRUE(!any(diffPrint(bytes, bytes)))
[1] TRUE
>
> # - Quoted Objects -------------------------------------------------------------
>
> all.equal(
+ as.character(diffPrint(quote(zz + 1), quote(zz + 3))),
+ structure(
+ c("\033[33m<\033[39m \033[33mquote(..\033[39m \033[34m>\033[39m \033[34mquote(..\033[39m", "\033[36m@@ 1 @@ \033[39m \033[36m@@ 1 @@ \033[39m", "\033[33m<\033[39m \033[90m\033[39mzz + \033[33m1\033[39m\033[90m\033[39m \033[34m>\033[39m \033[90m\033[39mzz + \033[34m3\033[39m\033[90m\033[39m "
+ ), len = 3L
+ )
+ )
[1] TRUE
> all.equal(
+ as.character(diffPrint(quote(x), quote(y))),
+ structure(
+ c("\033[33m<\033[39m \033[33mquote(x)\033[39m \033[34m>\033[39m \033[34mquote(y)\033[39m", "\033[36m@@ 1 @@ \033[39m \033[36m@@ 1 @@ \033[39m", "\033[33m<\033[39m \033[90m\033[39m\033[33mx\033[39m\033[90m\033[39m \033[34m>\033[39m \033[90m\033[39m\033[34my\033[39m\033[90m\033[39m "),
+ len = 3L
+ )
+ )
[1] TRUE
> # - par_frame ------------------------------------------------------------------
>
> # check that par_frame is retrieved correctly
> env <- new.env()
> env$print <- function(x, ...) stop('boom')
> try(evalq(diffPrint(1:3, 1:4), env)) # "Failed attempting .*: boom"
Error in print(1:4) : boom
Error in .local(target, current, ...) :
Failed attempting to get text representation of object: boom
>
> f <- function(a, b, ...) {
+ print <- function(x, ...) stop('boom2')
+ diffPrint(a, b, ...)
+ }
> try(f(1:3, 1:4, format='raw')) # "Failed attempting .*: boom2"
Error in print(1:4) : boom2
Error in .local(target, current, ...) :
Failed attempting to get text representation of object: boom2
>
>
> proc.time()
user system elapsed
5.686 0.658 6.772
|