Skip to content

Commit

Permalink
Merge pull request #91 from russHyde/pass-dots
Browse files Browse the repository at this point in the history
Pass dots
  • Loading branch information
russHyde authored Apr 3, 2024
2 parents 1191773 + 8240c60 commit 690605c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# dupree (development version)

* Pass print(dups, ...) dots to print(tibble, ...) so that the number of output lines can be
specified in the output (thanks @mikemahoney218)
* Update the CI workflows for pkgdown, test-coverage and R CMD check
* use lintr >= 3, and update .lintr config file
* Fixed linting across package
Expand Down
2 changes: 1 addition & 1 deletion R/dups-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ tibble::as_tibble

# nocov start
print.dups <- function(x, ...) {
print(as_tibble(x))
print(as_tibble(x), ...)
invisible(x)
}
# nocov end
22 changes: 19 additions & 3 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ expect_equivalent_tbl <- function(object, expected, ..., info = NULL) {
)
}

get_empty_dups_tbl <- function() {
tibble::tibble(
get_dups_tbl <- function(
...
) {
empty_tbl <- tibble::tibble(
file_a = character(0),
file_b = character(0),
block_a = integer(0),
Expand All @@ -41,10 +43,24 @@ get_empty_dups_tbl <- function() {
line_b = integer(0),
score = numeric(0)
)

user_tbl <- tibble::tibble(...)

common_cols <- intersect(colnames(user_tbl), colnames(empty_tbl))

if (length(common_cols) == 0) {
return(dplyr::cross_join(user_tbl, empty_tbl))
}

dplyr::left_join(
user_tbl,
empty_tbl,
by = common_cols
)
}

get_empty_dups_df <- function() {
as.data.frame(get_empty_dups_tbl(), stringsAsFactors = FALSE)
as.data.frame(get_dups_tbl(), stringsAsFactors = FALSE)
}

###############################################################################
19 changes: 18 additions & 1 deletion tests/testthat/test-dups-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test_that("`dups` object can be converted to `data.frame`", {
info = "dups -> dups conversion is an identity map"
)

y <- get_empty_dups_tbl()
y <- get_dups_tbl()
dups <- as_dups(y)

expect_equal(
Expand All @@ -28,3 +28,20 @@ test_that("`dups` object can be converted to `data.frame`", {
test_that("non dups/data-frames can't be converted to dups", {
expect_error(as_dups("NOT A data.frame or dups object"))
})

describe("printing a 'dups' object", {
dups <- as_dups(get_dups_tbl(file_a = paste0(letters, ".R")))

it("includes the first line in the output", {
expect_output(print(dups), regexp = "a\\.R")
})

it("respects print(tibble, n = ...)", {
# "z.R" is on the last line of the table, it shouldn't be visible by default
# because `print(tibble)` shows the first 10 lines for large tables
expect_output(print(dups), regexp = "[^z].\\R")
# But when 26 lines of the table are printed, then the file "z.R" should be
# seen
expect_output(print(dups, n = 26), regexp = "z\\.R")
})
})

0 comments on commit 690605c

Please sign in to comment.