test-maps.R 916 B

12345678910111213141516171819202122232425262728293031323334353637
  1. test_that("simple map works", {
  2. res <- llr_test("
  3. {:a 10 :b 20}
  4. ")
  5. expect_equal(res$get(":a"), 10, ignore_attr = TRUE)
  6. expect_equal(res$get(":b"), 20, ignore_attr = TRUE)
  7. })
  8. test_that("any key works", {
  9. res <- llr_test('
  10. (def some-map {:a 1 :b 41 r/datasets::mtcars "woot"})
  11. (def res
  12. (+ (get some-map :a) (get some-map :b)))
  13. (paste res (get some-map r/datasets::mtcars))
  14. ')
  15. expect_equal(res, "42 woot", ignore_attr = TRUE)
  16. })
  17. test_that("dynamic keys", {
  18. res <- llr_test("
  19. (def w 1)
  20. {w 1}
  21. ")
  22. expect_equal(res$length(), 1)
  23. expect_equal(res$keys()[[1]], 1, ignore_attr = TRUE)
  24. expect_equal(res$values()[[1]], 1, ignore_attr = TRUE)
  25. })
  26. test_that("empty map", {
  27. expect_silent(llr_test("{}"))
  28. })
  29. test_that("format works with length > 0 values and keys", {
  30. expect_silent(format(llr_test("{:b (r/base::list 1 2 3)}")))
  31. expect_silent(format(llr_test("{(r/base::list 1 2 3) 1}")))
  32. })