Skip to content

Commit a530c63

Browse files
committed
Polish expect_named()
1 parent 9bba39e commit a530c63

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

R/expect-named.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ expect_named <- function(
4444
exp <- quasi_label(enquo(expected), arg = "expected")
4545

4646
exp$val <- normalise_names(exp$val, ignore.order, ignore.case)
47-
act_names <- normalise_names(names(act$val), ignore.order, ignore.case)
48-
47+
act_names <- labelled_value(
48+
normalise_names(names(act$val), ignore.order, ignore.case),
49+
paste0("names of ", act$lab)
50+
)
4951
if (ignore.order) {
50-
act_names <- labelled_value(act_names, paste0("names(", act$lab, ")"))
5152
expect_setequal_(act_names, exp)
5253
} else {
53-
act_name <- labelled_value(act_names, paste0("names(", act$lab, ")"))
54-
expect_waldo_equal_("equal", act_name, exp)
54+
expect_waldo_equal_("equal", act_names, exp)
5555
}
5656

5757
invisible(act$val)

tests/testthat/_snaps/expect-named.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
expect_named(x, "b")
1313
Condition
1414
Error:
15-
! Expected names(`x`) to be equal to "b".
15+
! Expected names of `x` to be equal to "b".
1616
Differences:
1717
`actual`: "a"
1818
`expected`: "b"
@@ -23,7 +23,7 @@
2323
expect_named(x1, c("a", "b"), ignore.order = TRUE)
2424
Condition
2525
Error:
26-
! Expected names(`x1`) to have the same values as `c("a", "b")`.
26+
! Expected names of `x1` to have the same values as `c("a", "b")`.
2727
Actual: "a"
2828
Expected: "a", "b"
2929
Absent: "b"
@@ -34,7 +34,7 @@
3434
expect_named(x2, "a", ignore.order = TRUE)
3535
Condition
3636
Error:
37-
! Expected names(`x2`) to have the same values as "a".
37+
! Expected names of `x2` to have the same values as "a".
3838
Actual: "a", "b"
3939
Expected: "a"
4040
Needs: "b"
@@ -45,7 +45,7 @@
4545
expect_named(x1, "b", ignore.order = TRUE)
4646
Condition
4747
Error:
48-
! Expected names(`x1`) to have the same values as "b".
48+
! Expected names of `x1` to have the same values as "b".
4949
Actual: "a"
5050
Expected: "b"
5151
Needs: "a"
@@ -57,7 +57,7 @@
5757
expect_named(x1, c("a", "b"), ignore.order = FALSE)
5858
Condition
5959
Error:
60-
! Expected names(`x1`) to be equal to `c("a", "b")`.
60+
! Expected names of `x1` to be equal to `c("a", "b")`.
6161
Differences:
6262
`actual`: "a"
6363
`expected`: "a" "b"
@@ -68,18 +68,18 @@
6868
expect_named(x2, "a", ignore.order = FALSE)
6969
Condition
7070
Error:
71-
! Expected names(`x2`) to be equal to "a".
71+
! Expected names of `x2` to be equal to "a".
7272
Differences:
7373
`actual`: "a" "b"
7474
`expected`: "a"
7575

7676
---
7777

7878
Code
79-
expect_named(x1, c("b"), ignore.order = FALSE)
79+
expect_named(x1, "b", ignore.order = FALSE)
8080
Condition
8181
Error:
82-
! Expected names(`x1`) to be equal to `c("b")`.
82+
! Expected names of `x1` to be equal to "b".
8383
Differences:
8484
`actual`: "a"
8585
`expected`: "b"

tests/testthat/test-expect-named.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test_that("provide useful feedback on failure", {
3535

3636
expect_snapshot_failure(expect_named(x1, c("a", "b"), ignore.order = FALSE))
3737
expect_snapshot_failure(expect_named(x2, "a", ignore.order = FALSE))
38-
expect_snapshot_failure(expect_named(x1, c("b"), ignore.order = FALSE))
38+
expect_snapshot_failure(expect_named(x1, "b", ignore.order = FALSE))
3939
})
4040

4141
test_that("expect_named validates its inputs", {

0 commit comments

Comments
 (0)