Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions tests/testthat/_snaps/class.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
# abstract classes / can't be instantiated

Code
foo <- new_class("foo", abstract = TRUE)
foo := new_class(abstract = TRUE)
foo()
Condition
Error in `S7::new_object()`:
Expand All @@ -128,7 +128,7 @@
# abstract classes / can't inherit from concrete class

Code
foo1 <- new_class("foo1")
foo1 := new_class()
new_class("foo2", parent = foo1, abstract = TRUE)
Condition
Error in `new_class()`:
Expand Down Expand Up @@ -205,7 +205,7 @@
# S7 object / displays nicely

Code
foo <- new_class("foo", properties = list(x = class_double, y = class_double),
foo := new_class(properties = list(x = class_double, y = class_double),
package = NULL)
foo()
Output
Expand All @@ -223,7 +223,7 @@
# S7 object / displays objects with data nicely

Code
text <- new_class("text", class_character, package = NULL)
text := new_class(class_character, package = NULL)
text("x")
Output
<text> chr "x"
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/_snaps/constructor.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
}
<environment: namespace:S7>
Code
foo <- new_class("foo", parent = class_character)
foo := new_class(parent = class_character)
new_constructor(foo, list())
Output
function (.data = character(0))
new_object(foo(.data = .data))
<environment: 0x0>
Code
foo2 <- new_class("foo2", parent = foo)
foo2 := new_class(parent = foo)
new_constructor(foo2, list())
Output
function (.data = character(0))
Expand All @@ -52,7 +52,7 @@
# can generate constructor for inherited abstract classes

Code
foo1 <- new_class("foo1", abstract = TRUE, properties = list(x = class_double))
foo1 := new_class(abstract = TRUE, properties = list(x = class_double))
new_constructor(foo1, list())
Output
function ()
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/inherits.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# throws informative error

Code
foo1 <- new_class("foo1", package = NULL)
foo2 <- new_class("foo2", package = NULL)
foo1 := new_class(package = NULL)
foo2 := new_class(package = NULL)
check_is_S7(foo1(), foo2)
Condition
Error:
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/super.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# super() / checks to

Code
foo <- new_class("foo", package = NULL)
foo := new_class(package = NULL)
super(foo(), class_character)
Condition
Error in `super()`:
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/union.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# has useful print method

Code
foo1 <- new_class("foo1", package = NULL)
foo2 <- new_class("foo2", package = NULL)
foo1 := new_class(package = NULL)
foo2 := new_class(package = NULL)
new_union(foo1, foo2)
Output
<S7_union>: <foo1> or <foo2>
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-S3.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ test_that("new_S3_class has a print method", {
})

test_that("can construct objects that extend S3 classes", {
ordered2 <- new_class("ordered2", parent = class_factor, package = NULL)
ordered2 := new_class(parent = class_factor, package = NULL)
x <- ordered2(c(1L, 2L, 1L), letters[1:3])
expect_equal(class(x), c("ordered2", "factor", "S7_object"))
expect_equal(prop_names(x), character())
Expand All @@ -16,7 +16,7 @@ test_that("subclasses inherit validator", {
function(.data) structure(.data, class = "foo"),
function(x) if (!is.double(x)) "Underlying data must be a double"
)
foo2 <- new_class("foo2", foo, package = NULL)
foo2 := new_class(foo, package = NULL)

expect_snapshot(error = TRUE, foo2("a"))
})
Expand All @@ -38,7 +38,7 @@ test_that("default new_S3_class constructor errors", {
})

test_that("can construct data frame subclass", {
dataframe2 <- new_class("dataframe2", class_data.frame)
dataframe2 := new_class(class_data.frame)
df <- dataframe2(list(x = 1:3))
expect_s3_class(df, "data.frame")
})
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-S4.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test_that("can work with classGenerators", {
describe("S4_register", {
it("registers an S7 class so it can be used with S4 methods", {
on.exit(S4_remove_classes("S4regS7"))
S4regS7 <- new_class("S4regS7", package = NULL)
S4regS7 := new_class(package = NULL)
S4_register(S4regS7)
expect_contains(methods::extends("S4regS7"), c("S4regS7", "S7_object"))
})
Expand Down
9 changes: 4 additions & 5 deletions tests/testthat/test-base-r.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
test_that("base::inherits() accepts S7 objects", {
skip_if(getRversion() < "4.3")

ClassA <- new_class("ClassA")
ClassBA <- new_class("ClassBA", parent = ClassA)
ClassX <- new_class("ClassX")
ClassA := new_class()
ClassBA := new_class(parent = ClassA)
ClassX := new_class()

expect_no_error(stopifnot(exprs = {
isTRUE(inherits(ClassA(), ClassA))
Expand All @@ -19,8 +19,7 @@ test_that("base::inherits() accepts S7 objects", {
test_that("base::`@` accesses S7 properties", {
skip_if(getRversion() < "4.3")

range <- new_class(
"range",
range := new_class(
properties = list(start = class_double, end = class_double),
validator = function(self) {
if (length(self@start) != 1) {
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-base.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test_that("classes can inherit from base types", {
base_classes <- c(class_vector$classes, list(class_function))

for (class in base_classes) {
foo <- new_class("foo", parent = class)
foo := new_class(parent = class)
expect_error(foo(), NA)
}
})
Expand Down Expand Up @@ -344,11 +344,11 @@ test_that("ALTREP vectors aren't materialised (#607)", {
local_mocked_bindings(new_object = compiler::cmpfun(new_object))

# parent
myint <- new_class("myint", parent = class_integer)
myint := new_class(parent = class_integer)
expect_true(is_altrep_preserved(myint(seq_len(1e6))))

# properties, set during construction and via @<-
Foo <- new_class("Foo", properties = list(x = class_integer))
Foo := new_class(properties = list(x = class_integer))
y <- Foo(x = seq_len(1e6))
expect_true(is_altrep_preserved(y@x))
y@x <- seq_len(1e6)
Expand Down
13 changes: 6 additions & 7 deletions tests/testthat/test-class-spec.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test_that("can work with S7 classes", {
klass <- new_class("klass", package = NULL)
klass := new_class(package = NULL)
expect_equal(as_class(klass), klass)

expect_equal(class_type(klass), "S7")
Expand All @@ -17,7 +17,7 @@ test_that("can work with S7 classes", {
})

test_that("can work with S7 classes in packages", {
klass <- new_class("klass", package = "pkg")
klass := new_class(package = "pkg")
expect_equal(as_class(klass), klass)

expect_equal(class_type(klass), "S7")
Expand All @@ -35,8 +35,8 @@ test_that("can work with S7 classes in packages", {
})

test_that("can work with unions", {
text <- new_class("text", class_character, package = NULL)
number <- new_class("number", class_double, package = NULL)
text := new_class(class_character, package = NULL)
number := new_class(class_double, package = NULL)
klass <- new_union(text, number)
expect_equal(as_class(klass), klass)

Expand Down Expand Up @@ -147,8 +147,7 @@ test_that("can work with S7 classes that extend S3 classes", {
Date <- new_S3_class("Date", constructor = function(.data = numeric()) {
.Date(.data)
})
Date2 <- new_class(
"Date2",
Date2 := new_class(
parent = Date,
properties = list(x = class_numeric),
package = NULL
Expand Down Expand Up @@ -197,7 +196,7 @@ test_that("can work with S4 classes", {
})

test_that("S7_class_desc() formats every supported class spec", {
Foo <- new_class("Foo", package = NULL)
Foo := new_class(package = NULL)

expect_equal(S7_class_desc(Foo), "<Foo>")
expect_equal(S7_class_desc(class_integer), "<integer>")
Expand Down
Loading
Loading