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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
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 <- "style"
> source(file.path('_helper', 'init.R'))
>
> ## - Style Palette ------------------------------------------------------------
>
> all.equal(
+ capture.output(diffobj:::display_ansi_256_styles()),
+ rdsf(100)
+ )
[1] TRUE
> ## - crayon settings -----------------------------------------------------------
>
> # make sure crayon options are appropriately overriden
> local({
+ old.opt <- options(crayon.enabled=FALSE)
+ on.exit(options(old.opt))
+ print(identical(crayon::green("green"), "green"))
+ # should have ANSI coloring despite crayon disabled
+ print(
+ all.equal(
+ as.character(diffChr(letters[1:3], LETTERS[1:3])), rdsf(200)
+ )
+ )
+ identical(crayon::green("green"), "green")
+ })
[1] TRUE
[1] TRUE
[1] TRUE
> ## - Palette of Styles ---------------------------------------------------------
>
> pos <- PaletteOfStyles()
> identical(
+ pos[["ansi256", "light", "rgb"]],
+ getClassDef("StyleAnsi256LightRgb", package="diffobj", inherits=FALSE)
+ )
[1] TRUE
> all.equal(
+ capture.output(show(pos)), rdsf(300)
+ )
[1] TRUE
> all.equal(
+ capture.output(summary(pos)), rdsf(400)
+ )
[1] TRUE
>
> pos["ansi256", "light", "yb"] <- list(StyleRaw())
> all.equal(
+ c(pos["ansi256", "light", "yb"]@data), list(StyleRaw()),
+ check.environment=FALSE
+ )
[1] TRUE
> all.equal(
+ pos[["ansi256", "light", "yb"]], StyleRaw(),
+ check.environment=FALSE
+ )
[1] TRUE
>
> ## - Auto Styles ---------------------------------------------------------------
>
> try(diffChr(letters, LETTERS, style="auto", format="xml"))
Error in diffChr(target = letters, current = LETTERS, style = "auto", :
Argument `format` must be one of `c("auto", "raw", "ansi8", "ansi256", "html")`.
> is(
+ diffChr(
+ letters, LETTERS, style="auto", format="auto", brightness="light",
+ term.colors=256
+ )@etc@style,
+ "StyleAnsi256LightYb"
+ )
[1] TRUE
> is(
+ diffChr(
+ letters, LETTERS, style="auto", format="auto", brightness="light",
+ term.colors=8
+ )@etc@style,
+ "StyleAnsi8NeutralYb"
+ )
[1] TRUE
> is(
+ diffChr(
+ letters, LETTERS, style="auto", format="auto", interactive=FALSE,
+ term.colors=1
+ )@etc@style,
+ "StyleRaw"
+ )
[1] TRUE
> is(
+ diffChr(
+ letters, LETTERS, style="auto", format="auto", interactive=TRUE,
+ term.colors=1 # note pager off by default in tests
+ )@etc@style,
+ "StyleRaw"
+ )
[1] TRUE
> is(
+ diffChr(
+ letters, LETTERS, style="auto", format="auto", interactive=TRUE,
+ pager="auto", term.colors=1
+ )@etc@style,
+ "StyleHtml"
+ )
[1] TRUE
> is(
+ diffChr(
+ letters, LETTERS, style="auto", format="auto", interactive=TRUE,
+ pager="auto", term.colors=9
+ )@etc@style,
+ "StyleAnsi8NeutralYb"
+ )
[1] TRUE
> is(
+ diffChr(
+ letters, LETTERS, style="auto", format="auto", interactive=TRUE,
+ pager="auto", brightness='light', term.colors=500
+ )@etc@style,
+ "StyleAnsi256LightYb"
+ )
[1] TRUE
> is(
+ diffChr(
+ letters, LETTERS, style="auto", format="html", interactive=TRUE,
+ pager="auto", color.mode=c("rgb", ansi8="yb")
+ )@etc@style,
+ "StyleHtmlLightRgb"
+ )
[1] TRUE
> is(
+ diffChr(
+ letters, LETTERS, style="auto", format="html", interactive=TRUE,
+ pager="auto", color.mode=c("rgb", html="yb")
+ )@etc@style,
+ "StyleHtmlLightYb"
+ )
[1] TRUE
> ## - Palette Params ------------------------------------------------------------
>
> all.equal(
+ as.character(
+ diffChr(
+ letters, LETTERS, style="auto", format="ansi256",
+ brightness=c("light", ansi256="dark")
+ ) ),
+ rdsf(500)
+ )
[1] TRUE
> all.equal(
+ as.character(
+ diffChr(
+ letters, LETTERS, style="auto", format="ansi256", brightness=c("dark")
+ ) ),
+ rdsf(500)
+ )
[1] TRUE
> ## - Style Validation ----------------------------------------------------------
>
> s.f <- StyleFuns()
> isTRUE(validObject(s.f))
[1] TRUE
> s.f@word.insert <- function(x, y) NULL
> try(validObject(s.f)) # word.insert
Error in validObject(s.f) :
invalid class "StyleFuns" object: Argument `word.insert` may not have non-default formals argument after the first.
>
> try(diffChr(1,2, format='html', style=list(scale=1:3)))
Error in diffChr(target = 1, current = 2, format = "html", style = list(scale = 1:3)) :
Unable to instantiate `Style` object: Argument `scale` must be TRUE or FALSE
> try(diffChr(1,2, format='html', style=list(html.output="a")))
Error in diffChr(target = 1, current = 2, format = "html", style = list(html.output = "a")) :
Unable to instantiate `Style` object: Argument `html.output` must be in `c("auto", "page", "diff.only", "diff.w.style")`.
>
> ## - Pallette w/ Objs ----------------------------------------------------------
>
> pal <- PaletteOfStyles()
> pal["raw", "neutral", "rgb"] <- list(new(pal[["raw", "neutral", "rgb"]]))
>
> suppressWarnings(
+ withCallingHandlers(
+ invisible(diffChr(
+ letters, LETTERS, format="raw", brightness="neutral", color.mode="rgb",
+ palette.of.styles=pal, style=list(na.sub="NA")
+ )),
+ warning=function(e) writeLines(conditionMessage(e))
+ )
+ )
Extra `style` arguments cannot be applied because selected object `palette.of.styles` is a `Style` instance rather than a `Style` "classRepresentation". See documentation for the `style` parameter for details.
> ## - External Files ------------------------------------------------------------
>
> isTRUE(file_test("-f", diffobj_css()))
[1] TRUE
> isTRUE(file_test("-f", diffobj_js()))
[1] TRUE
>
> proc.time()
user system elapsed
3.692 0.414 4.303
|