removed elixir result parsing
This commit is contained in:
10
flake.lock
generated
10
flake.lock
generated
@@ -82,8 +82,8 @@
|
||||
"nixpkgs": "nixpkgs_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1769818307,
|
||||
"narHash": "sha256-FjojfnmW2/jRmbxfk+8yzU9OfqIl1mClNLywzSujSKQ=",
|
||||
"lastModified": 1770110491,
|
||||
"narHash": "sha256-nV2Sq7+y9ocPln5+zLVjV5cvE4E4i7J6TR88OnIPQdA=",
|
||||
"path": "/conf/jailed-agents",
|
||||
"type": "path"
|
||||
},
|
||||
@@ -146,11 +146,11 @@
|
||||
},
|
||||
"nixpkgs_3": {
|
||||
"locked": {
|
||||
"lastModified": 1769789167,
|
||||
"narHash": "sha256-kKB3bqYJU5nzYeIROI82Ef9VtTbu4uA3YydSk/Bioa8=",
|
||||
"lastModified": 1770115704,
|
||||
"narHash": "sha256-KHFT9UWOF2yRPlAnSXQJh6uVcgNcWlFqqiAZ7OVlHNc=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "62c8382960464ceb98ea593cb8321a2cf8f9e3e5",
|
||||
"rev": "e6eae2ee2110f3d31110d5c222cd395303343b08",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
package-lint
|
||||
relint
|
||||
buttercup
|
||||
eldev
|
||||
]);
|
||||
|
||||
devInputs = with pkgs; [
|
||||
@@ -35,7 +36,8 @@
|
||||
{
|
||||
devShells.default = pkgs.mkShell {
|
||||
packages = devInputs ++ [
|
||||
(jailed-agents.lib.${system}.makeJailedOpencode system {
|
||||
(jailed-agents.lib.${system}.makeJailed system {
|
||||
agentTool = "opencode";
|
||||
extraPkgs = devInputs;
|
||||
})
|
||||
];
|
||||
|
||||
67
ob-elixir.el
67
ob-elixir.el
@@ -287,12 +287,7 @@ Handles:
|
||||
|
||||
;;; 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)
|
||||
"Parse STR as a simple Elixir value."
|
||||
@@ -326,66 +321,14 @@ Handles format like: [a: 1, b: 2]"
|
||||
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)
|
||||
"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.
|
||||
Otherwise return as string.
|
||||
|
||||
Uses `org-babel-script-escape' for parsing."
|
||||
Returns the trimmed result string, or nil if empty."
|
||||
(let ((trimmed (string-trim result)))
|
||||
(cond
|
||||
;; Empty result
|
||||
((string-empty-p trimmed) nil)
|
||||
|
||||
;; 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))))
|
||||
(if (string-empty-p trimmed)
|
||||
nil
|
||||
trimmed)))
|
||||
|
||||
;;; Variable Handling
|
||||
|
||||
|
||||
@@ -2,57 +2,62 @@
|
||||
|
||||
;;; 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:
|
||||
|
||||
(require 'ert)
|
||||
(require 'ob-elixir)
|
||||
|
||||
;;; Parsing Tests
|
||||
;;; Result String Tests
|
||||
|
||||
(ert-deftest ob-elixir-test-parse-simple-list ()
|
||||
"Test parsing simple list result."
|
||||
(should (equal '(1 2 3) (ob-elixir--table-or-string "[1, 2, 3]"))))
|
||||
(ert-deftest ob-elixir-test-result-list-as-string ()
|
||||
"Test that list results are returned as strings."
|
||||
(should (equal "[1, 2, 3]" (ob-elixir--table-or-string "[1, 2, 3]"))))
|
||||
|
||||
(ert-deftest ob-elixir-test-parse-nested-list ()
|
||||
"Test parsing nested list (table) result."
|
||||
(should (equal '((1 2) (3 4))
|
||||
(ert-deftest ob-elixir-test-result-nested-list-as-string ()
|
||||
"Test that nested list results are returned as strings."
|
||||
(should (equal "[[1, 2], [3, 4]]"
|
||||
(ob-elixir--table-or-string "[[1, 2], [3, 4]]"))))
|
||||
|
||||
(ert-deftest ob-elixir-test-parse-tuple ()
|
||||
"Test parsing tuple result."
|
||||
(should (equal '(1 2 3) (ob-elixir--table-or-string "{1, 2, 3}"))))
|
||||
(ert-deftest ob-elixir-test-result-tuple-as-string ()
|
||||
"Test that tuple results are returned as strings."
|
||||
(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."
|
||||
(should (equal "42" (ob-elixir--table-or-string "42")))
|
||||
(should (equal ":ok" (ob-elixir--table-or-string ":ok"))))
|
||||
|
||||
(ert-deftest ob-elixir-test-parse-string ()
|
||||
"Test parsing string result."
|
||||
(ert-deftest ob-elixir-test-result-string ()
|
||||
"Test that string results are returned as-is."
|
||||
(should (equal "\"hello\"" (ob-elixir--table-or-string "\"hello\""))))
|
||||
|
||||
(ert-deftest ob-elixir-test-sanitize-table-nil ()
|
||||
"Test that nil values are sanitized in tables."
|
||||
(let ((ob-elixir-nil-to 'hline))
|
||||
(should (equal '((1 hline) (hline 2))
|
||||
(ob-elixir--sanitize-table '((1 nil) (nil 2)))))))
|
||||
(ert-deftest ob-elixir-test-result-empty ()
|
||||
"Test that empty results return nil."
|
||||
(should (null (ob-elixir--table-or-string "")))
|
||||
(should (null (ob-elixir--table-or-string " "))))
|
||||
|
||||
(ert-deftest ob-elixir-test-execution-returns-table ()
|
||||
"Test that list results become tables."
|
||||
(ert-deftest ob-elixir-test-result-whitespace-trimmed ()
|
||||
"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))
|
||||
(let ((result (ob-elixir--table-or-string
|
||||
(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 ()
|
||||
"Test parsing mixed-type list."
|
||||
(ert-deftest ob-elixir-test-mixed-list-as-string ()
|
||||
"Test that mixed-type list results are returned as strings."
|
||||
(skip-unless (executable-find ob-elixir-command))
|
||||
(let ((result (ob-elixir--table-or-string
|
||||
(ob-elixir--execute "[1, \"two\", :three]" 'value))))
|
||||
(should (listp result))
|
||||
(should (= 3 (length result)))))
|
||||
(should (stringp result))))
|
||||
|
||||
(provide 'test-ob-elixir-results)
|
||||
;;; test-ob-elixir-results.el ends here
|
||||
|
||||
Reference in New Issue
Block a user