Added a test for fixing the ticket #23551

Fixed a wrong evaluation of the `$COMP_CWORD` in `tests/bash_completion/tests.py` and added a test for the bug reported in #3246.