https://git.reactos.org/?p=reactos.git;a=commitdiff;h=014efdf7e85205fa2f8996...
commit 014efdf7e85205fa2f899675d19a243cf5b96b5a Author: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org AuthorDate: Fri Jun 5 00:41:31 2020 +0200 Commit: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org CommitDate: Sat Sep 19 19:44:53 2020 +0200
[CMD_ROSTEST] Add tests for delayed expansion. --- modules/rostests/win32/cmd/test_echoer_parser.cmd | 159 ++++++++++++++++++ .../rostests/win32/cmd/test_echoer_parser.cmd.exp | 187 +++++++++++++++++++++ 2 files changed, 346 insertions(+)
diff --git a/modules/rostests/win32/cmd/test_echoer_parser.cmd b/modules/rostests/win32/cmd/test_echoer_parser.cmd index 85d20ad9508..e94313871f7 100644 --- a/modules/rostests/win32/cmd/test_echoer_parser.cmd +++ b/modules/rostests/win32/cmd/test_echoer_parser.cmd @@ -92,6 +92,165 @@ if 1==0 (@echo lol) else (@echo better2) :: ()
+:: +:: Tests for delayed expansion. +:: + +@echo off +setlocal enableextensions +setlocal enabledelayedexpansion + +echo --------- Testing Delayed Expansion --------- + +:: Checking exclamation point escaping +set ENDV= ^(an open-source operating system^) +echo This is ReactOS^^!%ENDV% +echo Hello! +echo Hello!! +echo Hello!!! +echo Hello^^^! "^!" + +:: The following tests are adapted from +:: https://ss64.com/nt/delayedexpansion.html + +echo "Hello^World" +echo "Hello^World!" + +:: Checking expansion +set "_var=first" +set "_var=second" & Echo %_var% !_var! + +:: Checking expansion and replacement +set var1=Hello ABC how are you +set var2=ABC +set result=!var1:%var2%=Developer! +echo [!result!] + +:: Test of FOR-loop +set COUNT=0 +for /l %%v in (1,1,4) do ( + set /A COUNT=!COUNT! + 1 + echo [!COUNT!] +) +echo Total = %COUNT% + + +set "com[0]=lol0" +set "com[1]=lol2" +set "com[2]=lol4" +set "com[3]=lol6" +set "com[4]=lol8" +set "com[5]=lol10" + +for /l %%k in (1,1,5) do ( + echo(!com[%%k]! + if /I "%%k" equ "5" echo OHLALA +) + + +:: +:: Re-enable the command echoer +:: +@echo on + +setlocal disabledelayedexpansion + +echo %~DP0 + +set test=abc +set abc=def + +echo % +echo %% +echo %%% +echo %%%% + +echo %test% +echo %test%% +echo %%test% +echo %%test%% +echo %%%test%%% + +echo !test! +echo !!test!! + +endlocal +setlocal enabledelayedexpansion + +:: +:: Regular and Delayed variables +:: + +echo ! +echo !! +echo !!! +echo !!!! +echo !a! +echo !!a!! + +set a=b +:: Will display b +echo !!a!! +set b=c +:: Will still display b +echo !!a!! + +echo %test% +echo %test%% +echo %%test% +echo %%test%% +echo %%%test%%% + +echo %!test!% +echo !%test%! +echo !!test!! +:: That other one is the same as the previous one. +echo !^!test^!! +echo !^^!test^^!! +echo !test! +echo !test!! +echo !!test! +echo !!test!! +echo !!!test!!! + + +set proj=XYZ +echo !%proj%_folder! +echo !!proj!_folder! + +set %proj%_folder=\server\folder\ +echo !%proj%_folder! +echo !!proj!_folder! + + +:: +:: Delayed variables in blocks +:: + +if 1==1 ( + set "pc=T" + echo pc == !pc! + + set i=3 + set "!pc!!i!=5" + + echo other pc == !pc! and !pc!!i! == !!pc!!i!! + echo other pc == !pc! and !pc!!i! == !^!pc^!^!i^!! + echo other pc == !pc! and !pc!!i! == ^!!pc!!i!^! + echo other pc == !pc! and !pc!!i! == ^!^!pc^!^!i^!^! + set "trol=!pc!!i!" + echo the var was !trol! + + set "!pc!N=!i!" + echo updated !pc!N == !!pc!N! + echo updated !pc!N == !^!pc^!N! + echo updated !pc!N == ^!!pc!N^! + echo updated !pc!N == ^!^!pc^!N^! + set "trol=!pc!N" + echo updated !pc!N == !trol! +) + + @echo off
:: diff --git a/modules/rostests/win32/cmd/test_echoer_parser.cmd.exp b/modules/rostests/win32/cmd/test_echoer_parser.cmd.exp index b582b62722f..796b31eef76 100644 --- a/modules/rostests/win32/cmd/test_echoer_parser.cmd.exp +++ b/modules/rostests/win32/cmd/test_echoer_parser.cmd.exp @@ -135,4 +135,191 @@ better2 @pwd@>(a)@space@
@pwd@>(a b )@space@ +--------- Testing Delayed Expansion --------- +This is ReactOS! (an open-source operating system) +Hello +Hello +Hello +Hello! "!" +"Hello^World" +"HelloWorld" +first second +[Hello Developer how are you] +[1] +[2] +[3] +[4] +Total = 4 +lol2 +lol4 +lol6 +lol8 +lol10 +OHLALA + +@pwd@>setlocal disabledelayedexpansion@space@ + +@pwd@>echo @pwd@@space@ +@pwd@\ + +@pwd@>set test=abc@space@ + +@pwd@>set abc=def@space@ + +@pwd@>echo@space@@space@ +ECHO is on. + +@pwd@>echo %@space@ +% + +@pwd@>echo %@space@ +% + +@pwd@>echo %%@space@ +%% + +@pwd@>echo abc@space@ +abc + +@pwd@>echo abc@space@ +abc + +@pwd@>echo %test@space@ +%test + +@pwd@>echo %test%@space@ +%test% + +@pwd@>echo %abc%@space@ +%abc% + +@pwd@>echo !test!@space@ +!test! + +@pwd@>echo !!test!!@space@ +!!test!! + +@pwd@>endlocal + +@pwd@>setlocal enabledelayedexpansion@space@ + +@pwd@>echo !@space@ +ECHO is on. + +@pwd@>echo !!@space@ +ECHO is on. + +@pwd@>echo !!!@space@ +ECHO is on. + +@pwd@>echo !!!!@space@ +ECHO is on. + +@pwd@>echo !a!@space@ +ECHO is on. + +@pwd@>echo !!a!!@space@ +ECHO is on. + +@pwd@>set a=b@space@ + +@pwd@>echo !!a!!@space@ +b + +@pwd@>set b=c@space@ + +@pwd@>echo !!a!!@space@ +b + +@pwd@>echo@space@@space@ +ECHO is on. + +@pwd@>echo@space@@space@ +ECHO is on. + +@pwd@>echo %test@space@ +%test + +@pwd@>echo %test%@space@ +%test% + +@pwd@>echo %%@space@ +%% + +@pwd@>echo@space@@space@ +ECHO is on. + +@pwd@>echo !!@space@ +ECHO is on. + +@pwd@>echo !!test!!@space@ +ECHO is on. + +@pwd@>echo !!test!!@space@ +ECHO is on. + +@pwd@>echo !^!test^!!@space@ +test! + +@pwd@>echo !test!@space@ +ECHO is on. + +@pwd@>echo !test!!@space@ +ECHO is on. + +@pwd@>echo !!test!@space@ +ECHO is on. + +@pwd@>echo !!test!!@space@ +ECHO is on. + +@pwd@>echo !!!test!!!@space@ +ECHO is on. + +@pwd@>set proj=XYZ@space@ + +@pwd@>echo !XYZ_folder!@space@ +ECHO is on. + +@pwd@>echo !!proj!_folder!@space@ +XYZ_folder + +@pwd@>set XYZ_folder=\server\folder@space@ + +@pwd@>echo !XYZ_folder!@space@ +\server\folder\ + +@pwd@>echo !!proj!_folder!@space@ +XYZ_folder + +@pwd@>if 1 == 1 ( +set "pc=T"@space@@space@ + echo pc == !pc!@space@@space@ + set i=3@space@@space@ + set "!pc!!i!=5"@space@@space@ + echo other pc == !pc! and !pc!!i! == !!pc!!i!!@space@@space@ + echo other pc == !pc! and !pc!!i! == !!pc!!i!!@space@@space@ + echo other pc == !pc! and !pc!!i! == !!pc!!i!!@space@@space@ + echo other pc == !pc! and !pc!!i! == !!pc!!i!!@space@@space@ + set "trol=!pc!!i!"@space@@space@ + echo the var was !trol!@space@@space@ + set "!pc!N=!i!"@space@@space@ + echo updated !pc!N == !!pc!N!@space@@space@ + echo updated !pc!N == !!pc!N!@space@@space@ + echo updated !pc!N == !!pc!N!@space@@space@ + echo updated !pc!N == !!pc!N!@space@@space@ + set "trol=!pc!N"@space@@space@ + echo updated !pc!N == !trol!@space@ +)@space@ +pc == T +other pc == T and T3 == T3 +other pc == T and T3 == T3 +other pc == T and T3 == T3 +other pc == T and T3 == T3 +the var was T3 +updated TN == TN +updated TN == TN +updated TN == TN +updated TN == TN +updated TN == TN --------- Finished --------------