3c7e75ab0b
* lisp/ob-shell.el: added support to serialize vars as arrays or associative arrays as appropriate if it is using bash. * testing/examples/ob-shell-test.org: a file containing a few code blocks both illustrating the use of arrays as well as serving as test for the new export functionality. * testing/lisp/test-ob-shell.el: added a few unit tests that verify that this new logic only triggers for bash and no other shell at this time. When variables are defined in a 'sh' code block, they are exported as strings. when the variable itself is an array or a table, then we simply get a shell variable that contains the list of all values in a non-structured form. When calling the code block with bash, however, it will now export the list as an array, the table as an associative array. A scalar is exported the same way as before. Signed-off-by: Pascal Fleury <fleury@google.com>
2.1 KiB
2.1 KiB
a collection of examples for ob-shell tests
- Sample data structures
- Array tests
- Associative array tests (simple map)
- Associative array tests (more than 2 columns)
Sample data structures
one |
two |
three |
first | one |
second | two |
third | three |
bread | 2 | kg |
spaghetti | 20 | cm |
milk | 50 | dl |
Array tests
Generic shell: no arrays
one two three
Bash shell: support for arrays
Bash will see a simple indexed array. In this test, we check that the returned value is indeed only the first item of the array, as opposed to the generic serialiation that will return all elements of the array as a single string.
one
Associative array tests (simple map)
Generic shell: no special handing
The shell will see all values as a single string.
first one second two third three
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.
two
Associative array tests (more than 2 columns)
Generic shell: no special handing
bread 2 kg spaghetti 20 cm milk 50 dl
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.
20 cm