-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathtest-vctrs.R
71 lines (66 loc) · 1.79 KB
/
test-vctrs.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
test_that("common type of character and glue is glue", {
expect_identical(
vctrs::vec_ptype2(character(), glue()),
glue()[0]
)
expect_identical(
vctrs::vec_ptype2(glue(), character()),
glue()[0]
)
})
test_that("common type is not inherited", {
expect_error(
vctrs::vec_ptype2(glue(), structure(character(), class = "foobar")),
class = "vctrs_error_incompatible_type"
)
expect_error(
vctrs::vec_ptype2(structure(character(), class = "foobar"), glue()),
class = "vctrs_error_incompatible_type"
)
expect_error(
vctrs::vec_ptype2(character(), structure(glue(), class = "foobar")),
class = "vctrs_error_incompatible_type"
)
expect_error(
vctrs::vec_ptype2(structure(glue(), class = "foobar"), character()),
class = "vctrs_error_incompatible_type"
)
})
test_that("glue and character are coercible", {
expect_identical(
vctrs::vec_cast("foo", glue()),
glue("foo")
)
expect_identical(
vctrs::vec_cast(glue("foo"), character()),
"foo"
)
expect_identical(
vctrs::vec_cast(glue("foo"), glue()),
glue("foo")
)
})
test_that("coercion is not inherited", {
expect_error(
vctrs::vec_cast(glue(), structure(character(), class = "foobar")),
class = "vctrs_error_incompatible_type"
)
expect_error(
vctrs::vec_cast(structure(character(), class = "foobar"), glue()),
class = "vctrs_error_incompatible_type"
)
expect_error(
vctrs::vec_cast(character(), structure(glue(), class = "foobar")),
class = "vctrs_error_incompatible_type"
)
expect_error(
vctrs::vec_cast(structure(glue(), class = "foobar"), character()),
class = "vctrs_error_incompatible_type"
)
})
test_that("can concatenate glue", {
expect_identical(
vctrs::vec_c(glue("foo"), glue("bar")),
as_glue(c("foo", "bar"))
)
})