Skip to content

Commit

Permalink
Reorganize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Oct 7, 2023
1 parent 1a32127 commit 7034245
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
26 changes: 15 additions & 11 deletions tests/testthat/_snaps/code-generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,27 @@
mtcars, penguins)))
Output
[1] "dm_add_tbl(weather, airports, flights, airlines, planes, mtcars, penguins)"

---

Code
new_cg_block()
new_cg_block(quo(dm_nycflights13()), list(function(.) dm_add_pk(., flights,
flight_id)))
Output
dm_nycflights13() %>%
dm_add_pk(flights, flight_id)

---

Code
table <- "flights"
columns <- "carrier"
cg_block <- new_cg_block(quo(dm_nycflights13())) %>% cg_add_call(dm_rm_fk(.,
table = !!ensym(table), columns = !!ensym(columns), ref_table = airlines)) %>%
table = !!sym(table), columns = !!sym(columns), ref_table = airlines)) %>%
cg_add_call(dm_rm_fk(., table = flights, columns = c(origin, time_hour),
ref_table = weather)) %>% cg_add_call(dm_add_fk(., table = !!ensym(table),
columns = !!ensym(columns), ref_table = airlines))
ref_table = weather)) %>% cg_add_call(dm_add_fk(., table = !!sym(table),
columns = !!sym(columns), ref_table = airlines))
cg_block
Output
dm_nycflights13() %>%
Expand All @@ -38,21 +44,19 @@
Columns: 53
Primary keys: 4
Foreign keys: 3

---

Code
cg_block_2 <- new_cg_block(cg_block$cg_input_object, list(function(.)
dm_add_tbl(., mtcars), function(.) dm_select_tbl(., -planes)))
cg_block_2 <- new_cg_block(cg_block$cg_input_object, list(function(.) dm(.,
mtcars), function(.) dm_select_tbl(., -planes)))
cg_block_2
Output
dm_nycflights13() %>%
dm_add_tbl(mtcars) %>%
dm(mtcars) %>%
dm_select_tbl(-planes)
Code
cg_eval_block(cg_block_2)
Condition
Warning:
`dm_add_tbl()` was deprecated in dm 1.0.0.
i Please use `dm()` instead.
i Use `.name_repair = "unique"` if necessary.
Output
-- Metadata --------------------------------------------------------------------
Tables: `airlines`, `airports`, `flights`, `weather`, `mtcars`
Expand Down
15 changes: 12 additions & 3 deletions tests/testthat/test-code-generation.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,29 @@ test_that("code generation works", {
expect_snapshot({
call_to_char(body(function(.) dm_add_tbl(., weather)))
call_to_char(expr(dm_add_tbl(., weather, airports, flights, airlines, planes, mtcars, penguins)))
})

expect_snapshot({
new_cg_block()
new_cg_block(quo(dm_nycflights13()), list(function(.) dm_add_pk(., flights, flight_id)))
})

expect_snapshot({
table <- "flights"
columns <- "carrier"
cg_block <- new_cg_block(quo(dm_nycflights13())) %>%
cg_add_call(dm_rm_fk(., table = !!ensym(table), columns = !!ensym(columns), ref_table = airlines)) %>%
cg_add_call(dm_rm_fk(., table = !!sym(table), columns = !!sym(columns), ref_table = airlines)) %>%
cg_add_call(dm_rm_fk(., table = flights, columns = c(origin, time_hour), ref_table = weather)) %>%
cg_add_call(dm_add_fk(., table = !!ensym(table), columns = !!ensym(columns), ref_table = airlines))
cg_add_call(dm_add_fk(., table = !!sym(table), columns = !!sym(columns), ref_table = airlines))
cg_block
cg_eval_block(cg_block)
})

expect_snapshot({
cg_block_2 <- new_cg_block(
cg_block$cg_input_object,
list(
function(.) dm_add_tbl(., mtcars),
function(.) dm(., mtcars),
function(.) dm_select_tbl(., -planes)
)
)
Expand Down

0 comments on commit 7034245

Please sign in to comment.