[CMD_ROSTEST] Add tests for GOTO label parsing.

This commit is contained in:
Hermès Bélusca-Maïto 2020-07-27 01:11:23 +02:00
parent c5e6e5a19c
commit 71cd64d66a
No known key found for this signature in database
GPG Key ID: 3B2539C65E7B93D0
2 changed files with 69 additions and 3 deletions

View File

@ -11,8 +11,9 @@ setlocal enabledelayedexpansion
:: GOTO/CALL jump to labels present forward to their call-point. Only when
:: the label cannot be found forward, the search is then restarted from the
:: beginning of the batch file onwards up to the original call-point.
::
goto :test_start
:: GOTO with a label parameter without ':' works.
goto test_start
:: Execution must never go there!
:test_goto
@ -36,7 +37,8 @@ goto :continue
:test_goto
echo Test GOTO ok
goto :do_test_call
:: GOTO also understands '+' instead of ':' in its label parameter.
goto +do_test_call
:test_call
echo Test CALL ok from %0
@ -44,12 +46,69 @@ echo Test CALL ok from %0
goto :EOF
::
:: Next suite of tests.
::
:: GOTO label search algorithm ignores any whitespace between ':'
:: and the label name, as well as leading and trailing whitespace.
:@tab@continue@space@@space@
:: Jumping to a label with escape carets.
goto :la^^bel2
:la^bel2
echo Unexpected GOTO jump^^!
:la^^bel2
echo GOTO with escape caret worked
:: Go to the next tests below.
goto :continue
::
:: Next suite of tests.
::
:continue
::
:: Extra GOTO syntax checks: separators in the label parameter
::
:: Whitespace
goto :testLbl1@tab@ignored
:testLbl1
echo Hi there^^!
:: Colon
goto :testLbl2:ignored
:testLbl2
echo Hi there^^!
:: Plus sign
goto :testLbl3+ignored
:testLbl3
echo Hi there^^!
:: Comma
goto :testLbl4,ignored
:testLbl4
echo Hi there^^!
:: Semicolon
goto :testLbl5;ignored
:testLbl5
echo Hi there^^!
:: Equals
goto :testLbl6;ignored
:testLbl6
echo Hi there^^!
::
:: Testing :EOF support
::

View File

@ -2,6 +2,13 @@
Test GOTO ok
--------- Testing CALL within batch ---------
Test CALL ok from :test_call
GOTO with escape caret worked
Hi there!
Hi there!
Hi there!
Hi there!
Hi there!
Hi there!
--------- Testing :EOF support ---------
OK
OK