Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Depends:
R (>= 3.3)
Imports:
ellipsis (>= 0.3.1),
rlang (>= 0.4.10),
rlang (>= 1.0.0),
tzdb (>= 0.2.0),
vctrs (>= 0.3.7)
Suggests:
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# clock (development version)

* Updated all snapshot tests to use rlang 1.0.0 (#285).

* `date_seq()` and the `seq()` methods for the calendar, time point, and
duration types now allow `from > to` when `by > 0`. This now results in a
size zero result rather than an error, which is more in line with
Expand Down
21 changes: 14 additions & 7 deletions tests/testthat/_snaps/calendar.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,44 +184,51 @@
(expect_error(calendar_count_between(x, 1, "year")))
Output
<error/rlang_error>
`end` must be a <clock_calendar>.
Error in `calendar_count_between()`:
! `end` must be a <clock_calendar>.

# can't count with a precision finer than the calendar precision

Code
(expect_error(calendar_count_between(x, x, "month")))
Output
<error/rlang_error>
Precision of inputs must be at least as precise as `precision`.
Error in `calendar_count_between()`:
! Precision of inputs must be at least as precise as `precision`.

# `n` is validated

Code
(expect_error(calendar_count_between(x, x, "year", n = NA_integer_)))
Output
<error/rlang_error>
`n` must be a single positive integer.
Error in `calendar_count_between()`:
! `n` must be a single positive integer.
Code
(expect_error(calendar_count_between(x, x, "year", n = -1)))
Output
<error/rlang_error>
`n` must be a single positive integer.
Error in `calendar_count_between()`:
! `n` must be a single positive integer.
Code
(expect_error(calendar_count_between(x, x, "year", n = 1.5)))
Output
<error/vctrs_error_cast_lossy>
Can't convert from `n` <double> to <integer> due to loss of precision.
Error in `stop_vctrs()`:
! Can't convert from `n` <double> to <integer> due to loss of precision.
* Locations: 1
Code
(expect_error(calendar_count_between(x, x, "year", n = "x")))
Output
<error/vctrs_error_incompatible_type>
Can't convert `n` <character> to <integer>.
Error in `stop_vctrs()`:
! Can't convert `n` <character> to <integer>.
Code
(expect_error(calendar_count_between(x, x, "year", n = c(1L, 2L))))
Output
<error/rlang_error>
`n` must be a single positive integer.
Error in `calendar_count_between()`:
! `n` must be a single positive integer.

# precision: can only be called on calendars

Expand Down
26 changes: 14 additions & 12 deletions tests/testthat/_snaps/date.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@

Code
date_format(x, format = "%z")
Warning <clock_warning_format_failures>
Condition
Warning:
Failed to format 1 string at location 1. Returning `NA` at that location.
Output
[1] NA
Expand All @@ -131,7 +132,8 @@

Code
date_format(x, format = "%Z")
Warning <clock_warning_format_failures>
Condition
Warning:
Failed to format 1 string at location 1. Returning `NA` at that location.
Output
[1] NA
Expand All @@ -140,7 +142,8 @@

Code
date_parse("foo")
Warning <clock_warning_parse_failures>
Condition
Warning:
Failed to parse 1 string at location 1. Returning `NA` at that location.
Output
[1] NA
Expand Down Expand Up @@ -224,29 +227,28 @@

# checks empty dots

`...` is not empty.

We detected these problematic arguments:
* `..1`

These dots only exist to allow future extensions and should be empty.
Did you misspecify an argument?
`...` must be empty.
x Problematic argument:
* ..1 = new_date(2)
i Did you forget to name an argument?

# must use a valid Date precision

Code
(expect_error(date_count_between(x, x, "hour")))
Output
<error/rlang_error>
`precision` must be one of: 'year', 'quarter', 'month', 'week', 'day'.
Error in `date_count_between_impl()`:
! `precision` must be one of: 'year', 'quarter', 'month', 'week', 'day'.

# can't count between a Date and a POSIXt

Code
(expect_error(date_count_between(x, y, "year")))
Output
<error/rlang_error>
`end` must be a <Date>.
Error in `date_count_between()`:
! `end` must be a <Date>.

# cannot get the zone of a Date

Expand Down
23 changes: 12 additions & 11 deletions tests/testthat/_snaps/duration.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,10 @@

# seq() validates dots

`...` is not empty.

We detected these problematic arguments:
* `..1`

These dots only exist to allow future extensions and should be empty.
Did you misspecify an argument?
`...` must be empty.
x Problematic argument:
* ..1 = 1
i Did you forget to name an argument?

# seq() enforces non-fractional results

Expand Down Expand Up @@ -186,21 +183,24 @@
(expect_error(duration_years(1) / duration_years(2)))
Output
<error/vctrs_error_incompatible_op>
<duration<year>> / <duration<year>> is not permitted
Error in `stop_vctrs()`:
! <duration<year>> / <duration<year>> is not permitted
Durations only support integer division. Did you want `%/%`?

# `<duration> %/% <duration>` results in NA for OOB values

Code
out <- (numerator + one) %/% denominator
Warning <simpleWarning>
Condition
Warning:
Conversion to integer is outside the range of an integer. `NA` values have been introduced, beginning at location 1.

---

Code
out <- (-numerator - one) %/% denominator
Warning <simpleWarning>
Condition
Warning:
Conversion to integer is outside the range of an integer. `NA` values have been introduced, beginning at location 1.

# `<duration> %% <numeric>` casts the numeric to integer
Expand All @@ -209,6 +209,7 @@
(expect_error(duration_hours(5) %% 2.5))
Output
<error/vctrs_error_cast_lossy>
Can't convert from `y` <double> to <integer> due to loss of precision.
Error in `stop_vctrs()`:
! Can't convert from `y` <double> to <integer> due to loss of precision.
* Locations: 1

3 changes: 2 additions & 1 deletion tests/testthat/_snaps/gregorian-year-day.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
(expect_error(calendar_count_between(x, x, "day")))
Output
<error/rlang_error>
`precision` must be one of: 'year'.
Error in `calendar_count_between_standardize_precision_n()`:
! `precision` must be one of: 'year'.

# only granular precisions are allowed

Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/_snaps/gregorian-year-month-day.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@

Code
year_month_day_parse("foo")
Warning <clock_warning_parse_failures>
Condition
Warning:
Failed to parse 1 string at location 1. Returning `NA` at that location.
Output
<year_month_day<day>[1]>
Expand Down Expand Up @@ -142,7 +143,8 @@
(expect_error(calendar_count_between(x, x, "day")))
Output
<error/rlang_error>
`precision` must be one of: 'year', 'quarter', 'month'.
Error in `calendar_count_between_standardize_precision_n()`:
! `precision` must be one of: 'year', 'quarter', 'month'.

# only granular precisions are allowed

Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/_snaps/gregorian-year-month-weekday.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@
(expect_error(calendar_count_between(x, x, "month")))
Output
<error/rlang_error>
'year_month_weekday' types with a precision of >= 'day' cannot be trivially compared or ordered. Convert to 'year_month_day' to compare using day-of-month values.
Error in `vec_proxy_compare()`:
! 'year_month_weekday' types with a precision of >= 'day' cannot be trivially compared or ordered. Convert to 'year_month_day' to compare using day-of-month values.

# only granular precisions are allowed

Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/_snaps/iso-year-week-day.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
(expect_error(calendar_count_between(x, x, "week")))
Output
<error/rlang_error>
`precision` must be one of: 'year'.
Error in `calendar_count_between_standardize_precision_n()`:
! `precision` must be one of: 'year'.

# only year precision is allowed

Expand Down
29 changes: 16 additions & 13 deletions tests/testthat/_snaps/naive-time.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

Code
naive_time_parse(x, precision = "day")
Warning <clock_warning_parse_failures>
Condition
Warning:
Failed to parse 1 string at location 1. Returning `NA` at that location.
Output
<time_point<naive><day>[1]>
Expand All @@ -20,7 +21,8 @@

Code
naive_time_parse("foo")
Warning <clock_warning_parse_failures>
Condition
Warning:
Failed to parse 1 string at location 1. Returning `NA` at that location.
Output
<time_point<naive><second>[1]>
Expand All @@ -37,7 +39,8 @@

Code
format(x, format = "%Z")
Warning <clock_warning_format_failures>
Condition
Warning:
Failed to format 1 string at location 1. Returning `NA` at that location.
Output
[1] NA
Expand All @@ -46,7 +49,8 @@

Code
format(c(x, x), format = "%Z")
Warning <clock_warning_format_failures>
Condition
Warning:
Failed to format 2 strings, beginning at location 1. Returning `NA` at the locations where there were format failures.
Output
[1] NA NA
Expand All @@ -55,7 +59,8 @@

Code
format(x, format = "%z")
Warning <clock_warning_format_failures>
Condition
Warning:
Failed to format 1 string at location 1. Returning `NA` at that location.
Output
[1] NA
Expand All @@ -64,7 +69,8 @@

Code
format(c(x, x), format = "%z")
Warning <clock_warning_format_failures>
Condition
Warning:
Failed to format 2 strings, beginning at location 1. Returning `NA` at the locations where there were format failures.
Output
[1] NA NA
Expand Down Expand Up @@ -163,11 +169,8 @@

# empty dots are checked

`...` is not empty.

We detected these problematic arguments:
* `..1`

These dots only exist to allow future extensions and should be empty.
Did you misspecify an argument?
`...` must be empty.
x Problematic argument:
* ..1 = "roll-forward"
i Did you forget to name an argument?

Loading