Files
ob-elixir/test/test-ob-elixir-vars.el

91 lines
3.2 KiB
EmacsLisp

;;; test-ob-elixir-vars.el --- Variable handling tests -*- lexical-binding: t; -*-
;;; Commentary:
;; Variable handling and type conversion tests for ob-elixir package.
;;; Code:
(require 'ert)
(require 'ob-elixir)
;;; Type Conversion Tests
(ert-deftest ob-elixir-test-convert-nil ()
"Test nil conversion."
(should (equal "nil" (ob-elixir--elisp-to-elixir nil))))
(ert-deftest ob-elixir-test-convert-true ()
"Test t conversion."
(should (equal "true" (ob-elixir--elisp-to-elixir t))))
(ert-deftest ob-elixir-test-convert-integer ()
"Test integer conversion."
(should (equal "42" (ob-elixir--elisp-to-elixir 42)))
(should (equal "-10" (ob-elixir--elisp-to-elixir -10))))
(ert-deftest ob-elixir-test-convert-float ()
"Test float conversion."
(should (equal "3.14" (ob-elixir--elisp-to-elixir 3.14))))
(ert-deftest ob-elixir-test-convert-string ()
"Test string conversion."
(should (equal "\"hello\"" (ob-elixir--elisp-to-elixir "hello"))))
(ert-deftest ob-elixir-test-convert-string-escaping ()
"Test string escaping."
(should (equal "\"say \\\"hi\\\"\""
(ob-elixir--elisp-to-elixir "say \"hi\"")))
(should (equal "\"line1\\nline2\""
(ob-elixir--elisp-to-elixir "line1\nline2"))))
(ert-deftest ob-elixir-test-convert-symbol ()
"Test symbol conversion to atom."
(should (equal ":foo" (ob-elixir--elisp-to-elixir 'foo)))
(should (equal ":ok" (ob-elixir--elisp-to-elixir 'ok))))
(ert-deftest ob-elixir-test-convert-list ()
"Test list conversion."
(should (equal "[1, 2, 3]" (ob-elixir--elisp-to-elixir '(1 2 3))))
(should (equal "[\"a\", \"b\"]" (ob-elixir--elisp-to-elixir '("a" "b")))))
(ert-deftest ob-elixir-test-convert-nested-list ()
"Test nested list conversion."
(should (equal "[[1, 2], [3, 4]]"
(ob-elixir--elisp-to-elixir '((1 2) (3 4))))))
(ert-deftest ob-elixir-test-convert-vector ()
"Test vector to tuple conversion."
(should (equal "{1, 2, 3}" (ob-elixir--elisp-to-elixir [1 2 3]))))
;;; Variable Assignment Tests
(ert-deftest ob-elixir-test-variable-assignments ()
"Test variable assignment generation."
(let ((params '((:var . ("x" . 5))
(:var . ("name" . "Alice")))))
(let ((assignments (org-babel-variable-assignments:elixir params)))
(should (member "x = 5" assignments))
(should (member "name = \"Alice\"" assignments)))))
(ert-deftest ob-elixir-test-var-execution ()
"Test code execution with variables."
(skip-unless (executable-find ob-elixir-command))
(let* ((params '((:var . ("x" . 10))))
(var-lines (org-babel-variable-assignments:elixir params))
(full-body (concat (mapconcat #'identity var-lines "\n")
"\nx * 2")))
(should (equal "20" (ob-elixir--execute full-body 'value)))))
(ert-deftest ob-elixir-test-var-list ()
"Test passing list as variable."
(skip-unless (executable-find ob-elixir-command))
(let* ((params '((:var . ("data" . (1 2 3)))))
(var-lines (org-babel-variable-assignments:elixir params))
(full-body (concat (mapconcat #'identity var-lines "\n")
"\nEnum.sum(data)")))
(should (equal "6" (ob-elixir--execute full-body 'value)))))
(provide 'test-ob-elixir-vars)
;;; test-ob-elixir-vars.el ends here