1NAME <- "diffFile"
2source(file.path('_helper', 'init.R'))
3
4# - Code File ------------------------------------------------------------------
5
6# # compare two crayon file versions
7# # These should eventually just be downloaded and made into diffFile tests
8
9f.p.1 <- file.path("_helper", "objs", "diffFile", "s.o.3f1f68.R")
10f.p.2 <- file.path("_helper", "objs", "diffFile", "s.o.30dbe0.R")
11
12# url.1 <- "https://raw.githubusercontent.com/gaborcsardi/crayon/3f1f68ab177b82a27e754a58264af801f7194820/R/string_operations.r"
13# url.2 <- "https://raw.githubusercontent.com/gaborcsardi/crayon/30dbe0d4d92157350af3cb3aeebd6d9a9cdf5c0e/R/string_operations.r"
14# f.1 <- readLines(url.1)
15# f.2 <- readLines(url.2)
16# writeLines(f.1, f.p.1)
17# writeLines(f.2, f.p.2)
18
19all.equal(as.character(diffFile(f.p.1, f.p.2)), rdsf(100))
20
21# - RDS ------------------------------------------------------------------------
22
23f1 <- tempfile()
24f2 <- tempfile()
25
26mx1 <- mx2 <- matrix(1:9, 3)
27mx2[5] <- 99
28saveRDS(mx1, f1)
29saveRDS(mx2, f2)
30
31is(diffobj:::get_rds(f1), "matrix")
32is(diffobj:::get_rds(f2), "matrix")
33
34ref <- as.character(diffPrint(mx1, mx2))
35identical(as.character(diffPrint(mx1, f2, cur.banner="mx2")), ref)
36identical(as.character(diffPrint(f1, mx2, tar.banner="mx1")), ref)
37identical(
38  as.character(diffPrint(f1, f2, tar.banner="mx1", cur.banner="mx2")), ref
39)
40isTRUE(!identical(as.character(diffPrint(mx1, f2, rds=FALSE)), ref))
41unlink(c(f1, f2))
42
43# - file -----------------------------------------------------------------------
44
45f1 <- tempfile()
46f2 <- tempfile()
47letters2 <- letters
48letters2[15] <- "HELLO"
49
50writeLines(letters, f1)
51writeLines(letters2, f2)
52
53identical(
54  as.character(diffChr(letters, letters2, tar.banner="f1", cur.banner="f2")),
55  as.character(diffFile(f1, f2))
56)
57unlink(c(f1, f2))
58
59# issue 133 h/t Noam Ross, thanks for the test
60
61x <- tempfile()
62y <- tempfile()
63cat("Hello\nthere\n", file = x)
64file.copy(x, y)
65identical(
66  as.character(diffFile(x, y, format = "raw")),
67  structure(
68    c("No visible differences between objects.",
69      "< x          > y        ",
70      "@@ 1,2 @@    @@ 1,2 @@  ",
71      "  Hello        Hello    ",
72      "  there        there    "), len = 5L)
73)
74unlink(c(x, y))
75
76# - CSV ------------------------------------------------------------------------
77
78f1 <- tempfile()
79f2 <- tempfile()
80
81iris2 <- iris
82iris2$Sepal.Length[25] <- 9.9
83
84write.csv(iris, f1, row.names=FALSE)
85write.csv(iris2, f2, row.names=FALSE)
86
87identical(
88  as.character(diffPrint(iris, iris2, tar.banner="f1", cur.banner="f2")),
89  as.character(diffCsv(f1, f2))
90)
91unlink(c(f1, f2))
92
93