diff tests/farray-array.t @ 764:711c0a11d642

farray.sh: Implement farray_insert()
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 21 Oct 2024 15:38:01 +0200
parents 7ead30e3b2f9
children 54fefbabcf78
line wrap: on
line diff
--- a/tests/farray-array.t	Mon Oct 21 15:14:48 2024 +0200
+++ b/tests/farray-array.t	Mon Oct 21 15:38:01 2024 +0200
@@ -348,6 +348,78 @@
   $ check_no_array_artifacts
 
 
+Inserting
+=========
+
+Append
+
+  $ farray_create TEST 0 1 2 '3  4   5' $'" 678" \\\'910 ' 11
+  $ farray_insert TEST "" $'the new appended value \\ \''
+  $ farray_debug TEST
+  DEBUG: array `TEST' has length 7
+  DEBUG:   the items:
+  DEBUG:     1: `0'
+  DEBUG:     2: `1'
+  DEBUG:     3: `2'
+  DEBUG:     4: `3  4   5'
+  DEBUG:     5: `" 678" \'910 '
+  DEBUG:     6: `11'
+  DEBUG:     7: `the new appended value \ ''
+  $ farray_release TEST
+  $ check_no_array_artifacts
+
+Prepend
+
+  $ farray_create TEST 0 1 2 '3  4   5' $'" 678" \\\'910 ' 11
+  $ farray_insert TEST 1 $'the new prepended value \\ \''
+  $ farray_debug TEST
+  DEBUG: array `TEST' has length 7
+  DEBUG:   the items:
+  DEBUG:     1: `the new prepended value \ ''
+  DEBUG:     2: `0'
+  DEBUG:     3: `1'
+  DEBUG:     4: `2'
+  DEBUG:     5: `3  4   5'
+  DEBUG:     6: `" 678" \'910 '
+  DEBUG:     7: `11'
+  $ farray_release TEST
+  $ check_no_array_artifacts
+
+In the middle
+
+  $ farray_create TEST 0 1 2 '3  4   5' $'" 678" \\\'910 ' 11
+  $ farray_insert TEST 2 $'the new inserted value \\ \''
+  $ farray_debug TEST
+  DEBUG: array `TEST' has length 7
+  DEBUG:   the items:
+  DEBUG:     1: `0'
+  DEBUG:     2: `the new inserted value \ ''
+  DEBUG:     3: `1'
+  DEBUG:     4: `2'
+  DEBUG:     5: `3  4   5'
+  DEBUG:     6: `" 678" \'910 '
+  DEBUG:     7: `11'
+  $ farray_release TEST
+  $ check_no_array_artifacts
+
+Out of bounds
+
+  $ farray_create TEST 0 1 2 '3  4   5' $'" 678" \\\'910 ' 11
+  $ (farray_insert TEST 8 $'the new inserted value \\ \'')
+  ERROR: array index out of bounds
+  [70]
+  $ farray_release TEST
+  $ check_no_array_artifacts
+
+Missing value
+
+  $ farray_create TEST 0 1 2 '3  4   5' $'" 678" \\\'910 ' 11
+  $ (farray_insert TEST 0)
+  ERROR: missing value to insert
+  [70]
+  $ farray_release TEST
+  $ check_no_array_artifacts
+
 Splicing
 ========