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 <- "style" 19> source(file.path('_helper', 'init.R')) 20> 21> ## - Style Palette ------------------------------------------------------------ 22> 23> all.equal( 24+ capture.output(diffobj:::display_ansi_256_styles()), 25+ rdsf(100) 26+ ) 27[1] TRUE 28> ## - crayon settings ----------------------------------------------------------- 29> 30> # make sure crayon options are appropriately overriden 31> local({ 32+ old.opt <- options(crayon.enabled=FALSE) 33+ on.exit(options(old.opt)) 34+ print(identical(crayon::green("green"), "green")) 35+ # should have ANSI coloring despite crayon disabled 36+ print( 37+ all.equal( 38+ as.character(diffChr(letters[1:3], LETTERS[1:3])), rdsf(200) 39+ ) 40+ ) 41+ identical(crayon::green("green"), "green") 42+ }) 43[1] TRUE 44[1] TRUE 45[1] TRUE 46> ## - Palette of Styles --------------------------------------------------------- 47> 48> pos <- PaletteOfStyles() 49> identical( 50+ pos[["ansi256", "light", "rgb"]], 51+ getClassDef("StyleAnsi256LightRgb", package="diffobj", inherits=FALSE) 52+ ) 53[1] TRUE 54> all.equal( 55+ capture.output(show(pos)), rdsf(300) 56+ ) 57[1] TRUE 58> all.equal( 59+ capture.output(summary(pos)), rdsf(400) 60+ ) 61[1] TRUE 62> 63> pos["ansi256", "light", "yb"] <- list(StyleRaw()) 64> all.equal( 65+ c(pos["ansi256", "light", "yb"]@data), list(StyleRaw()), 66+ check.environment=FALSE 67+ ) 68[1] TRUE 69> all.equal( 70+ pos[["ansi256", "light", "yb"]], StyleRaw(), 71+ check.environment=FALSE 72+ ) 73[1] TRUE 74> 75> ## - Auto Styles --------------------------------------------------------------- 76> 77> try(diffChr(letters, LETTERS, style="auto", format="xml")) 78Error in diffChr(target = letters, current = LETTERS, style = "auto", : 79 Argument `format` must be one of `c("auto", "raw", "ansi8", "ansi256", "html")`. 80> is( 81+ diffChr( 82+ letters, LETTERS, style="auto", format="auto", brightness="light", 83+ term.colors=256 84+ )@etc@style, 85+ "StyleAnsi256LightYb" 86+ ) 87[1] TRUE 88> is( 89+ diffChr( 90+ letters, LETTERS, style="auto", format="auto", brightness="light", 91+ term.colors=8 92+ )@etc@style, 93+ "StyleAnsi8NeutralYb" 94+ ) 95[1] TRUE 96> is( 97+ diffChr( 98+ letters, LETTERS, style="auto", format="auto", interactive=FALSE, 99+ term.colors=1 100+ )@etc@style, 101+ "StyleRaw" 102+ ) 103[1] TRUE 104> is( 105+ diffChr( 106+ letters, LETTERS, style="auto", format="auto", interactive=TRUE, 107+ term.colors=1 # note pager off by default in tests 108+ )@etc@style, 109+ "StyleRaw" 110+ ) 111[1] TRUE 112> is( 113+ diffChr( 114+ letters, LETTERS, style="auto", format="auto", interactive=TRUE, 115+ pager="auto", term.colors=1 116+ )@etc@style, 117+ "StyleHtml" 118+ ) 119[1] TRUE 120> is( 121+ diffChr( 122+ letters, LETTERS, style="auto", format="auto", interactive=TRUE, 123+ pager="auto", term.colors=9 124+ )@etc@style, 125+ "StyleAnsi8NeutralYb" 126+ ) 127[1] TRUE 128> is( 129+ diffChr( 130+ letters, LETTERS, style="auto", format="auto", interactive=TRUE, 131+ pager="auto", brightness='light', term.colors=500 132+ )@etc@style, 133+ "StyleAnsi256LightYb" 134+ ) 135[1] TRUE 136> is( 137+ diffChr( 138+ letters, LETTERS, style="auto", format="html", interactive=TRUE, 139+ pager="auto", color.mode=c("rgb", ansi8="yb") 140+ )@etc@style, 141+ "StyleHtmlLightRgb" 142+ ) 143[1] TRUE 144> is( 145+ diffChr( 146+ letters, LETTERS, style="auto", format="html", interactive=TRUE, 147+ pager="auto", color.mode=c("rgb", html="yb") 148+ )@etc@style, 149+ "StyleHtmlLightYb" 150+ ) 151[1] TRUE 152> ## - Palette Params ------------------------------------------------------------ 153> 154> all.equal( 155+ as.character( 156+ diffChr( 157+ letters, LETTERS, style="auto", format="ansi256", 158+ brightness=c("light", ansi256="dark") 159+ ) ), 160+ rdsf(500) 161+ ) 162[1] TRUE 163> all.equal( 164+ as.character( 165+ diffChr( 166+ letters, LETTERS, style="auto", format="ansi256", brightness=c("dark") 167+ ) ), 168+ rdsf(500) 169+ ) 170[1] TRUE 171> ## - Style Validation ---------------------------------------------------------- 172> 173> s.f <- StyleFuns() 174> isTRUE(validObject(s.f)) 175[1] TRUE 176> s.f@word.insert <- function(x, y) NULL 177> try(validObject(s.f)) # word.insert 178Error in validObject(s.f) : 179 invalid class "StyleFuns" object: Argument `word.insert` may not have non-default formals argument after the first. 180> 181> try(diffChr(1,2, format='html', style=list(scale=1:3))) 182Error in diffChr(target = 1, current = 2, format = "html", style = list(scale = 1:3)) : 183 Unable to instantiate `Style` object: Argument `scale` must be TRUE or FALSE 184> try(diffChr(1,2, format='html', style=list(html.output="a"))) 185Error in diffChr(target = 1, current = 2, format = "html", style = list(html.output = "a")) : 186 Unable to instantiate `Style` object: Argument `html.output` must be in `c("auto", "page", "diff.only", "diff.w.style")`. 187> 188> ## - Pallette w/ Objs ---------------------------------------------------------- 189> 190> pal <- PaletteOfStyles() 191> pal["raw", "neutral", "rgb"] <- list(new(pal[["raw", "neutral", "rgb"]])) 192> 193> suppressWarnings( 194+ withCallingHandlers( 195+ invisible(diffChr( 196+ letters, LETTERS, format="raw", brightness="neutral", color.mode="rgb", 197+ palette.of.styles=pal, style=list(na.sub="NA") 198+ )), 199+ warning=function(e) writeLines(conditionMessage(e)) 200+ ) 201+ ) 202Extra `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. 203> ## - External Files ------------------------------------------------------------ 204> 205> isTRUE(file_test("-f", diffobj_css())) 206[1] TRUE 207> isTRUE(file_test("-f", diffobj_js())) 208[1] TRUE 209> 210> proc.time() 211 user system elapsed 212 3.692 0.414 4.303 213