Add test cases for escape function
Cases:
"
\"
-
\\"
...
Reference
text='A test "of quotes" and $variables ${abcd} $(ls)'
printf "0 %s\n" "${text}"
count=5
arr=("${text}")
for ((i=1;i<=$count;i++)); do
_escape "text" '"$'
printf "%d %s\n" "$i" "${text}"
arr[$i]="${text}"
done
for ((i=$count;i>=1;i--)); do
text="${arr[$i]}"
text=$(eval "echo \"$text\"")
printf "%d %s\n" "$((i-1))" "${text}"
if [ "${arr[$((i-1))]}" != "${text}" ]; then
_error "bad _escape"
exit 1
fi
done
Other points
- Five times it the maximum escape level
-
text=' \" '
counts as one escape level (4 more after that) - A first test should be to compare
_escape
results against an absolute reference string (as it's done inString
module). - An absolute reference string could be created by issuing
_escape
multiple times over the same string and saving the result. This however is still be tied to_escape
as a relative reference. Inspecting it by hand and then it will serve as an abs ref for how_escape
should behave.
Edited by Maicon Diniz Filippsen