@@ -2,13 +2,14 @@ context("Parsing, datetime")

test_that("utctime is equivalent to R conversion", {
year <- seq(0, 4000)
mon <- rep(3, length(year))
day <- rep(1, length(year))
zero <- rep(0, length(year))
mon <- rep(3L, length(year))
day <- rep(1L, length(year))
zero_i <- rep(0L, length(year))
zero_d <- rep(0, length(year))

expect_equal(
ISOdatetime(year, mon, day, zero, zero, zero, tz = "UTC"),
utctime(year, mon, day, zero, zero, zero, zero)
utctime(year, mon, day, zero_i, zero_i, zero_i, zero_d),
ISOdatetime(year, mon, day, zero_i, zero_i, zero_i, tz = "UTC")
)
})

@@ -17,7 +18,7 @@ test_that("utctime is equivalent to R conversion", {
r_parse <- function(x, fmt) as.POSIXct(strptime(x, fmt, tz = "UTC"))

test_that("%d, %m and %y", {
target <- utctime(2010, 2, 3, 0, 0, 0, 0)
target <- utctime(2010L, 2L, 3L, 0L, 0L, 0L, 0)

expect_equal(parse_datetime("10-02-03", "%y-%m-%d"), target)
expect_equal(parse_datetime("10-03-02", "%y-%d-%m"), target)
@@ -26,7 +27,7 @@ test_that("%d, %m and %y", {
})

test_that("Compound formats work", {
target <- utctime(2010, 2, 3, 0, 0, 0, 0)
target <- utctime(2010L, 2L, 3L, 0L, 0L, 0L, 0)

expect_equal(parse_datetime("02/03/10", "%D"), target)
expect_equal(parse_datetime("2010-02-03", "%F"), target)
@@ -45,15 +46,15 @@ test_that("%y matches R behaviour", {
})

test_that("%e allows leading space", {
expect_equal(parse_datetime("201010 1", "%Y%m%e"), utctime(2010, 10, 1, 0, 0, 0, 0))
expect_equal(parse_datetime("201010 1", "%Y%m%e"), utctime(2010L, 10L, 1L, 0L, 0L, 0L, 0))
})

test_that("%OS captures partial seconds", {
x <- parse_datetime("2001-01-01 00:00:01.125", "%Y-%m-%d %H:%M:%OS")
expect_equal(as.POSIXlt(x)$sec, 1.125)

x <- parse_datetime("2001-01-01 00:00:01.333", "%Y-%m-%d %H:%M:%OS")
expect_equal(as.POSIXlt(x)$sec, 1.333, tol = 1e-6)
expect_equal(as.POSIXlt(x)$sec, 1.333, tolerance = 1e-6)
})

test_that("%y requries 4 digits", {
@@ -218,7 +219,7 @@ test_that("same times with different offsets parsed as same time", {
same_time <- paste("2010-02-03", c("18:30Z", "22:30+04", "1130-0700", "15:00-03:30"))
parsed <- parse_datetime(same_time)

expect_equal(parsed, rep(utctime(2010, 2, 3, 18, 30, 0, 0), 4))
expect_equal(parsed, rep(utctime(2010L, 2L, 3L, 18L, 30L, 0L, 0), 4))
})

test_that("offsets can cross date boundaries", {
@@ -53,7 +53,7 @@ test_that("NAs included in levels if desired", {
expect_equal(x, factor(c("NA", "b", "a"), levels = c("b", "a")))

x <- parse_factor(c("NA", "b", "a"), levels = NULL, include_na = TRUE)
expect_equal(x, factor(c("NA", "b", "a"), levels = c(NA, "b", "a"), exclude = NULL))
expect_equal(x, factor(c(NA, "b", "a"), levels = c(NA, "b", "a"), exclude = NULL))
})

test_that("Factors handle encodings properly (#615)", {
@@ -5,8 +5,8 @@ test_that("default format captures cases", {
expect_equal(parse_time("22:20"), late_night)
expect_equal(parse_time("10:20 pm"), late_night)

expect_equal(parse_time("22:20:05"), hms::as.hms(late_night + 5))
expect_equal(parse_time("10:20:05 pm"), hms::as.hms(late_night + 5))
expect_equal(parse_time("22:20:05"), hms::as_hms(late_night + 5))
expect_equal(parse_time("10:20:05 pm"), hms::as_hms(late_night + 5))
})

test_that("twelve o'clock is parsed properly", {
@@ -1,6 +1,7 @@
context("test-read-builtin")

test_that("read_builtin works", {
skip_if(interactive())
# fails with unquoted symbol (like data(storms, package = "dplyr"))
expect_error(read_builtin(storms, "dplyr"))

@@ -208,9 +208,9 @@ test_that("comments are ignored regardless of where they appear", {
x2 = c("B2", NA_character_, "A5"),
x3 = c("C2", NA_character_, "A6"))

expect_true(all.equal(chk, out5))
expect_true(all.equal(chk, out6))
expect_true(all.equal(chk, out7))
expect_true(all.equal(chk, out5, check.attributes = FALSE))
expect_true(all.equal(chk, out6, check.attributes = FALSE))
expect_true(all.equal(chk, out7, check.attributes = FALSE))
})

test_that("escaped/quoted comments are ignored", {
@@ -123,9 +123,9 @@ test_that("check for line breaks in between widths", {
expect_warning(out2 <- read_fwf(txt2, fwf_empty(txt2)))
expect_equal(n_problems(out2), 2)

exp <- tibble::tibble(X1 = c(1L, 2L, 1L), X2 = c(1L, NA, 1L))
expect_true(all.equal(out1, exp))
expect_true(all.equal(out2, exp))
exp <- tibble::tibble(X1 = c(1, 2, 1), X2 = c(1, NA, 1))
expect_true(all.equal(out1, exp, check.attributes = FALSE))
expect_true(all.equal(out2, exp, check.attributes = FALSE))

})

@@ -203,7 +203,7 @@ test_that("read_table skips all comment lines", {

y <- read_table("#comment1\n#comment2\nfoo bar\n1 2\n3 4\n5 6\n", progress = FALSE, comment = "#")

expect_equal(x, y)
expect_equal(x[], y[])
})

test_that("read_table can read from a pipe (552)", {
@@ -12,7 +12,7 @@ test_that("read_table skips all comment lines", {

y <- read_table("#comment1\n#comment2\nfoo bar\n1 2\n3 4\n5 6\n", progress = FALSE, comment = "#")

expect_equal(x, y)
expect_equal(x[], y[], ignore_attr = FALSE)
})

test_that("read_table can read from a pipe (552)", {
@@ -36,15 +36,15 @@ test_that("read_table2 skips all comment lines", {

y <- read_table2("#comment1\n#comment2\nfoo bar\n1 2\n3 4\n5 6\n", progress = FALSE, comment = "#")

expect_equal(x, y)
expect_equal(x[], y[])
})

test_that("read_table2 skips even more comment lines", {
x <- read_table2("foo bar\n1 2\n3 4\n5 6\n", progress = FALSE)

y <- read_table2("#comment1\n#comment2\nfoo bar # comment\n1 2 # comment\n3 4\n5 6\n #comment \n", progress = FALSE, comment = "#")

expect_equal(x, y)
expect_equal(x[], y[])
})

test_that("read_table2 can read from a pipe (552)", {
@@ -25,7 +25,8 @@ test_that("read_delim/csv/tsv and write_delim round trip special chars", {
input <- read_delim(format_delim(output, delim = " "), delim = " ", trim_ws = FALSE, progress = FALSE)
input_csv <- read_csv(format_delim(output, delim = ","), trim_ws = FALSE, progress = FALSE)
input_tsv <- read_tsv(format_delim(output, delim = "\t"), trim_ws = FALSE, progress = FALSE)
expect_equal(input$x, input_csv$x, input_tsv$x, x)
expect_equal(input$x, input_csv$x)
expect_equal(input_tsv$x, x)
})

test_that("special floating point values translated to text", {
@@ -178,7 +179,7 @@ test_that("Can change the escape behavior for quotes", {
})

test_that("hms NAs are written without padding (#930)", {
df <- data.frame(x = hms::as.hms(c(NA, 34.234)))
df <- data.frame(x = hms::as_hms(c(NA, 34.234)))
expect_equal(format_tsv(df), "x\nNA\n00:00:34.234\n")
})