Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brodieG committed Jun 27, 2021
1 parent 2973b17 commit b4a2cfc
Show file tree
Hide file tree
Showing 17 changed files with 109 additions and 11 deletions.
1 change: 1 addition & 0 deletions tests/run.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ if(getRversion() < "3.2.2") {
)
on.exit(old.opt)
pattern <- "^[^.].*\\.[Rr]$"
# pattern <- "wrap"
unitize_dir(
'unitizer',
pattern=pattern,
Expand Down
10 changes: 8 additions & 2 deletions tests/special/_pre/funs.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@

## Helpers to extract the condition message only due to instability in
## C level error/warning in displaying the call or not
## C level error/warning in displaying the call or not.
##
## This seems to be related to whether functions are byte compiled or not, with
## non-bc ones not getting the call. Possible we stopped seeing issues with the
## advent of always byte compiling packages.

tce <- function(x) tryCatch(x, error=conditionMessage)
tcw <- function(x) tryCatch(x, warning=conditionMessage)

## writeLines!
wl <- function(x) writeLines(c(x, "\033[m"))
Binary file modified tests/special/utf8.unitizer/data.rds
Binary file not shown.
4 changes: 3 additions & 1 deletion tests/unitizer/_pre/funs.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

## Helpers to extract the condition message only due to instability in
## C level error/warning in displaying the call or not

tce <- function(x) tryCatch(x, error=conditionMessage)
tcw <- function(x) tryCatch(x, warning=conditionMessage)

## writeLines!
wl <- function(x) writeLines(c(x, "\033[m"))
3 changes: 3 additions & 0 deletions tests/unitizer/interactions.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ unitizer_sect("carry corner cases", {
strwrap_sgr(wrp.0, 20, carry=character())
strwrap2_ctl(wrp.0, 20, carry=1)
strwrap2_sgr(wrp.0, 20, carry=Inf)

## leading SGR consumed and merged with carry
strwrap_ctl(c("\033[33mA \033[4mB", "\033[44mC D"), carry=TRUE, 2)
})

unitizer_sect("terminate", {
Expand Down
Binary file modified tests/unitizer/interactions.unitizer/data.rds
Binary file not shown.
Binary file modified tests/unitizer/misc.unitizer/data.rds
Binary file not shown.
Binary file modified tests/unitizer/normalize.unitizer/data.rds
Binary file not shown.
13 changes: 11 additions & 2 deletions tests/unitizer/overflow.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ unitizer_sect('wrap', {
tce(strwrap_ctl(string4, 16))

## Overflow when wrap adds a closing tag
invisible(fansi:::set_int_max(12))
tce(strwrap_ctl("hello\033[31m a", 5))
invisible(fansi:::set_int_max(9))
tce(strwrap_ctl("A\033[31m a", 5))
})
unitizer_sect('html', {
invisible(fansi:::set_int_max(38))
Expand Down Expand Up @@ -94,8 +94,17 @@ unitizer_sect('size buffer', {
dat['smaller 2.0', 'prev'] == dat['grow 2.0', 'prev']
dat['grow 1.1', 'prev'] == dat['grow 2.0', 'self']
dat['grow 2.1', 'prev'] == dat['grow 1.1', 'self']
})
unitizer_sect('misc', {
invisible(fansi:::set_int_max(5))
# this is from trying to create result matrix names, so need longer than that
# to test other stuff
substr_ctl("\033[43mA B", 5, 5)


## this caused a segfault due to missing comma in error(...)
invisible(fansi:::set_int_max(1L))
substr_ctl("1", 2, 2)
})

new_max <- fansi:::set_int_max(old_max)
Binary file modified tests/unitizer/overflow.unitizer/data.rds
Binary file not shown.
39 changes: 35 additions & 4 deletions tests/unitizer/strip.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ unitizer_sect("Whitespace", {
fansi:::process('hello? ')

# Tabs / ctrl; newlines remain

fansi:::process(' \t hello')
fansi:::process(' \t\a\r hello')
fansi:::process(' \t\a\r hello', ctl=c("all", "c0"))

# interactiong between punct and ctrl

fansi:::process('hello. \r world.')

# CSIs

fansi:::process('hello. \033[31m world.\033[0m')

# Make sure we are not inadvertently changing SXPs
Expand All @@ -64,7 +62,6 @@ unitizer_sect("Whitespace", {
str1

# Paragraphs and so on

fansi:::process('hello.\n\nworld')
fansi:::process('hello.\n\n\nworld')
fansi:::process('hello.\n\n\n\nworld')
Expand All @@ -76,6 +73,40 @@ unitizer_sect("Whitespace", {
fansi:::process('hello.\n\nworld\n\n ')
fansi:::process('\n\nhello.\n\t\n\tworld\n\t\n woohoo\n ')
fansi:::process('\n \t\nhello.\n\t\n\tworld\n\t\n woohoo\n ')

# corner cases
fansi:::process('hello.\n\033[44m\nworld')
fansi:::process('hello.\n\033[44m\n \t\nworld')
fansi:::process('hello.\033[44m\n\n \t\nworld')
fansi:::process('hello.\n\n \t\n\033[44mworld')
fansi:::process('hello.\n\n\033[44m \t\nworld')

fansi:::process('hello \033[44m world')
fansi:::process("hello. \033[44m world")

fansi:::process('hello\033[44m\033[31m world')
fansi:::process('hello\033[44m\033[31m\n\nworld')
fansi:::process('hello\n\033[44m\033[31m\nworld')
fansi:::process('hello\n\n\033[44m\033[31mworld')

fansi:::process('hello\033[44m\033[31d world')
fansi:::process('hello \033[44m\033[31d world')
fansi:::process('hello \033[44m \033[31d world')
fansi:::process('hello\033[44m\033[31d world', ctl=c("all", "csi"))
fansi:::process('hello \033[44m\033[31d world', ctl=c("all", "csi"))
fansi:::process('hello \033[44m \033[31d world', ctl=c("all", "csi"))
fansi:::process('hello\033[44m\a world', ctl=c("all"))
fansi:::process('hello\033[44m\a world', ctl=c("all", "c0"))
fansi:::process('hello. \033[44m\a world', ctl=c("all"))
fansi:::process('hello. \033[44m\a world', ctl=c("all", "c0"))
fansi:::process('hello. \033[44m \a world', ctl=c("all"))
fansi:::process('hello. \033[44m \a world', ctl=c("all", "c0"))
fansi:::process('hello.\n\033[44m \a world', ctl=c("all"))
fansi:::process('hello.\n\033[44m \a world', ctl=c("all", "c0"))
fansi:::process('hello.\n\033[44m\n\a world', ctl=c("all"))
fansi:::process('hello.\n\033[44m\n\a world', ctl=c("all", "c0"))
fansi:::process('hello.\n\033[44m\a\n world', ctl=c("all"))
fansi:::process('hello.\n\033[44m\a\n world', ctl=c("all", "c0"))
})
unitizer_sect("Selective stripping", {
string.0 <- "hello\033k\033[45p world\n\033[31mgoodbye\a moon"
Expand Down
Binary file modified tests/unitizer/strip.unitizer/data.rds
Binary file not shown.
Binary file modified tests/unitizer/strsplit.unitizer/data.rds
Binary file not shown.
14 changes: 14 additions & 0 deletions tests/unitizer/substr.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ unitizer_sect("Corner cases", {

substr_ctl(str.2, -1, 2)
substr_ctl(str.2, -2, -1)
substr_ctl(str.2, 4, 1)
substr_ctl(str.2, 4, 1, terminate=FALSE)
substr_ctl(str.2, 4, 1, carry="\033[44m")
substr_ctl(str.2, 4, 1, carry="\033[44m", terminate=FALSE)

substr_ctl("hello", 5, 5)
substr_ctl("hello", 6, 6)
Expand Down Expand Up @@ -117,6 +121,10 @@ unitizer_sect("Corner cases", {

# Make sure things stay in order
substr2_ctl(rep("o\033[31m ", 2), 1:2, 1:2)

# bad sequence at beginning or end
substr_ctl("\033[41bhello", 1, 5)
substr_ctl("hello\033[41b", 1, 5)
})
unitizer_sect("Obscure escapes", {
# illegal 38/48
Expand Down Expand Up @@ -215,4 +223,10 @@ unitizer_sect('`ctl` related issues', {
substr_sgr("ab\n\033[31m\tcd\n", 3, 6, warn=FALSE)
substr_ctl("ab\n\033[31m\tcd\n", 3, 6, warn=FALSE, ctl=c('all', 'nl'))
substr_ctl("ab\n\033[31m\tcd\n", 3, 6, warn=FALSE, ctl=c('all', 'nl', 'c0'))

# Index reporting

substr_sgr(c("\a", "b", "c"), 1, 1)
substr_sgr(c("a", "\b", "c"), 1, 1)
substr_sgr(c("a", "b", "\ac"), 1, 1)
})
Binary file modified tests/unitizer/substr.unitizer/data.rds
Binary file not shown.
36 changes: 34 additions & 2 deletions tests/unitizer/wrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ unitizer_sect("Basic Ansi", {
"normal \033[6mblinking quickly oh my\033[25m normal"
)
strwrap_ctl(hello.blinky, 10)
strwrap_ctl(hello.blinky, 10, terminate=FALSE)

# simplify

Expand Down Expand Up @@ -256,14 +257,15 @@ unitizer_sect("rare escapes", {
"hello \033[53mworld woohoo\033[55m woohoo"
)
strwrap_ctl(hello.border, 12)
strwrap_ctl(hello.border, 12, terminate=FALSE)
hello.ideogram <- c(
"hello \033[60mworld woohoo\033[65m woohoo",
"hello \033[61mworld woohoo\033[65m woohoo",
"hello \033[62mworld woohoo\033[65m woohoo",
"hello \033[63mworld woohoo\033[65m woohoo",
"hello \033[64mworld woohoo\033[65m woohoo"
)
strwrap_ctl(hello.ideogram, 12)
strwrap_ctl(hello.ideogram, 12, terminate=FALSE)
hello.font <- c(
"hello \033[10mworld woohoo\033[10m woohoo",
"hello \033[11mworld woohoo\033[10m woohoo",
Expand All @@ -276,7 +278,7 @@ unitizer_sect("rare escapes", {
"hello \033[18mworld woohoo\033[10m woohoo",
"hello \033[19mworld woohoo\033[10m woohoo"
)
strwrap_ctl(hello.font, 12)
strwrap_ctl(hello.font, 12, terminate=FALSE)
})
unitizer_sect("term cap and bright", {
# default term cap should recognize bright and 256, but not true color.
Expand Down Expand Up @@ -332,6 +334,36 @@ unitizer_sect("corner cases", {
## dropped, and _trailing_ SGR should be dropped.
strwrap_ctl("hello world\033[31m\033A", 12)
strwrap_ctl("hello world\033A\033[31m", 12)

# Islanded SGR escape sequence
strwrap_ctl("hello \033[44m world", 5)
strwrap_ctl("hello \033[44m world", 6)
strwrap_ctl("hello \033[44m world", 5, terminate=FALSE)
strwrap_ctl("hello \033[44m world", 6, terminate=FALSE)

strwrap_ctl("hello\n\033[44m\nworld", 5)
strwrap_ctl("hello \n\033[44m\n world", 5)
strwrap_ctl("hello \n \033[44m\n world", 5)
strwrap_ctl("hello \n \n\033[44mworld", 5)
strwrap_ctl("hello \n \n\033[44m world", 5)
strwrap_ctl("hello \n \n\033[44m\nworld", 5)
strwrap_ctl("hello \033[44m\n\n world", 5)
strwrap("hello \n\n world", 5)

## Trailing SGR followed by word break
strwrap_ctl("\033[33mAB\033[44m CD", 3)

## New paragraph with wrap.always and trailing SGR
strwrap2_ctl("AB\033[44m\n\nCD", 3, wrap.always=TRUE)
strwrap2_ctl("AB\033[44m\n\nCD", 3, wrap.always=TRUE, pad.end="#")
strwrap2_ctl("AB\033[44m\n\nCD", 3, wrap.always=TRUE, terminate=FALSE)

## Don't omit trail SGR when there is padding
strwrap2_ctl("AB\033[44m CD", 4, pad.end="#")
strwrap2_ctl("AB\033[44m CD", 3, pad.end="#")

## Combine Leading SGR without stripping spaces
strwrap2_sgr("\033[43mAB \033[34mCD", strip.spaces=FALSE, 4)
})
unitizer_sect("bad inputs", {
strwrap_ctl(1:3)
Expand Down
Binary file modified tests/unitizer/wrap.unitizer/data.rds
Binary file not shown.

0 comments on commit b4a2cfc

Please sign in to comment.