File: test-context.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 (58 lines) | stat: -rwxr-xr-x 1,386 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
55
56
57
58
NAME <- "context"
source(file.path('_helper', 'init.R'))

# - interesting context values -------------------------------------------------

all.equal(
  as.character(diffChr(chr.9, chr.10, context=0)),
  rdsf(100)
)
all.equal(
  as.character(diffChr(chr.9, chr.10, context=-1L)),
  rdsf(150)
)
all.equal(
  as.character(diffChr(chr.9, chr.10, context="auto")),
  rdsf(200)
)
all.equal(
  as.character(diffChr(chr.9, chr.10, context=0, mode="context")), rdsf(300)
)
# - with line limit ------------------------------------------------------------

all.equal(
  as.character(diffChr(chr.9, chr.10, context="auto", line.limit=18)),
  rdsf(400)
)
all.equal(
  as.character(diffChr(chr.9, chr.10, context="auto", line.limit=25)),
  rdsf(500)
)
# default to min context

a <- b <- letters
b[c(3, 20)] <- LETTERS[c(3,20)]
all.equal(
  capture.output(
    show(diffChr(a, b, line.limit=c(20, 10), context='auto', format='raw'))
  ),
  txtf(100)
)
# trim hunks in auto-context mode

a <- b <- letters
b[c(3, 10, 20)] <- LETTERS[c(3,10,20)]
all.equal(
  capture.output(show(
    diffChr(
      a, b, hunk.limit=c(2, 1), context=auto_context(1, 5), line.limit=20,
      format='raw'
    )
  )),
  txtf(200)
)
# - error handling -------------------------------------------------------------

try(auto_context(min=-1, max=1:3)) # "`min` must be"
try(auto_context(min=1, max=1:3)) # "`max` must be"