1
2R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
3Copyright (C) 2020 The R Foundation for Statistical Computing
4Platform: x86_64-apple-darwin17.0 (64-bit)
5
6R is free software and comes with ABSOLUTELY NO WARRANTY.
7You are welcome to redistribute it under certain conditions.
8Type 'license()' or 'licence()' for distribution details.
9
10R is a collaborative project with many contributors.
11Type 'contributors()' for more information and
12'citation()' on how to cite R or R packages in publications.
13
14Type 'demo()' for some demos, 'help()' for on-line help, or
15'help.start()' for an HTML browser interface to help.
16Type 'q()' to quit R.
17
18> NAME <- "diffObj"
19> source(file.path('_helper', 'init.R'))
20>
21> # - simple diffobj -------------------------------------------------------------
22>
23> # no diff for print
24> all.equal(as.character(diffObj(iris.s, iris.c)), rdsf(100))
25[1] TRUE
26> # no diff for str
27> all.equal(
28+   as.character(diffObj(1:100, c(1:99, 200L))), rdsf(200)
29+ )
30[1] TRUE
31> # diffs for both and must pick one, first one is str, second is print
32> all.equal(
33+   as.character(diffObj(mdl1[7], mdl2[7])), rdsf(300)
34+ )
35[1] TRUE
36> all.equal(as.character(diffObj(mdl1, mdl2)), rdsf(400))
37[1] TRUE
38>
39> # - fits or doesn't ------------------------------------------------------------
40>
41> # Note, the first test used to favor str until we handicapped print
42> all.equal(
43+   diffObj(matrix(1:20, ncol=2), matrix(2:21, ncol=2), line.limit=5)@capt.mode,
44+   "str"
45+ )
46[1] TRUE
47> # test kinda slow, would be better to have one with smaller objects with print
48> # methods
49>
50> all.equal(
51+   diffObj(mdl1, mdl2, line.limit=15, mode='unified')@capt.mode, "print"
52+ )
53[1] TRUE
54> all.equal(diffObj(1:1000, 1000:1, line.limit=5)@capt.mode, "str")
55[1] TRUE
56>
57> # - misc -----------------------------------------------------------------------
58>
59> try(diffObj(1, 2, extra=list(TRUE))) # "extra"
60Error in .local(target, current, ...) :
61  Argument `extra` must be empty in `diffObj`.
62>
63> # - print error ----------------------------------------------------------------
64>
65> x <- structure("hello", class="diffobj_ogewlhgiadfl")
66> y <- structure("goodbye", class="diffobj_ogewlhgiadfl")
67> try(diffObj(x, y)) # "Error in calling .diffPrint."
68Error in print.diffobj_ogewlhgiadfl(structure("goodbye", class = "diffobj_ogewlhgiadfl")) :
69  failure
70Error in diffObj(target = x, current = y) :
71  Error in calling `diffPrint`: Failed attempting to get text representation of object: failure
72>
73> # Random exmaples to think through `diffObj` output
74>
75> diffObj(
76+   pairlist("`logical(2L)` should be length 2 (is 3)"),
77+   pairlist("be length 2 (is 3)")
78+ )
79< pairlist("`logical(2L)` should be l..  > pairlist("be length 2 (is 3)")
80@@ 1,3 @@                                @@ 1,3 @@                              
81  [[1]]                                    [[1]]
82< [1] "`logical(2L)` should be length 2  > [1] "be length 2 (is 3)"
83:  (is 3)"                               ~
84
85>
86> diffObj(
87+   pairlist("`matrix(integer(), nrow = 3)` should be matrix (is list)", "`list(character(1L), 1L)[[2]]` should be type \"integer-like\" (is \"character\")"),
88+   pairlist("be class \"matrix\" (is \"list\")", "be type \"integer-like\" (is \"character\") at index [[2]]")
89+ )
90< pairlist("`matrix(integer(), nrow =..  > pairlist("be class \"matrix\" (is \..
91@@ 1,6 @@                                @@ 1,6 @@                              
92  [[1]]                                    [[1]]
93< [1] "`matrix(integer(), nrow = 3)` sh  > [1] "be class \"matrix\" (is \"list\"
94: ould be matrix (is list)"              : )"
95
96  [[2]]                                    [[2]]
97< [1] "`list(character(1L), 1L)[[2]]` s  > [1] "be type \"integer-like\" (is \"c
98: hould be type \"integer-like\" (is \"  : haracter\") at index [[2]]"
99: character\")"                          ~
100
101>
102> proc.time()
103   user  system elapsed
104  3.252   0.326   3.687
105