Skip to content

Commit

Permalink
#4, #5: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gagolews committed Aug 5, 2021
1 parent 7ae8715 commit 04ca583
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 43 deletions.
5 changes: 4 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# What Is New in *stringx*


## 0.1.2.9xxx (under development)

* ...
* [BUGFIX] #4: Fixed failing check with ICU 55.

* [BUGFIX] #5: Fixed failing check under POSIX/C locale.


## 0.1.2 (2021-07-27)
Expand Down
12 changes: 6 additions & 6 deletions R/grepl.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@
#'
#' @examples
#' x <- c("abc", "1237", "\U0001f602", "\U0001f603", "stringx\U0001f970", NA)
#' grepl2(x, "\\p{EMOJI_PRESENTATION}")
#' which(grepl2(x, "\\p{EMOJI_PRESENTATION}")) # like grep
#' grepl2(x, "\\p{L}")
#' which(grepl2(x, "\\p{L}")) # like grep
#'
#' # at least 1 letter, digit, or emoji:
#' p <- c("\\p{L}", "\\p{N}", "\\p{EMOJI_PRESENTATION}")
#' # at least 1 letter or digit:
#' p <- c("\\p{L}", "\\p{N}")
#' `dimnames<-`(outer(x, p, grepl2), list(x, p))
#'
#' x |> grepv2("\\p{EMOJI_PRESENTATION}")
#' grepv2(x, "\\p{EMOJI_PRESENTATION}", invert=TRUE) <- "\U0001F496"
#' x |> grepv2("\\p{L}")
#' grepv2(x, "\\p{L}", invert=TRUE) <- "\U0001F496"
#' print(x)
#'
#' @seealso
Expand Down
2 changes: 1 addition & 1 deletion R/gsub.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
#'
#'
#' @examples
#' "change \U0001f602 me \U0001f603" |> gsub2("\\p{EMOJI_PRESENTATION}", "O_O")
#' "change \U0001f602 me \U0001f603" |> gsub2("\\p{L}+", "O_O")
#'
#' x <- c("mario", "Mario", "M\u00E1rio", "M\u00C1RIO", "Mar\u00EDa", "Rosario", NA)
#' sub2(x, "mario", "M\u00E1rio", fixed=NA, strength=1L)
Expand Down
24 changes: 16 additions & 8 deletions inst/realtest/gregexpr-stringx.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ E(

E(
regexpr2(x, "mario", fixed=NA, ignore_case=TRUE)!=-1L,
c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, NA)
c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, NA),
bad=c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NA) # C locale
)

E(
regexpr2(x, "mario", fixed=NA, strength=1L)!=-1L,
c(TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NA)
c(TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NA),
bad=c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NA) # C locale
)


Expand All @@ -43,30 +45,36 @@ E(

E(
unlist(gregexpr2(x, "mario", fixed=NA, ignore_case=TRUE))!=-1L,
c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, NA)
c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, NA),
bad=c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NA) # C locale
)

E(
unlist(gregexpr2(x, "mario", fixed=NA, strength=1L))!=-1L,
c(TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NA)
c(TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NA),
bad=c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NA) # C locale
)

E(
unlist(regexec2(x, "mario", fixed=NA, ignore_case=TRUE))!=-1L,
c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, NA)
c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, NA),
bad=c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NA) # C locale
)

E(
unlist(regexec2(x, "mario", fixed=NA, strength=1L))!=-1L,
c(TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NA)
c(TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NA),
bad=c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NA) # C locale
)

E(
unlist(gregexec2(x, "mario", fixed=NA, ignore_case=TRUE))!=-1L,
c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, NA)
c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, NA),
bad=c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NA) # C locale
)

E(
unlist(gregexec2(x, "mario", fixed=NA, strength=1L))!=-1L,
c(TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NA)
c(TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NA),
bad=c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NA) # C locale
)
26 changes: 22 additions & 4 deletions inst/realtest/gregextr-stringx.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ x <- c("mario", "Mario M\u00E1rio M\u00C1RIO Mar\u00EDa Marios", "Rosario", NA)
E(regextr2(x, "mario", ignore_case=TRUE, fixed=TRUE), c("mario", "Mario", NA, NA))
E(gregextr2(x, "mario", ignore_case=TRUE, fixed=TRUE), list("mario", c("Mario", "Mario"), character(0), NA_character_))

E(regextr2(x, "mario", fixed=NA, strength=1L), c("mario", "Mario", NA, NA))
E(gregextr2(x, "mario", fixed=NA, strength=1L), list("mario", c("Mario", "M\u00E1rio", "M\u00C1RIO", "Mario"), character(0), NA_character_))
E(
regextr2(x, "mario", fixed=NA, strength=1L),
c("mario", "Mario", NA, NA),
bad=c("mario", NA, NA, NA) # C locale
)
E(
gregextr2(x, "mario", fixed=NA, strength=1L),
list("mario", c("Mario", "M\u00E1rio", "M\u00C1RIO", "Mario"), character(0), NA_character_),
bad=list("mario", character(0), character(0), NA_character_) # C locale
)

E(regextr2(x, "m(?<a>[a\u00E1])rio(?<plural>s)?", ignore_case=TRUE), c("mario", "Mario", NA, NA))
E(gregextr2(x, "m(?<a>[a\u00E1])rio(?<plural>s)?", ignore_case=TRUE), list("mario", c("Mario", "M\u00E1rio", "M\u00C1RIO", "Marios"), character(0), NA_character_))
Expand All @@ -44,7 +52,11 @@ E(
)
)

E(regextr2(x, "mario", fixed=NA, strength=1L, capture_groups=TRUE), list("mario", "Mario", NA_character_, NA_character_))
E(
regextr2(x, "mario", fixed=NA, strength=1L, capture_groups=TRUE),
list("mario", "Mario", NA_character_, NA_character_),
bad=list("mario", NA_character_, NA_character_, NA_character_) # C locale
)

E(
gregextr2(x, "mario", fixed=NA, strength=1L, capture_groups=TRUE),
Expand All @@ -53,7 +65,13 @@ E(
cbind("Mario", "M\u00E1rio", "M\u00C1RIO", "Mario"),
cbind(NA_character_)[, -1, drop=FALSE],
cbind(NA_character_)
)
),
bad=list(
cbind("mario"),
cbind(NA_character_)[, -1, drop=FALSE],
cbind(NA_character_)[, -1, drop=FALSE],
cbind(NA_character_)
) # C locale
)

E(`regextr2<-`(x, "[mM]\\w+", value="x"), c("x", "x M\u00E1rio M\u00C1RIO Mar\u00EDa Marios", "Rosario", NA))
Expand Down
12 changes: 10 additions & 2 deletions inst/realtest/grepl-stringx.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ x <- c("mario", "Mario", "M\u00E1rio", "M\u00C1RIO", "Mar\u00EDa", "Rosario", NA
E(grepl2(x, "mario"), c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NA))
E(grepl2(x, "mario", fixed=NA), c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NA))
E(grepl2(x, "mario", ignore_case=TRUE), c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, NA))
E(grepl2(x, "mario", fixed=NA, ignore_case=TRUE), c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, NA))
E(grepl2(x, "mario", fixed=NA, strength=1L), c(TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NA))
E(
grepl2(x, "mario", fixed=NA, ignore_case=TRUE),
c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, NA),
bad=c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NA) # C locale
)
E(
grepl2(x, "mario", fixed=NA, strength=1L),
c(TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NA),
bad=c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NA) # C locale
)

E(grepl2("abc", ".{3,3}"), TRUE) # default fixed=FALSE

Expand Down
6 changes: 4 additions & 2 deletions inst/realtest/nchar-all.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ E(
E(
nchar(x, "width", keepNA=FALSE),
c(1L, 0L, 2L, 1L, 8L, 6L, 2L, 2L),
bad=c(1L, 0L, 2L, 1L, 8L, 6L, 2L, 4L)
bad=c(1L, 0L, 2L, 1L, 8L, 6L, 2L, 4L),
bad=c(1L, 0L, 2L, 1L, 8L, 6L, 2L, 3L)
)

E(
nchar(x, "width", keepNA=TRUE),
c(1L, 0L, NA, 1L, 8L, 6L, 2L, 2L),
bad=c(1L, 0L, NA, 1L, 8L, 6L, 2L, 4L)
bad=c(1L, 0L, NA, 1L, 8L, 6L, 2L, 4L),
bad=c(1L, 0L, NA, 1L, 8L, 6L, 2L, 3L)
)

E(
Expand Down
26 changes: 22 additions & 4 deletions inst/realtest/startswith-stringx.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,26 @@ E(endsWith(x, "mario", fixed=NA), c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NA)
E(startsWith(x, "mario", ignore_case=TRUE), c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, NA))
E(endsWith(x, "mario", ignore_case=TRUE), c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, NA))

E(startsWith(x, "mario", fixed=NA, ignore_case=TRUE), c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, NA))
E(endsWith(x, "mario", fixed=NA, ignore_case=TRUE), c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, NA))
E(
startsWith(x, "mario", fixed=NA, ignore_case=TRUE),
c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, NA),
bad=c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NA) # C locale
)

E(startsWith(x, "mario", fixed=NA, strength=1L), c(TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NA))
E(endsWith(x, "mario", fixed=NA, strength=1L), c(TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NA))
E(
endsWith(x, "mario", fixed=NA, ignore_case=TRUE),
c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, NA),
bad=c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NA) # C locale
)

E(
startsWith(x, "mario", fixed=NA, strength=1L),
c(TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NA),
bad=c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NA) # C locale
)

E(
endsWith(x, "mario", fixed=NA, strength=1L),
c(TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NA),
bad=c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NA) # C locale
)
1 change: 0 additions & 1 deletion inst/realtest/strcoll-stringx.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ E(x %x==% y, x == y)
E(x %x!=% y, x != y)
E(x %x>% y, x > y)
E(x %x<=% y, x <= y)

2 changes: 1 addition & 1 deletion inst/realtest/strptime-all.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ E(
)


t <- ISOdate(2021, 05, 27)
t <- ISOdatetime(2021, 05, 27, 12, 0, 0) # default time zone

E(
strftime(t),
Expand Down
5 changes: 4 additions & 1 deletion inst/realtest/strptime-stringx.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
t <- structure(ISOdate(2021, 05, 27), names="t")
t <- structure(ISOdatetime(2021, 05, 27, 12, 0, 0), names="t") # default time zone

# different calendar/locale - easy with stringx:

Expand All @@ -17,6 +17,9 @@ E(
c(t="Donnerstag")
)


t <- structure(ISOdatetime(2021, 05, 27, 12, 0, 0, tz="GMT"), names="t")

E(
strftime(t, "%H:%M:%S", tz="UTC", usetz=TRUE),
P(c(t="12:00:00"), warning=TRUE)
Expand Down
14 changes: 14 additions & 0 deletions inst/realtest/strtrim-all.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ E(
x,
bad=c("\U0001F4A9", "\U0001F64D", "\U0001F64D", "\u26F9\U0001F3FF\u200D",
"\U0001F3F4\U000E0067\U000E0062\U000E0073\U000E0063\U000E0074\U000E007F"),
bad=c(
"\U0001F4A9",
"\U0001F64D\U0001F3FC\U0000200D",
"\U0001F64D\U0001F3FB\U0000200D",
"\U000026F9\U0001F3FF\U0000200D",
"\U0001F3F4\U000E0067\U000E0062\U000E0073\U000E0063\U000E0074\U000E007F"
),
worst=c("<U+", "<U+", "<U+", "<U+", "<U+")
)
E(
Expand All @@ -69,6 +76,13 @@ E(
bad=c("\U0001F4A9", "\U0001F64D\U0001F3FC\u200D",
"\U0001F64D\U0001F3FB\u200D", "\u26F9\U0001F3FF\u200D\u2640\uFE0F",
"\U0001F3F4\U000E0067\U000E0062\U000E0073\U000E0063\U000E0074\U000E007F"),
bad=c(
"\U0001F4A9",
"\U0001F64D\U0001F3FC\U0000200D",
"\U0001F64D\U0001F3FB\U0000200D",
"\U000026F9\U0001F3FF\U0000200D",
"\U0001F3F4\U000E0067\U000E0062\U000E0073\U000E0063\U000E0074\U000E007F"
),
worst=c("<U+0", "<U+0", "<U+0", "<U+2", "<U+0")
)
E(
Expand Down
4 changes: 2 additions & 2 deletions inst/realtest/strwrap-all.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ E(strwrap(character(0), simplify=FALSE), list())

E(stringi::stri_width(strwrap(strrep("az ", 20), 60)), 59L)
E(stringi::stri_width(strwrap(strrep("\u0105\u20AC ", 20), 60)), 59L)
E(stringi::stri_width(strwrap(strrep("\U0001F643 ", 20), 60)), 59L)
E(stringi::stri_width(strwrap(strrep("\U0001F3F3\U0000FE0F\U0000200D\U0001F308 ", 20), 60)), 59L, bad=c(44L, 14L))
E(stringi::stri_width(strwrap(strrep("\U0001F643 ", 20), 60)), 59L, bad=39L)
E(stringi::stri_width(strwrap(strrep("\U0001F3F3\U0000FE0F\U0000200D\U0001F308 ", 20), 60)), 59L, bad=c(44L, 14L), bad=c(74L, 24L), bad=c(59L, 39L))

# attribute preservation (lack thereof)
E(attributes(strwrap(structure(c(a="aaa", attrib1="value1")), simplify=TRUE)), NULL)
Expand Down
12 changes: 6 additions & 6 deletions man/grepl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/gsub.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions tests/realtest.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,23 @@ library(this_package, character.only=TRUE)
if (require("realtest", quietly=TRUE)) {
f <- file.path(path.package(this_package), "realtest")
r <- test_dir(f, ".*\\.R$")
s <- summary(r)
print(s)
stopifnot(all(s[["match"]] != "fail"))
x <- summary(r)

names(r) <- row.names(x)
fails <- x[x[["match"]] == "fail", , drop=FALSE]
if (nrow(fails) > 0) {
fails2 <- as.data.frame(fails[,
!(names(fails) %in% ".expr") & !sapply(fails, function(x) all(is.na(x))),
drop=FALSE])
for (i in row.names(fails2)) {
cat(sprintf("%s:%d:\n", fails2[i, ".file"], fails2[i, ".line"]))
cat(" value: "); str(r[[i]][["object"]][["value"]], indent.str=" ")
cat(" sides: "); str(r[[i]][["object"]][["sides"]], indent.str=" ")
}

if (require("stringi", quietly=TRUE))
cat(sprintf("%s; %s\n", stri_info(TRUE), Sys.getlocale()))

stop("some tests failed")
}
}

0 comments on commit 04ca583

Please sign in to comment.