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
|
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 <- "context"
> source(file.path('_helper', 'init.R'))
>
> # - interesting context values -------------------------------------------------
>
> all.equal(
+ as.character(diffChr(chr.9, chr.10, context=0)),
+ rdsf(100)
+ )
[1] TRUE
> all.equal(
+ as.character(diffChr(chr.9, chr.10, context=-1L)),
+ rdsf(150)
+ )
[1] TRUE
> all.equal(
+ as.character(diffChr(chr.9, chr.10, context="auto")),
+ rdsf(200)
+ )
[1] TRUE
> all.equal(
+ as.character(diffChr(chr.9, chr.10, context=0, mode="context")), rdsf(300)
+ )
[1] TRUE
> # - with line limit ------------------------------------------------------------
>
> all.equal(
+ as.character(diffChr(chr.9, chr.10, context="auto", line.limit=18)),
+ rdsf(400)
+ )
[1] TRUE
> all.equal(
+ as.character(diffChr(chr.9, chr.10, context="auto", line.limit=25)),
+ rdsf(500)
+ )
[1] TRUE
> # 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)
+ )
[1] TRUE
> # 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)
+ )
[1] TRUE
> # - error handling -------------------------------------------------------------
>
> try(auto_context(min=-1, max=1:3)) # "`min` must be"
Error in auto_context(min = -1, max = 1:3) :
Argument `min` must be integer(1L) and greater than zero
> try(auto_context(min=1, max=1:3)) # "`max` must be"
Error in auto_context(min = 1, max = 1:3) :
Argument `max` must be integer(1L) and not NA
>
>
> proc.time()
user system elapsed
1.714 0.151 1.881
|