File: test-translate-sql-paste.R

package info (click to toggle)
r-cran-dbplyr 2.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,376 kB
  • sloc: sh: 13; makefile: 2
file content (23 lines) | stat: -rw-r--r-- 668 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
test_that("basic prefix operation", {
  local_con(simulate_dbi())

  paste <- sql_paste("")
  x <- ident("x")
  y <- ident("y")

  expect_equal(paste(x), sql("CONCAT_WS('', `x`)"))
  expect_equal(paste(x, y), sql("CONCAT_WS('', `x`, `y`)"))
  expect_equal(paste(x, y, sep = " "), sql("CONCAT_WS(' ', `x`, `y`)"))
})

test_that("basic infix operation", {
  local_con(simulate_dbi())

  paste <- sql_paste_infix("", "&&", function(x) sql_expr(cast((!!x) %as% text)))
  x <- ident("x")
  y <- ident("y")

  expect_equal(paste(x), sql("CAST(`x` AS text)"))
  expect_equal(paste(x, y), sql("`x` && `y`"))
  expect_equal(paste(x, y, sep = " "), sql("`x` && ' ' && `y`"))
})