test-quote.R 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. test_that("quote list and vectors #1", {
  2. expect_silent(res <- llr_test("'(1 2 a)"))
  3. expect_equal(res, ral_list(1L, 2L, sym("a")), ignore_attr = TRUE)
  4. expect_silent(res <- llr_test("(quote (1 2 a))"))
  5. expect_equal(res, ral_list(1L, 2L, sym("a")), ignore_attr = TRUE)
  6. })
  7. test_that("syntax quote edge cases", {
  8. expect_equal(as.integer(llr_test("`1")), 1L)
  9. expect_equal(as.integer(llr_test("`~1")), 1L)
  10. expect_equal(as.integer(llr_test("`~1")), 1L)
  11. expect_equal(as.integer(llr_test("`~(+ 1 1)")), 2L)
  12. })
  13. test_that("syntax quote UQ works", {
  14. res <- llr_test("
  15. (let [a 1 b 2] `(+ ~a ~b))
  16. ")
  17. expect_equal(unlist(res), list(sym("+"), 1L, 2L))
  18. })
  19. test_that("unquote splicing works", {
  20. res <- llr_test("`(1 ~@[1 2 3])")
  21. expect_equal(unlist(res), c(1L, 1L, 2L, 3L), ignore_attr = TRUE)
  22. })
  23. test_that("UQ on maps", {
  24. res <- llr_test("`{:a ~(+ 1 1)}")
  25. expect_equal(res$get(":a"), 2, ignore_attr = TRUE)
  26. res <- llr_test("(defn w [] :a) `{~(w) ~(+ 1 1)}")
  27. expect_equal(res$get(":a"), 2, ignore_attr = TRUE)
  28. })
  29. test_that("UQ on maps2", {
  30. res <- llr_test("
  31. (def dynamic_symbol (fn [] :a))
  32. (get `{~(dynamic_symbol) ~(+ 1 1)} :a)
  33. ")
  34. expect_equal(res, 2, ignore_attr = TRUE)
  35. })