removed elixir result parsing

This commit is contained in:
2026-02-18 11:07:02 +01:00
parent 1600d386e1
commit 926a5d5c05
4 changed files with 44 additions and 94 deletions

10
flake.lock generated
View File

@@ -82,8 +82,8 @@
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs_2"
}, },
"locked": { "locked": {
"lastModified": 1769818307, "lastModified": 1770110491,
"narHash": "sha256-FjojfnmW2/jRmbxfk+8yzU9OfqIl1mClNLywzSujSKQ=", "narHash": "sha256-nV2Sq7+y9ocPln5+zLVjV5cvE4E4i7J6TR88OnIPQdA=",
"path": "/conf/jailed-agents", "path": "/conf/jailed-agents",
"type": "path" "type": "path"
}, },
@@ -146,11 +146,11 @@
}, },
"nixpkgs_3": { "nixpkgs_3": {
"locked": { "locked": {
"lastModified": 1769789167, "lastModified": 1770115704,
"narHash": "sha256-kKB3bqYJU5nzYeIROI82Ef9VtTbu4uA3YydSk/Bioa8=", "narHash": "sha256-KHFT9UWOF2yRPlAnSXQJh6uVcgNcWlFqqiAZ7OVlHNc=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "62c8382960464ceb98ea593cb8321a2cf8f9e3e5", "rev": "e6eae2ee2110f3d31110d5c222cd395303343b08",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@@ -21,6 +21,7 @@
package-lint package-lint
relint relint
buttercup buttercup
eldev
]); ]);
devInputs = with pkgs; [ devInputs = with pkgs; [
@@ -35,7 +36,8 @@
{ {
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
packages = devInputs ++ [ packages = devInputs ++ [
(jailed-agents.lib.${system}.makeJailedOpencode system { (jailed-agents.lib.${system}.makeJailed system {
agentTool = "opencode";
extraPkgs = devInputs; extraPkgs = devInputs;
}) })
]; ];

View File

@@ -287,12 +287,7 @@ Handles:
;;; Result Formatting ;;; Result Formatting
(defvar ob-elixir-nil-to 'hline
"Elisp value to use for Elixir nil in table cells.
When nil appears in an Elixir list that becomes a table,
it is replaced with this value. Use `hline' for org table
horizontal lines, or nil for empty cells.")
(defun ob-elixir--parse-value (str) (defun ob-elixir--parse-value (str)
"Parse STR as a simple Elixir value." "Parse STR as a simple Elixir value."
@@ -326,66 +321,14 @@ Handles format like: [a: 1, b: 2]"
pairs))) pairs)))
(nreverse pairs)))))) (nreverse pairs))))))
(defun ob-elixir--sanitize-row (row)
"Sanitize a single ROW for table display."
(if (listp row)
(mapcar (lambda (cell)
(cond
((null cell) ob-elixir-nil-to)
((eq cell 'nil) ob-elixir-nil-to)
(t cell)))
row)
row))
(defun ob-elixir--sanitize-table (data)
"Sanitize DATA for use as an org table.
Replaces nil values according to `ob-elixir-nil-to'.
Ensures consistent structure for table rendering."
(cond
;; Not a list - return as-is
((not (listp data)) data)
;; Empty list
((null data) nil)
;; List of lists - could be table
((and (listp (car data)) (not (null (car data))))
(mapcar #'ob-elixir--sanitize-row data))
;; Simple list - single row
(t (ob-elixir--sanitize-row data))))
(defun ob-elixir--table-or-string (result) (defun ob-elixir--table-or-string (result)
"Convert RESULT to Emacs table or string. "Clean up RESULT string for display.
If RESULT looks like a list, parse it into an Elisp list. Returns the trimmed result string, or nil if empty."
Otherwise return as string.
Uses `org-babel-script-escape' for parsing."
(let ((trimmed (string-trim result))) (let ((trimmed (string-trim result)))
(cond (if (string-empty-p trimmed)
;; Empty result nil
((string-empty-p trimmed) nil) trimmed)))
;; Looks like a list - try to parse
((string-match-p "^\\[.*\\]$" trimmed)
(condition-case nil
(let ((parsed (org-babel-script-escape trimmed)))
(ob-elixir--sanitize-table parsed))
(error trimmed)))
;; Looks like a tuple - convert to list first
((string-match-p "^{.*}$" trimmed)
(condition-case nil
(let* ((as-list (replace-regexp-in-string
"^{\\(.*\\)}$" "[\\1]" trimmed))
(parsed (org-babel-script-escape as-list)))
(ob-elixir--sanitize-table parsed))
(error trimmed)))
;; Scalar value
(t trimmed))))
;;; Variable Handling ;;; Variable Handling

View File

@@ -2,57 +2,62 @@
;;; Commentary: ;;; Commentary:
;; Result formatting and table support tests for ob-elixir package. ;; Result formatting tests for ob-elixir package.
;; Results are returned as plain strings without parsing into elisp structures.
;;; Code: ;;; Code:
(require 'ert) (require 'ert)
(require 'ob-elixir) (require 'ob-elixir)
;;; Parsing Tests ;;; Result String Tests
(ert-deftest ob-elixir-test-parse-simple-list () (ert-deftest ob-elixir-test-result-list-as-string ()
"Test parsing simple list result." "Test that list results are returned as strings."
(should (equal '(1 2 3) (ob-elixir--table-or-string "[1, 2, 3]")))) (should (equal "[1, 2, 3]" (ob-elixir--table-or-string "[1, 2, 3]"))))
(ert-deftest ob-elixir-test-parse-nested-list () (ert-deftest ob-elixir-test-result-nested-list-as-string ()
"Test parsing nested list (table) result." "Test that nested list results are returned as strings."
(should (equal '((1 2) (3 4)) (should (equal "[[1, 2], [3, 4]]"
(ob-elixir--table-or-string "[[1, 2], [3, 4]]")))) (ob-elixir--table-or-string "[[1, 2], [3, 4]]"))))
(ert-deftest ob-elixir-test-parse-tuple () (ert-deftest ob-elixir-test-result-tuple-as-string ()
"Test parsing tuple result." "Test that tuple results are returned as strings."
(should (equal '(1 2 3) (ob-elixir--table-or-string "{1, 2, 3}")))) (should (equal "{1, 2, 3}" (ob-elixir--table-or-string "{1, 2, 3}"))))
(ert-deftest ob-elixir-test-parse-scalar () (ert-deftest ob-elixir-test-result-scalar ()
"Test that scalars are returned as strings." "Test that scalars are returned as strings."
(should (equal "42" (ob-elixir--table-or-string "42"))) (should (equal "42" (ob-elixir--table-or-string "42")))
(should (equal ":ok" (ob-elixir--table-or-string ":ok")))) (should (equal ":ok" (ob-elixir--table-or-string ":ok"))))
(ert-deftest ob-elixir-test-parse-string () (ert-deftest ob-elixir-test-result-string ()
"Test parsing string result." "Test that string results are returned as-is."
(should (equal "\"hello\"" (ob-elixir--table-or-string "\"hello\"")))) (should (equal "\"hello\"" (ob-elixir--table-or-string "\"hello\""))))
(ert-deftest ob-elixir-test-sanitize-table-nil () (ert-deftest ob-elixir-test-result-empty ()
"Test that nil values are sanitized in tables." "Test that empty results return nil."
(let ((ob-elixir-nil-to 'hline)) (should (null (ob-elixir--table-or-string "")))
(should (equal '((1 hline) (hline 2)) (should (null (ob-elixir--table-or-string " "))))
(ob-elixir--sanitize-table '((1 nil) (nil 2)))))))
(ert-deftest ob-elixir-test-execution-returns-table () (ert-deftest ob-elixir-test-result-whitespace-trimmed ()
"Test that list results become tables." "Test that whitespace is trimmed from results."
(should (equal "42" (ob-elixir--table-or-string " 42 ")))
(should (equal "[1, 2]" (ob-elixir--table-or-string "\n[1, 2]\n"))))
(ert-deftest ob-elixir-test-execution-returns-string ()
"Test that execution results are returned as strings."
(skip-unless (executable-find ob-elixir-command)) (skip-unless (executable-find ob-elixir-command))
(let ((result (ob-elixir--table-or-string (let ((result (ob-elixir--table-or-string
(ob-elixir--execute "[[1, 2], [3, 4]]" 'value)))) (ob-elixir--execute "[[1, 2], [3, 4]]" 'value))))
(should (equal '((1 2) (3 4)) result)))) (should (stringp result))
(should (string-match-p "\\[\\[1, 2\\], \\[3, 4\\]\\]" result))))
(ert-deftest ob-elixir-test-mixed-list () (ert-deftest ob-elixir-test-mixed-list-as-string ()
"Test parsing mixed-type list." "Test that mixed-type list results are returned as strings."
(skip-unless (executable-find ob-elixir-command)) (skip-unless (executable-find ob-elixir-command))
(let ((result (ob-elixir--table-or-string (let ((result (ob-elixir--table-or-string
(ob-elixir--execute "[1, \"two\", :three]" 'value)))) (ob-elixir--execute "[1, \"two\", :three]" 'value))))
(should (listp result)) (should (stringp result))))
(should (= 3 (length result)))))
(provide 'test-ob-elixir-results) (provide 'test-ob-elixir-results)
;;; test-ob-elixir-results.el ends here ;;; test-ob-elixir-results.el ends here