;;; test-ob-elixir-imports.el --- Imports block tests -*- lexical-binding: t; -*- ;;; Commentary: ;; Tests for the imports block functionality. ;;; Code: (require 'ert) (require 'ob-elixir) ;;; Imports Block Parsing Tests (ert-deftest ob-elixir-test-imports-block-parsing () "Test that imports blocks are correctly parsed." (with-temp-buffer (insert "#+BEGIN_IMPORTS elixir\nimport Enum\nalias Foo\n#+END_IMPORTS\n") (goto-char (point-max)) (let ((imports (ob-elixir--find-imports-for-position (point)))) (should imports) (should (string-match-p "import Enum" imports)) (should (string-match-p "alias Foo" imports))))) (ert-deftest ob-elixir-test-no-imports-block () "Test that nil is returned when no imports block exists." (with-temp-buffer (insert "#+begin_src elixir\n1 + 1\n#+end_src\n") (should (null (ob-elixir--find-imports-for-position (point)))))) (ert-deftest ob-elixir-test-imports-block-before-position () "Test that imports block must be before position." (with-temp-buffer (insert "#+begin_src elixir\n1 + 1\n#+end_src\n") (let ((pos (point))) (insert "#+BEGIN_IMPORTS elixir\nimport Enum\n#+END_IMPORTS\n") (should (null (ob-elixir--find-imports-for-position pos)))))) (ert-deftest ob-elixir-test-imports-block-override () "Test that later imports blocks override earlier ones." (with-temp-buffer (insert "#+BEGIN_IMPORTS elixir\nimport Enum\n#+END_IMPORTS\n") (insert "#+BEGIN_IMPORTS elixir\nimport String\n#+END_IMPORTS\n") (goto-char (point-max)) (let ((imports (ob-elixir--find-imports-for-position (point)))) (should imports) (should (string-match-p "import String" imports)) (should-not (string-match-p "import Enum" imports))))) ;;; Imports Execution Tests (ert-deftest ob-elixir-test-imports-execution () "Test that imports are applied during execution." (skip-unless (executable-find ob-elixir-command)) ;; Ensure org-babel is loaded with Elixir support (setq org-confirm-babel-evaluate nil) (org-babel-do-load-languages 'org-babel-load-languages '((elixir . t))) (with-temp-buffer (org-mode) (insert "#+BEGIN_IMPORTS elixir\nimport Enum\n#+END_IMPORTS\n\n") (insert "#+begin_src elixir :results value\nmap([1,2,3], &(&1 * 2))\n#+end_src\n") (goto-char (point-min)) (search-forward "#+begin_src") (let ((result (org-babel-execute-src-block))) ;; Without import, this would fail because map/2 requires Enum prefix (should result) (should (equal result '(2 4 6)))))) (ert-deftest ob-elixir-test-imports-with-alias () "Test that alias works in imports block." (skip-unless (executable-find ob-elixir-command)) ;; Ensure org-babel is loaded with Elixir support (setq org-confirm-babel-evaluate nil) (org-babel-do-load-languages 'org-babel-load-languages '((elixir . t))) (with-temp-buffer (org-mode) (insert "#+BEGIN_IMPORTS elixir\nalias String, as: S\n#+END_IMPORTS\n\n") (insert "#+begin_src elixir :results value\nS.upcase(\"hello\")\n#+end_src\n") (goto-char (point-min)) (search-forward "#+begin_src") (let ((result (org-babel-execute-src-block))) (should (equal result "\"HELLO\""))))) (provide 'test-ob-elixir-imports) ;;; test-ob-elixir-imports.el ends here