test_that("null-coalescing operator works correctly", {
  expect_equal(NULL %||% "default", "default")
  expect_equal("value" %||% "default", "value")
  expect_equal(0 %||% "default", 0)
  expect_equal("" %||% "default", "")
})

test_that("format_generic_access_error returns appropriate message", {
  msg1 <- cloudosR:::format_generic_access_error("schema", "public")
  expect_true(grepl("does not exist or you do not have access", msg1))
  
  msg2 <- cloudosR:::format_generic_access_error("table")
  expect_true(grepl("does not exist or you do not have access", msg2))
})


test_that("paginate_results handles edge cases", {
  data <- 1:100
  
  # First page
  result <- cloudosR:::paginate_results(data, page = 0, page_size = 20)
  expect_equal(length(result$data), 20)
  expect_equal(result$page, 0)
  expect_equal(result$total, 100)
  expect_equal(result$pages, 5)
  
  # Last page
  result <- cloudosR:::paginate_results(data, page = 4, page_size = 20)
  expect_equal(length(result$data), 20)
  expect_equal(result$page, 4)
  
  # Beyond last page
  result <- cloudosR:::paginate_results(data, page = 10, page_size = 20)
  expect_equal(length(result$data), 0)
})


test_that("build_query_string handles various inputs", {
  # Empty params
  expect_equal(cloudosR:::build_query_string(list()), "")
  
  # Single param
  result <- cloudosR:::build_query_string(list(param1 = "value1"))
  expect_true(grepl("param1=value1", result))
  
  # Multiple params
  result <- cloudosR:::build_query_string(list(param1 = "value1", param2 = "value2"))
  expect_true(grepl("param1=value1", result))
  expect_true(grepl("param2=value2", result))
  
  # NULL param should be skipped
  result <- cloudosR:::build_query_string(list(param1 = "value1", param2 = NULL))
  expect_true(grepl("param1=value1", result))
  expect_false(grepl("param2", result))
})
