>From 42975ddf6e8bd3ba39328989e9baf016ab510077 Mon Sep 17 00:00:00 2001
From: Matt <matt@excalamus.com>
Date: Wed, 21 Dec 2022 00:45:44 -0500
Subject: [PATCH 7/7] Refactor ob-shell/bash-uses-assoc-arrays

- Split cases into separate tests
- Rename "ob-shell" to "test-ob-shell"
- Remove external file dependency
---
 testing/lisp/test-ob-shell.el | 51 ++++++++++++++++++++++++++---------
 1 file changed, 38 insertions(+), 13 deletions(-)

diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index ed73a1cd9..1404647b9 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -146,21 +146,46 @@ as a single string."
      (equal "bread 2 kg spaghetti 20 cm milk 50 dl"
             (org-trim (org-babel-execute-src-block))))))
 
-(ert-deftest ob-shell/bash-uses-assoc-arrays ()
-  "Bash associative arrays"
-  (should
-   (equal "two"
-          (org-test-at-id
-           "bec1a5b0-4619-4450-a8c0-2a746b44bf8d"
-           (org-babel-next-src-block 2)
-           (org-trim (org-babel-execute-src-block)))))
-  ;; Bash associative arrays as strings for the row.
+(ert-deftest test-ob-shell/bash-uses-assoc-arrays ()
+  "Bash shell: support for associative arrays
+
+Bash will see a table that contains the first column as the
+'index' of the associative array, and the second column as the
+value. "
+  (org-test-with-temp-text
+      (multiline-string
+       "#+NAME: sample_mapping_table"
+       "| first  | one   |"
+       "| second | two   |"
+       "| third  | three |"
+       ""
+       "#+begin_src bash :exports :results output results :var table=sample_mapping_table"
+       "echo ${table[second]}"
+       "<point>"
+       "#+end_src")
+    (should
+     (equal "two"
+            (org-trim (org-babel-execute-src-block))))))
+
+(ert-deftest test-ob-shell/bash-uses-assoc-arrays-with-lists ()
+  "Bash shell: support for associative arrays with lists
+
+Bash will see an associative array that contains each row as a single
+string. Bash cannot handle lists in associative arrays."
+  (org-test-with-temp-text
+      (multiline-string
+       "#+NAME: sample_big_table"
+       "| bread     |  2 | kg |"
+       "| spaghetti | 20 | cm |"
+       "| milk      | 50 | dl |"
+       ""
+       "#+begin_src bash :exports results :results output :var table=sample_big_table"
+       "echo ${table[spaghetti]}"
+       "<point>"
+       "#+end_src")
   (should
    (equal "20 cm"
-          (org-test-at-id
-           "82320a48-3409-49d7-85c9-5de1c6d3ff87"
-           (org-babel-next-src-block 2)
-           (org-trim (org-babel-execute-src-block))))))
+          (org-trim (org-babel-execute-src-block))))))
 
 (ert-deftest ob-shell/simple-list ()
   "Test list variables in shell."
-- 
2.38.1

