1library(fansi) 2 3unitizer_sect('basic tests', { 4 nchar_ctl(c('hello', 'world')) 5 nchar_ctl(c('hello', 'world'), type='width') 6 nchar_ctl(c('hello', 'world'), type='wi') # partial match 7 8 # Keep NA 9 10 na.world <- c('hello', NA, 'world') 11 nchar_ctl(na.world) 12 nchar_ctl(na.world, keepNA=FALSE) 13 nchar_ctl(na.world, keepNA=NA, type='width') 14 nchar_ctl(na.world, keepNA=TRUE, type='width') 15 16 nzchar_ctl(na.world) 17 nzchar_ctl(na.world, keepNA=NA) 18 nzchar_ctl(na.world, keepNA=TRUE) 19 20}) 21unitizer_sect('with escapes', { 22 esc.2 <- "\n\r\033P\033[31m\a" 23 24 nchar_ctl(esc.2) 25 nchar_ctl(esc.2, warn=FALSE) 26 nzchar_ctl(esc.2) 27 nzchar_ctl(esc.2, warn=FALSE) 28 29 # not an SGR 30 31 nchar_ctl("\033[31#mworld", ctl="sgr") 32 nchar_ctl("\033[31#mworld", ctl="csi") 33}) 34unitizer_sect('ctl', { 35 esc.3 <- "\n\t\033[31m\033[41!m\033p" 36 nzchar_ctl(esc.3, warn=FALSE) 37 nzchar_ctl(sprintf("%sa", esc.3), warn=FALSE) 38 nzchar_ctl(esc.3, ctl=c('sgr', 'csi', 'esc'), warn=FALSE) 39 nzchar_ctl(esc.3, ctl=c('c0', 'nl'), warn=FALSE) 40 nzchar_ctl("\n\t\n", ctl=c('nl'), warn=FALSE) 41 nzchar_ctl("\t\n", ctl=c('nl'), warn=FALSE) 42}) 43unitizer_sect('bad inputs', { 44 nchar_ctl(9:10, warn=1:3) 45 nchar_ctl("hello\033[31m world", allowNA=1:3) 46 nchar_ctl("hello\033[31m world", keepNA=1:3) 47 nchar_ctl("hello\033[31m world", strip=1:3) 48 nchar_ctl("hello\033[31m world", ctl="bananas") 49 nchar_ctl("hello\033[31m world", type=NA_character_) 50 nchar_ctl("hello\033[31m world", type=1) 51 nchar_ctl("hello\033[31m world", type="bananas") 52 53 nzchar_ctl(9:10, warn=1:3) 54 nzchar_ctl("hello\033[31m world", keepNA=1:3) 55 nzchar_ctl("hello\033[31m world", ctl=1) 56 nzchar_ctl("hello\033[31m world", ctl="bananas") 57}) 58