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

59 lines
1.9 KiB
EmacsLisp

;;; test-ob-elixir.el --- Tests for ob-elixir -*- lexical-binding: t; -*-
;;; Commentary:
;; Test suite for ob-elixir package.
;;; Code:
(require 'ert)
;; Add parent directory to load path
(let ((dir (file-name-directory (or load-file-name buffer-file-name))))
(add-to-list 'load-path (expand-file-name ".." dir)))
(require 'ob-elixir)
(ert-deftest ob-elixir-test-package-loads ()
"Test that the package loads successfully."
(should (featurep 'ob-elixir)))
(ert-deftest ob-elixir-test-elixir-available ()
"Test that Elixir is available."
(should (executable-find ob-elixir-command)))
(ert-deftest ob-elixir-test-simple-value ()
"Test simple value evaluation."
(skip-unless (executable-find ob-elixir-command))
(let ((result (ob-elixir--execute "1 + 1" 'value)))
(should (equal "2" result))))
(ert-deftest ob-elixir-test-simple-output ()
"Test simple output evaluation."
(skip-unless (executable-find ob-elixir-command))
(let ((result (ob-elixir--execute "IO.puts(\"hello\")" 'output)))
(should (equal "hello" result))))
(ert-deftest ob-elixir-test-multiline-value ()
"Test multiline code value evaluation."
(skip-unless (executable-find ob-elixir-command))
(let ((result (ob-elixir--execute "x = 10\ny = 20\nx + y" 'value)))
(should (equal "30" result))))
(ert-deftest ob-elixir-test-list-result ()
"Test list result."
(skip-unless (executable-find ob-elixir-command))
(let ((result (ob-elixir--execute "[1, 2, 3]" 'value)))
(should (equal "[1, 2, 3]" result))))
(ert-deftest ob-elixir-test-map-result ()
"Test map result."
(skip-unless (executable-find ob-elixir-command))
(let ((result (ob-elixir--execute "%{a: 1, b: 2}" 'value)))
;; Maps are unordered in Elixir, so accept either order
(should (or (string-match-p "%{a: 1, b: 2}" result)
(string-match-p "%{b: 2, a: 1}" result)))))
(provide 'test-ob-elixir)
;;; test-ob-elixir.el ends here