From 7f7c386439265cca9d9f121cdf34fd87845548a4 Mon Sep 17 00:00:00 2001 From: tsi Date: Sat, 3 Jan 2026 01:32:34 +0100 Subject: [PATCH] Add unit tests and testing framework --- tests | 271 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 271 insertions(+) create mode 100755 tests diff --git a/tests b/tests new file mode 100755 index 0000000..bc98b78 --- /dev/null +++ b/tests @@ -0,0 +1,271 @@ +#!/usr/bin/env bash + +printf_if_clr () { + [[ -v NO_COLOR ]] && return + [[ -v FORCE_COLOR ]] || [[ -v CLIFORCE_COLOR ]] && { printf "$@"; return; } + [[ -v CLICOLOR ]] || [[ -v TERM ]] && [[ -t 1 ]] && { printf "$@"; return; } + + # Fallback behavior + [[ -t 1 ]] && printf "$@" + +} +log () { + clr=$1 + shift + case "$clr" in + (white) printf_if_clr '\033[97m' ;; + (grey) printf_if_clr '\033[90m' ;; + (green) printf_if_clr '\033[92m' ;; + (red) printf_if_clr '\033[91m' ;; + (*) printf_if_clr '\033[m' + esac + printf "$@" + printf_if_clr '\033[m' +} +white () { log white "$@"; } +grey () { log grey "$@"; } +green () { log green "$@"; } +red () { log red "$@"; } + +init () { + white '## Unit tests for bash-abbr ##\n' + white '# Running on bash version %s system type %s\n' "${BASH_VERSION@Q}" "${MACHTYPE@Q}" + . bash-abbr || { red 'Failed to source bash-abbr\n'; exit 1; } + unalias -a + declare -gi tests_passed=0 tests_failed=0 tests_total=0 + [[ $1 ]] && declare -gi isolate_test=$1 || declare -gi isolate_test=0 +} + +# inherits all variables from test_abbr function +check () { + [[ ! $new_test_line = "$expected_line" ]] && { red 'Test %s "%s" failed: Line %s did not expand to expected line %s, but %s\n' "$tests_total" "$test_name" "${test_line@Q}" "${expected_line@Q}" "${new_test_line@Q}"; return 1; } + [[ ! $new_test_point = "$expected_point" ]] && { red 'Test %s "%s" failed: Point was %s and did not update to %s, but %s\n' "$tests_total" "$test_name" "${test_point@Q}" "${expected_point@Q}" "${new_test_point@Q}"; return 2; } + [[ ! $new_test_mark = "$expected_mark" ]] && { red 'Test %s "%s" failed: Mark was %s and did not update to %s, but %s\n' "$tests_total" "$test_name" "${test_mark@Q}" "${expected_mark@Q}" "${new_test_mark@Q}"; return 3; } + return 0; +} + +test_abbr () { + tests_total+=1 + [[ isolate_test -gt 0 && isolate_test -ne tests_total ]] && return + + declare test_name=$1 + declare test_line=$2 new_test_line + declare test_point=$3 new_test_point + declare test_mark=$4 new_test_mark + declare expected_line=$5 + declare expected_point=$6 + declare expected_mark=$7 + declare insertion_char=$8 + shift 8 + + unalias -a + alias "$@" + + declare -gA _expanded_aliases=() + _try_abbrev_internal "$test_line" "$test_point" "$test_mark" new_test_line new_test_point new_test_mark "$insertion_char" + unset -v _expanded_aliases + + check && tests_passed+=1 || tests_failed+=1 +} + +summary () { + white 'Total number of tests: %q\n' "$tests_total" + grey 'Tests skipped: %q\n' "$((tests_total - tests_passed - tests_failed))" + green 'Tests passed: %q\n' "$tests_passed" + red 'Tests failed: %q\n' "$tests_failed" +} + +init "$@" + +# empty insertion char means a newline (or a similar accept-line command) was used + +test_abbr "expand regular alias when followed by a space at EOL" 'foo' '3' '0' 'barr ' '5' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when followed by a tab at EOL" 'foo' '3' '0' 'barr ' '5' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when followed by a newline at EOL" 'foo' '3' '0' 'barr' '4' '0' '' 'foo=barr' +test_abbr "expand regular alias when followed by a ')' at EOL" 'foo' '3' '0' 'barr ' '5' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when followed by a '(' at EOL" 'foo' '3' '0' 'barr ' '5' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when followed by a '<' at EOL" 'foo' '3' '0' 'barr ' '5' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when followed by a '>' at EOL" 'foo' '3' '0' 'barr ' '5' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when followed by a '&' at EOL" 'foo' '3' '0' 'barr ' '5' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when followed by a ';' at EOL" 'foo' '3' '0' 'barr ' '5' '0' ' ' 'foo=barr' + +test_abbr "don't expand regular alias when followed by a ']' at EOL" 'foo' '3' '0' 'foo]' '4' '0' ']' 'foo=barr' +test_abbr "don't expand regular alias when followed by a '[' at EOL" 'foo' '3' '0' 'foo[' '4' '0' '[' 'foo=barr' +test_abbr "don't expand regular alias when followed by a '}' at EOL" 'foo' '3' '0' 'foo}' '4' '0' '}' 'foo=barr' +test_abbr "don't expand regular alias when followed by a '.' at EOL" 'foo' '3' '0' 'foo.' '4' '0' '.' 'foo=barr' +test_abbr "don't expand regular alias when followed by a 'b' at EOL" 'foo' '3' '0' 'foob' '4' '0' 'b' 'foo=barr' + +test_abbr "expand regular alias when followed by a space inside word" 'foobar' '3' '0' 'barr bar' '5' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when followed by a tab inside word" 'foobar' '3' '0' 'barr bar' '5' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when followed by a ) inside word" 'foobar' '3' '0' 'barr bar' '5' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when followed by a ( inside word" 'foobar' '3' '0' 'barr bar' '5' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when followed by a < inside word" 'foobar' '3' '0' 'barr bar' '5' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when followed by a > inside word" 'foobar' '3' '0' 'barr bar' '5' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when followed by a & inside word" 'foobar' '3' '0' 'barr bar' '5' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when followed by a ; inside word" 'foobar' '3' '0' 'barr bar' '5' '0' ' ' 'foo=barr' + +test_abbr "don't expand regular alias when followed by a newline inside word" 'foobar' '3' '0' 'foobar' '6' '0' '' 'foo=barr' + +test_abbr "don't expand regular alias when space is entered at the beginning" 'foo' '0' '0' ' foo' '1' '0' ' ' 'foo=barr' +test_abbr "don't expand regular alias when space is entered after 1st character inside alias" 'foo' '1' '0' 'f oo' '2' '0' ' ' 'foo=barr' +test_abbr "don't expand regular alias when space is entered before last character inside alias" 'foo' '2' '0' 'fo o' '3' '0' ' ' 'foo=barr' + +test_abbr "expand regular alias when newline is entered at the beginning" 'foo' '0' '0' 'barr' '4' '0' '' 'foo=barr' +test_abbr "expand regular alias when newline is entered after 1st character inside alias" 'foo' '1' '0' 'barr' '4' '0' '' 'foo=barr' +test_abbr "expand regular alias when newline is entered before last character inside alias" 'foo' '2' '0' 'barr' '4' '0' '' 'foo=barr' + +test_abbr "recursively expand regular alias once" 'foo' '3' '0' 'bazqux ' '7' '0' ' ' 'foo=bar' 'bar=bazqux' +test_abbr "recursively expand regular alias twice" 'foo' '3' '0' 'wowitworks ' '11' '0' ' ' 'foo=bar' 'bar=bazqux' 'bazqux=wowitworks' +test_abbr "recursively expand regular alias thrice with a shorter final alias" 'foo' '3' '0' 'shorter ' '8' '0' ' ' 'foo=bar' 'bar=bazqux' 'bazqux=wowitworks' 'wowitworks=shorter' + +test_abbr "don't recursively expand regular alias infinitely (0 indirections)" 'foo' '3' '0' 'foo ' '4' '0' ' ' 'foo=foo' +test_abbr "don't recursively expand regular alias infinitely (1 indirection)" 'foo' '3' '0' 'foo ' '4' '0' ' ' 'foo=bar' 'bar=foo' +test_abbr "don't recursively expand regular alias infinitely (2 indirections)" 'foo' '3' '0' 'foo ' '4' '0' ' ' 'foo=bar' 'bar=baz' 'baz=foo' +test_abbr "don't recursively expand regular alias infinitely (3 indirections)" 'foo' '3' '0' 'foo ' '4' '0' ' ' 'foo=bar' 'bar=baz' 'baz=qux' 'qux=foo' + +test_abbr "don't recursively expand regular alias infinitely (1 indirection, different lengths)" 'foo' '3' '0' 'foo ' '4' '0' ' ' 'foo=b' 'b=foo' +test_abbr "don't recursively expand regular alias infinitely (2 indirections, different lengths)" 'foo' '3' '0' 'foo ' '4' '0' ' ' 'foo=ba' 'ba=bazz' 'bazz=foo' +test_abbr "don't recursively expand regular alias infinitely (3 indirections, different lengths)" 'foo' '3' '0' 'foo ' '4' '0' ' ' 'foo=barst' 'barst=b' 'b=quxio' 'quxio=foo' + +# Note that there are two spaces after the `foo=` because a single spaces is used as an escape mechanism for different alias flags like * or $. See later test cases. +test_abbr "recursively expand regular alias when alias value has leading spaces before the first command word" 'foo' '3' '0' ' cool ' '7' '0' ' ' 'foo= bar' 'bar=cool' +test_abbr "recursively expand regular alias when alias value has leading tabs before the first command word" 'foo' '3' '0' $'\t\tcool ' '7' '0' ' ' $'foo=\t\tbar' 'bar=cool' +test_abbr "recursively expand regular alias when alias value has leading spaces and assignment words before the first command word" 'foo' '3' '0' ' a=1 b=2 cool ' '14' '0' ' ' 'foo= a=1 b=2 bar' 'bar=cool' +test_abbr "recursively expand regular alias when alias value has leading spaces and redirections before the first command word" 'foo' '3' '0' ' 3>/dev/null 2>&1- cool ' '24' '0' ' ' 'foo= 3>/dev/null 2>&1- bar' 'bar=cool' + +test_abbr "recursively expand regular alias when entering a newline mid-word" 'foo' '2' '0' 'cool' '4' '0' '' 'foo=bar' 'bar=cool' + +test_abbr "don't expand regular alias when value is empty" 'foo' '3' '0' 'foo ' '4' '0' ' ' 'foo=' + +test_abbr "expand regular alias when it has a leading assignment word with spaces" 'A=1 foo' '7' '0' 'A=1 barr ' '9' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has leading assignment words with spaces" 'A=1 B=2 C=3 foo' '20' '0' 'A=1 B=2 C=3 barr ' '22' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has leading assignment words with spaces and tabs" $'A=1 \t B=2\t C=3\tfoo' '19' '0' $'A=1 \t B=2\t C=3\tbarr ' '21' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading null assignment word" 'A= foo' '6' '0' 'A= barr ' '8' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has two leading null assignment words" 'A= B= foo' '9' '0' 'A= B= barr ' '11' '0' ' ' 'foo=barr' + +test_abbr "expand regular alias when it has a leading single-quoted assignment word without spaces" "A='whatever' foo" '16' '0' "A='whatever' barr " '18' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading single-quoted assignment word with spaces" "A='what ever' foo" '17' '0' "A='what ever' barr " '19' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading dollar single-quoted assignment word with spaces" "A=$'what ever' foo" '18' '0' "A=$'what ever' barr " '20' '0' ' ' 'foo=barr' + +test_abbr "expand regular alias when it has a leading double-quoted assignment word without spaces" 'A="whatever" foo' '16' '0' 'A="whatever" barr ' '18' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading double-quoted assignment word with spaces" 'A="what ever" foo' '17' '0' 'A="what ever" barr ' '19' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading double-quoted assignment word with spaces and an escaped double quote" 'A="what \"ever" foo' '19' '0' 'A="what \"ever" barr ' '21' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading dollar double-quoted assignment word with spaces" 'A=$"what ever" foo' '18' '0' 'A=$"what ever" barr ' '20' '0' ' ' 'foo=barr' + +test_abbr "expand regular alias when it has a leading assignment word with backtick command substitution with spaces" 'A=`what ever` foo' '17' '0' 'A=`what ever` barr ' '19' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading assignment word with normal command substitution with spaces" 'A=$(echo hi; arbitrary commands; no nesting allowed!; literally anyhing '\'' " > @ [ ] { } ;) foo' '97' '0' 'A=$(echo hi; arbitrary commands; no nesting allowed!; literally anyhing '\'' " > @ [ ] { } ;) barr ' '99' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading assignment word with deprecated arithmetic expansion with spaces" 'A=$[1 + 1, 2 ** 4#2] foo' '24' '0' 'A=$[1 + 1, 2 ** 4#2] barr ' '26' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading assignment word with normal arithmetic expansion with spaces" 'A=$((1 + 1, 2 ** 4#2)) foo' '26' '0' 'A=$((1 + 1, 2 ** 4#2)) barr ' '28' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading assignment word with simple variable expansion" 'A=$FOO foo' '10' '0' 'A=$FOO barr ' '12' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading assignment word with special variable expansion" 'A=$- foo' '8' '0' 'A=$- barr ' '10' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading assignment word with simple braced variable expansion" 'A=${FOO} foo' '12' '0' 'A=${FOO} barr ' '14' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading assignment word with special braced variable expansion" 'A=${-} foo' '12' '0' 'A=${-} barr ' '14' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading assignment word with advanced braced variable expansion" 'A=${FOO: -1:2} foo' '18' '0' 'A=${FOO: -1:2} barr ' '20' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading assignment word with advanced special braced variable expansion" 'A=${-: -1:2} foo' '16' '0' 'A=${-: -1:2} barr ' '18' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading assignment word with process substitution with spaces" 'A=<(echo bla) foo' '17' '0' 'A=<(echo bla) barr ' '19' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading backslash quoted assignment word with spaces" 'A=what\ ever foo' '16' '0' 'A=what\ ever barr ' '18' '0' ' ' 'foo=barr' + +test_abbr "expand regular alias when it has multiple leading complex assignment words separated by multiple spaces or tabs" \ + $'_A= B=2 \t \t C=<(echo bla; whatever)test$(bla bla bla)` hey`\'quoted string\'"another \\"one\\""$(( 1+1 ))$[ 2**2 ]$\'and another one\'$"translated \\"string"\\.\\ \\c\\o\\o\\l$foo${bar}${baz%%hey}$-$1${10}\tD=cool foo' '207' '0' \ + $'_A= B=2 \t \t C=<(echo bla; whatever)test$(bla bla bla)` hey`\'quoted string\'"another \\"one\\""$(( 1+1 ))$[ 2**2 ]$\'and another one\'$"translated \\"string"\\.\\ \\c\\o\\o\\l$foo${bar}${baz%%hey}$-$1${10}\tD=cool barr ' '209' '0' \ + ' ' 'foo=barr' + +test_abbr "don't expand regular alias when there's an invalid assignment word (0what=1)" '0what=1 foo' '11' '0' '0what=1 foo ' '12' '0' ' ' 'foo=barr' +test_abbr "don't expand regular alias when there's an invalid assignment word (what=\$[[hey]])" 'what=$[[hey]] foo' '17' '0' 'what=$[[hey]] foo ' '18' '0' ' ' 'foo=barr' + +test_abbr "expand regular alias when it has a leading output redirection" '>/dev/null foo' '14' '0' '>/dev/null barr ' '16' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading output redirection with tabs and spaces" $'> \t /dev/null foo' '17' '0' $'> \t /dev/null barr ' '19' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading input redirection" '>hey foo' '9' '0' '>>hey barr ' '11' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading noclobber output redirection" '>|hey foo' '9' '0' '>|hey barr ' '11' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading output redirection with fd" '5>hey foo' '9' '0' '5>hey barr ' '11' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading output redirection with a {varname}" '{bla}>hey foo' '13' '0' '{bla}>hey barr ' '15' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading read-write redirection" '<>file foo' '10' '0' '<>file barr ' '12' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading file descriptor close redirection" '>&- foo' '7' '0' '>&- barr ' '9' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading file descriptor move redirection" '>&5- foo' '8' '0' '>&5- barr ' '10' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has a leading file descriptor move redirection with fd" '6>&5- foo' '9' '0' '6>&5- barr ' '11' '0' ' ' 'foo=barr' + +test_abbr "expand regular alias when it has multiple leading redirections" '>/dev/null 2>&1 2>/dev/null 3<>file 3>&4- foo' '45' '0' '>/dev/null 2>&1 2>/dev/null 3<>file 3>&4- barr ' '47' '0' ' ' 'foo=barr' + +test_abbr "expand regular alias when it has multiple leading complex redirections separated by multiple spaces or tabs" \ + $'<|../log &- 3<&- 4>&1- >/dev/null 2>&3 \t \t 5<><(echo bla; whatever)test$(bla bla bla)` hey`\'quoted string\'"another \\"one\\""$(( 1+1 ))$[ 2**2 ]$\'and another one\'$"translated \\"string"\\.\\ \\c\\o\\o\\l$foo${bar}${baz%%hey}$-$1${10}\t<<|../log &- 3<&- 4>&1- >/dev/null 2>&3 \t \t 5<><(echo bla; whatever)test$(bla bla bla)` hey`\'quoted string\'"another \\"one\\""$(( 1+1 ))$[ 2**2 ]$\'and another one\'$"translated \\"string"\\.\\ \\c\\o\\o\\l$foo${bar}${baz%%hey}$-$1${10}\t<</dev/null A=1 1>&3- <>file \t _B=$(hello world)"cool"$VAR << <(test) foo' '74' '0' \ + $' >/dev/null A=1 1>&3- <>file \t _B=$(hello world)"cool"$VAR << <(test) barr ' '76' '0' \ + ' ' 'foo=barr' + +test_abbr "don't expand regular alias when there's an invalid redirection operator (6<>&5-)" '6<>&5- foo' '10' '0' '6<>&5- foo ' '11' '0' ' ' 'foo=barr' +test_abbr "don't expand regular alias when there's an invalid redirection operator (>>>)" '>>> foo' '7' '0' '>>> foo ' '8' '0' ' ' 'foo=barr' +test_abbr "don't expand regular alias when there's an invalid redirection operator ({0fail}>file)" '{0fail}>file foo' '16' '0' '{0fail}>file foo ' '17' '0' ' ' 'foo=barr' + +test_abbr "expand regular alias when it has one leading control operator (&&)" ' && foo' '7' '0' ' && barr ' '9' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has one leading control operator (||)" ' || foo' '7' '0' ' || barr ' '9' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has one leading control operator (|)" ' | foo' '6' '0' ' | barr ' '8' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has one leading control operator (;)" ' ; foo' '6' '0' ' ; barr ' '8' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has one leading control operator (;;)" ' ;; foo' '7' '0' ' ;; barr ' '9' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has one leading control operator (;&)" ' ;& foo' '7' '0' ' ;& barr ' '9' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has one leading control operator (;;&)" ' ;;& foo' '8' '0' ' ;;& barr ' '10' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has one leading control operator (&)" ' & foo' '6' '0' ' & barr ' '8' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has one leading control operator (newline)" $'\nfoo' '4' '0' $'\nbarr ' '6' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has one leading control operator (opening parenthesis)" '(foo' '4' '0' '(barr ' '6' '0' ' ' 'foo=barr' + +test_abbr "don't expand regular alias when there's a closing parenthesis" ' ) foo' '7' '0' ' ) foo ' '8' '0' ' ' 'foo=barr' + +test_abbr "expand regular alias when it has two leading control operators" ' && echo hi && foo' '18' '0' ' && echo hi && barr ' '20' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when it has two leading and one trailing control operator(s)" ' && echo hi (foo&& okay)' '16' '0' ' && echo hi (barr && okay)' '18' '0' ' ' 'foo=barr' + +test_abbr "expand regular alias when it has leading and trailing control operators, assignment words and redirections" $'\necho hi&&a=1 echo ho || 2>/dev/null echo bla & {var}<>file another ;;& a=1 2>/dev/null 3>&4- foo; >/dev/null cool <>file' '97' '0' $'\necho hi&&a=1 echo ho || 2>/dev/null echo bla & {var}<>file another ;;& a=1 2>/dev/null 3>&4- barr ; >/dev/null cool <>file' '99' '0' ' ' 'foo=barr' + +test_abbr "don't expand regular alias when it's not the first word" 'hey foo' '7' '0' 'hey foo ' '8' '0' ' ' 'foo=barr' + +test_abbr "don't expand regular alias when there's a double quoted ';' before it" 'echo ";" foo' '12' '0' 'echo ";" foo ' '13' '0' ' ' 'foo=barr' +test_abbr "don't expand regular alias when there is 1 backslash before a ';' before the alias" 'echo \; foo' '11' '0' 'echo \; foo ' '12' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when there are 2 backslashes before a ';' before the alias" 'echo \\; foo' '12' '0' 'echo \\; barr ' '14' '0' ' ' 'foo=barr' +test_abbr "don't expand regular alias when there are 3 backslashes before a ';' before the alias" 'echo \\\; foo' '13' '0' 'echo \\\; foo ' '14' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when there are 4 backslashes before a ';' before the alias" 'echo \\\\; foo' '14' '0' 'echo \\\\; barr ' '16' '0' ' ' 'foo=barr' +test_abbr "don't expand regular alias when there are 5 backslashes before a ';' before the alias" 'echo \\\\\; foo' '15' '0' 'echo \\\\\; foo ' '16' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when there are 6 backslashes before a ';' before the alias" 'echo \\\\\\; foo' '16' '0' 'echo \\\\\\; barr ' '18' '0' ' ' 'foo=barr' + +test_abbr "don't expand regular alias when there is 1 backslash before a & before the alias" 'echo \& foo' '11' '0' 'echo \& foo ' '12' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when there are 2 backslashes before a & before the alias" 'echo \\& foo' '12' '0' 'echo \\& barr ' '14' '0' ' ' 'foo=barr' +test_abbr "don't expand regular alias when there are 3 backslashes before a & before the alias" 'echo \\\& foo' '13' '0' 'echo \\\& foo ' '14' '0' ' ' 'foo=barr' + +test_abbr "don't expand regular alias when there is 1 backslash before a | before the alias" 'echo \| foo' '11' '0' 'echo \| foo ' '12' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when there are 2 backslashes before a | before the alias" 'echo \\| foo' '12' '0' 'echo \\| barr ' '14' '0' ' ' 'foo=barr' +test_abbr "don't expand regular alias when there are 3 backslashes before a | before the alias" 'echo \\\| foo' '13' '0' 'echo \\\| foo ' '14' '0' ' ' 'foo=barr' + +test_abbr "expand regular alias when there is 1 backslash before a ||" 'echo \|| foo' '12' '0' 'echo \|| barr ' '14' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when there are 2 backslashes before a ||" 'echo \\|| foo' '13' '0' 'echo \\|| barr ' '15' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when there are 3 backslashes before a ||" 'echo \\\|| foo' '14' '0' 'echo \\\|| barr ' '16' '0' ' ' 'foo=barr' + +test_abbr "expand regular alias when there is 1 backslash before a &&" 'echo \&& foo' '12' '0' 'echo \&& barr ' '14' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when there are 2 backslashes before a &&" 'echo \\&& foo' '13' '0' 'echo \\&& barr ' '15' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when there are 3 backslashes before a &&" 'echo \\\&& foo' '14' '0' 'echo \\\&& barr ' '16' '0' ' ' 'foo=barr' + +test_abbr "expand regular alias when there is 1 backslash before a ;;" 'echo \;; foo' '12' '0' 'echo \;; barr ' '14' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when there are 2 backslashes before a ;;" 'echo \\;; foo' '13' '0' 'echo \\;; barr ' '15' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when there are 3 backslashes before a ;;" 'echo \\\;; foo' '14' '0' 'echo \\\;; barr ' '16' '0' ' ' 'foo=barr' + +test_abbr "expand regular alias when there is 1 backslash before a ;;&" 'echo \;;& foo' '13' '0' 'echo \;;& barr ' '15' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when there are 2 backslashes before a ;;&" 'echo \\;;& foo' '14' '0' 'echo \\;;& barr ' '16' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when there are 3 backslashes before a ;;&" 'echo \\\;;& foo' '15' '0' 'echo \\\;;& barr ' '17' '0' ' ' 'foo=barr' + +test_abbr "expand regular alias when there is 1 backslash before a ;&" 'echo \;& foo' '12' '0' 'echo \;& barr ' '14' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when there are 2 backslashes before a ;&" 'echo \\;& foo' '13' '0' 'echo \\;& barr ' '15' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when there are 3 backslashes before a ;&" 'echo \\\;& foo' '14' '0' 'echo \\\;& barr ' '16' '0' ' ' 'foo=barr' + +test_abbr "don't expand regular alias when there is 1 backslash before a (" 'echo \( foo' '11' '0' 'echo \( foo ' '12' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when there are 2 backslashes before a (" 'echo \\( foo' '12' '0' 'echo \\( barr ' '14' '0' ' ' 'foo=barr' +test_abbr "expand regular alias when there are 3 backslashes before a (" 'echo \\\( foo' '13' '0' 'echo \\\( foo ' '14' '0' ' ' 'foo=barr' + +test_abbr "don't expand regular alias when newline is entered not after or on the alias" 'foo ' '4' '0' 'foo ' '4' '0' '' 'foo=bar' +test_abbr "don't expand regular alias when space is entered not after or on the alias" 'foo ' '4' '0' 'foo ' '5' '0' ' ' 'foo=bar' + +summary