File: test-methods.R

package info (click to toggle)
r-cran-diffobj 0.3.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,432 kB
  • sloc: ansic: 455; javascript: 96; sh: 32; makefile: 8
file content (54 lines) | stat: -rwxr-xr-x 1,488 bytes parent folder | download
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
NAME <- "methods"
source(file.path('_helper', 'init.R'))

# try implementing methods that change default behavior outside of package

# - Force unified --------------------------------------------------------------

par.env <- new.env()
local(
  envir=par.env, {
  suppressWarnings(
    setClass(
      "testdiffobj", slots=c(a="integer"), where=par.env
  ) )
  # First check that we do actually output in side by side mode

  print(
    all.equal(
      as.character(diffObj(new("testdiffobj", a=1L), new("testdiffobj", a=2L))),
      rdsf(100)
  ) )
  # Now verify that with our new method, we get unified

  setMethod("diffObj", c("testdiffobj", "testdiffobj"),
    function(target, current, ...) {
      dots <- match.call(expand.dots=FALSE)[["..."]]
      if("mode" %in% names(dots))
        callNextMethod()
      else
        callNextMethod(target=target, current=current, ..., mode="unified")
    },
    where=par.env
  )
  on.exit(
    removeMethod("diffObj", c("testdiffobj", "testdiffobj"), where=par.env)
  )
  print(
    all.equal(
      as.character(diffObj(new("testdiffobj", a=1L), new("testdiffobj", a=2L))),
      rdsf(200)
    ) )
  # Make sure we can still get side by side?
  print(
    all.equal(
      as.character(
        diffObj(
          new("testdiffobj", a=1L), new("testdiffobj", a=2L), mode="sidebyside"
      ) ),
      rdsf(100)
  ) )
  try( #"Argument `mode` must be"
    diffObj(new("testdiffobj", a=1L), new("testdiffobj", a=2L), mode="hello")
  )
})