mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 18:15:11 +00:00
[CMD_ROSTEST] Add tests for delayed expansion.
This commit is contained in:
parent
da36f799c7
commit
014efdf7e8
2 changed files with 346 additions and 0 deletions
|
@ -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
|
||||
|
||||
::
|
||||
|
|
|
@ -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 --------------
|
||||
|
|
Loading…
Reference in a new issue