File: test-style.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 (159 lines) | stat: -rwxr-xr-x 4,133 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
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
NAME <- "style"
source(file.path('_helper', 'init.R'))

## - Style Palette ------------------------------------------------------------

all.equal(
  capture.output(diffobj:::display_ansi_256_styles()),
  rdsf(100)
)
## - 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")
})
## - Palette of Styles ---------------------------------------------------------

pos <- PaletteOfStyles()
identical(
  pos[["ansi256", "light", "rgb"]],
  getClassDef("StyleAnsi256LightRgb", package="diffobj", inherits=FALSE)
)
all.equal(
  capture.output(show(pos)), rdsf(300)
)
all.equal(
  capture.output(summary(pos)), rdsf(400)
)

pos["ansi256", "light", "yb"] <- list(StyleRaw())
all.equal(
  c(pos["ansi256", "light", "yb"]@data), list(StyleRaw()),
  check.environment=FALSE
)
all.equal(
  pos[["ansi256", "light", "yb"]], StyleRaw(),
  check.environment=FALSE
)

## - Auto Styles ---------------------------------------------------------------

try(diffChr(letters, LETTERS, style="auto", format="xml"))
is(
  diffChr(
    letters, LETTERS, style="auto", format="auto", brightness="light",
    term.colors=256
  )@etc@style,
  "StyleAnsi256LightYb"
)
is(
  diffChr(
    letters, LETTERS, style="auto", format="auto", brightness="light",
    term.colors=8
  )@etc@style,
  "StyleAnsi8NeutralYb"
)
is(
  diffChr(
    letters, LETTERS, style="auto", format="auto", interactive=FALSE,
    term.colors=1
  )@etc@style,
  "StyleRaw"
)
is(
  diffChr(
    letters, LETTERS, style="auto", format="auto", interactive=TRUE,
    term.colors=1  # note pager off by default in tests
  )@etc@style,
  "StyleRaw"
)
is(
  diffChr(
    letters, LETTERS, style="auto", format="auto", interactive=TRUE,
    pager="auto", term.colors=1
  )@etc@style,
  "StyleHtml"
)
is(
  diffChr(
    letters, LETTERS, style="auto", format="auto", interactive=TRUE,
    pager="auto", term.colors=9
  )@etc@style,
  "StyleAnsi8NeutralYb"
)
is(
  diffChr(
    letters, LETTERS, style="auto", format="auto", interactive=TRUE,
    pager="auto", brightness='light', term.colors=500
  )@etc@style,
  "StyleAnsi256LightYb"
)
is(
  diffChr(
    letters, LETTERS, style="auto", format="html", interactive=TRUE,
    pager="auto", color.mode=c("rgb", ansi8="yb")
  )@etc@style,
  "StyleHtmlLightRgb"
)
is(
  diffChr(
    letters, LETTERS, style="auto", format="html", interactive=TRUE,
    pager="auto", color.mode=c("rgb", html="yb")
  )@etc@style,
  "StyleHtmlLightYb"
)
## - Palette Params ------------------------------------------------------------

all.equal(
  as.character(
    diffChr(
      letters, LETTERS, style="auto", format="ansi256",
      brightness=c("light", ansi256="dark")
  ) ),
  rdsf(500)
)
all.equal(
  as.character(
    diffChr(
      letters, LETTERS, style="auto", format="ansi256", brightness=c("dark")
  ) ),
  rdsf(500)
)
## - Style Validation ----------------------------------------------------------

s.f <- StyleFuns()
isTRUE(validObject(s.f))
s.f@word.insert <- function(x, y) NULL
try(validObject(s.f)) # word.insert

try(diffChr(1,2, format='html', style=list(scale=1:3)))
try(diffChr(1,2, format='html', style=list(html.output="a")))

## - 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))
  )
)
## - External Files ------------------------------------------------------------

isTRUE(file_test("-f", diffobj_css()))
isTRUE(file_test("-f", diffobj_js()))