Unit Test Function Library

Unit Test for DosTips Functions.

Description: DOS functions open the door for effective unit test. Each DOS function can be tested by itself using a unit test function. This page lists the unit test functions that are currently available and being used to validate the DOS function provided at DosTips.com.


TOP
2008-03-21

:unittest.bannerPingPong - Test cases for the :bannerPingPong function

Description: call:unittest.bannerPingPong
Dependencies: :bannerPingPong
Script:
1.
2.
3.
4.
5.
6.
7.
8.
9.
:unittest.bannerPingPong
:$created 20080321 :$changed 20080321
:$source https://www.dostips.com
set "text=hi    -"
for /l %%C in (1,1,15) do (
    call:bannerPingPong text
    call echo.'%%text%%'
)
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.bannerPingPong - output
'-hi---+'
'--hi--+'
'---hi-+'
'----hi+'
'---hi--'
'--hi---'
'-hi----'
'hi-----'
'-hi---+'
'--hi--+'
'---hi-+'
'----hi+'
'---hi--'
'--hi---'
'-hi----'
----

TOP
2008-03-21

:unittest.bannerRotate - Test cases for the :bannerRotate function

Description: call:unittest.bannerRotate
Dependencies: :bannerRotate
Script:
1.
2.
3.
4.
5.
6.
7.
8.
9.
:unittest.bannerRotate
:$created 20080321 :$changed 20080321
:$source https://www.dostips.com
set "text= hi there! "
for /l %%C in (1,1,12) do (
    call:bannerRotate text
    call echo.'%%text%%'
)
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.bannerRotate - output
'hi-there!--'
'i-there!--h'
'-there!--hi'
'there!--hi-'
'here!--hi-t'
'ere!--hi-th'
're!--hi-the'
'e!--hi-ther'
'!--hi-there'
'--hi-there!'
'-hi-there!-'
'hi-there!--'
----

TOP
2009-03-28

:unittest.date2jdate - Test cases for the :date2jdate function

Description: call:unittest.date2jdate
Dependencies: :date2jdate, :Format
Script:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
:unittest.date2jdate
:$created 20080223 :$changed 20090328
:$source https://www.dostips.com
for %%C in (
        "2008 02 23"
        "2008 02 23"
        "2007 12 31"
        "2008 01 01"
        "2008 01 06"
        "2008 01 07"
        "2008 01 08"
        "2008 01 09"
        "100 1 1"
        "99 12 31"
        "0 1 1"
    ) do (
    call:date2jdate s %%~C
    call:Format "[35] [35]." "'%%~C'" "'%%s%%'"
)
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.date2jdate - output
'2008 02 23'                        '2454520'                          .
'2008 02 23'                        '2454520'                          .
'2007 12 31'                        '2454466'                          .
'2008 01 01'                        '2454467'                          .
'2008 01 06'                        '2454472'                          .
'2008 01 07'                        '2454473'                          .
'2008 01 08'                        '2454474'                          .
'2008 01 09'                        '2454475'                          .
'100 1 1'                           '1757585'                          .
'99 12 31'                          '2488069'                          .
'0 1 1'                             '2451545'                          .
----

TOP
2008-06-16

:unittest.dayOfYear - Test cases for the :dayOfYear function

Description: call:unittest.dayOfYear
Dependencies: :dayOfYear, :Format
Script:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
:unittest.dayOfYear
:$created 20080616 :$changed 20080616
:$source https://www.dostips.com
for %%C in (
        "1/1/2008"
        "1/31/2008"
        "2/1/2008"
        "3/31/2008"
        "12/31/2008"
        "1/1/2009"
    ) do (
    call:dayOfYear s "%%~C"
    call:Format "[35] [35]." "'%%~C'" "'%%s%%'"
)
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.dayOfYear - output
'1/1/2008'                          '1'                                .
'1/31/2008'                         '31'                               .
'2/1/2008'                          '32'                               .
'3/31/2008'                         '91'                               .
'12/31/2008'                        '366'                              .
'1/1/2009'                          '1'                                .
----

TOP
2010-02-05

:unittest.extractFileSection - Test cases for the :extractFileSection function

Description: call:unittest.extractFileSection
Dependencies: :extractFileSection
Script:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
:unittest.extractFileSection
:$created 20080219 :$changed 20100205
:$source https://www.dostips.com
SETLOCAL Disabledelayedexpansion
set "substitute=SUBSTITUTED"
echo.extract without substitution
call:extractFileSection "+++Section1" "+++" "%~f0"
echo.extract with substitution
SETLOCAL Enabledelayedexpansion
call:extractFileSection "+++Section2" "+++" "%~f0"
rem echo.-- extract function %~0
rem call:extractFileSection "%~0" "EXIT /b" "%~f0"
@EXIT /b
+++Section1
    Extracted Line 1
    Extracted Line 2 %substitute%
    a: %~1 %2
    b: %substitute:~3%
    c: %substitute:u=%
+++
+++Section2:S
    Extracted Line 1
    Extracted Line 2 %substitute%
    a: %~1 %2
    b: %substitute:~3%
    c: %substitute:u=%
+++
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.extractFileSection - output
extract without substitution
    Extracted Line 1
    Extracted Line 2 %substitute%
    a: %~1 %2
    b: %substitute:~3%
    c: %substitute:u=%
extract with substitution
    Extracted Line 1
    Extracted Line 2 SUBSTITUTED
    a: +++Section2 "+++"
    b: STITUTED
    c: SBSTITTED
----

TOP
2008-02-19

:unittest.false - Test cases for the :false function

Description: call:unittest.false
Dependencies: :false
Script:
1.
2.
3.
4.
5.
:unittest.false
:$created 20080219 :$changed 20080219
:$source https://www.dostips.com
call:false && echo.TRUE || echo.FALSE
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.false - output
FALSE
----

TOP
2008-02-19

:unittest.format - Test cases for the :format function

Description: call:unittest.format
Dependencies: :Format
Script:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
:unittest.format
:$created 20080219 :$changed 20080219
:$source https://www.dostips.com
echo.01234567890123456789012345678901234
call:Format "[-9] . [9] . [9] ." column1 column2 column3
call:Format "[9] . [-9] . [9] ." column1 column2 column3
call:Format "[9] . [9] . [-9] ." column1 column2 column3
call:Format "[-9] . [-9] . [-9] ." column1 column2 column3
call:Format "[-9] . [-9] . [-9] ." col1 col2 col3
call:Format "[9] . [-9] . [-9] ." column1column1 column2column2 column3column3
call:Format "[12][12][9] ." column1 column2 column3
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.format - output
01234567890123456789012345678901234
  column1 . column2   . column3   .
column1   .   column2 . column3   .
column1   . column2   .   column3 .
  column1 .   column2 .   column3 .
     col1 .      col2 .      col3 .
column1co . n2column2 . n3column3 .
column1     column2     column3   .
----

TOP
2009-03-28

:unittest.jdate - Test cases for the :jdate function

Description: call:unittest.jdate
Dependencies: :jdate, :Format
Script:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
:unittest.jdate
:$created 20080223 :$changed 20090328
:$source https://www.dostips.com
for %%C in (
        "Sat 02/23/2008"
        "02/23/2008"
        "12/31/2007"
        "01/01/2008"
        "01/06/2008"
        "01/07/2008"
        "01/08/2008"
        "01/09/2008"
        "1/1/100"
        "12/31/99"
        "1/1/0"
    ) do (
    call:jdate s "%%~C"
    call:Format "[35] [35]." "'%%~C'" "'%%s%%'"
)
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.jdate - output
'Sat 02/23/2008'                    '2454520'                          .
'02/23/2008'                        '2454520'                          .
'12/31/2007'                        '2454466'                          .
'01/01/2008'                        '2454467'                          .
'01/06/2008'                        '2454472'                          .
'01/07/2008'                        '2454473'                          .
'01/08/2008'                        '2454474'                          .
'01/09/2008'                        '2454475'                          .
'1/1/100'                           '1757585'                          .
'12/31/99'                          '2488069'                          .
'1/1/0'                             '2451545'                          .
----

TOP
2008-02-23

:unittest.jdate2date - Test cases for the :jdate2date function

Description: call:unittest.jdate2date
Dependencies: :jdate2date, :Format
Script:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
:unittest.jdate2date
:$created 20080223 :$changed 20080223
:$source https://www.dostips.com
for %%C in (
        "2454520"
        "2454466"
        "2454467"
        "2454472"
        "2454473"
        "2454474"
        "2454475"
    ) do (
    set "jd=%%~C"
    call:jdate2date jd Y M D
    call:Format "[35] [35]." "'%%jd%%'"    "'%%Y%% %%M%% %%D%%'"
)
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.jdate2date - output
'2454520'                           '2008 02 23'                       .
'2454466'                           '2007 12 31'                       .
'2454467'                           '2008 01 01'                       .
'2454472'                           '2008 01 06'                       .
'2454473'                           '2008 01 07'                       .
'2454474'                           '2008 01 08'                       .
'2454475'                           '2008 01 09'                       .
----

TOP
2008-02-27

:unittest.lTrim - Test cases for the :lTrim function

Description: call:unittest.lTrim
Dependencies: :lTrim, :Format
Script:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
:unittest.lTrim
:$created 20080227 :$changed 20080227
:$source https://www.dostips.com
for %%C in (
        "left trim nothing "
        " left trim one "
        "                left trim plenty "
    ) do (
    set "s=%%~C"
    call:lTrim s
    call:Format "[35] [35]." "'%%~C'" "'%%s%%'"
)
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.lTrim - output
'left trim nothing '                'left trim nothing '               .
' left trim one '                   'left trim one '                   .
'                left trim plenty ' 'left trim plenty '                .
----

TOP
2008-02-19

:unittest.MakeAbsolute - Test cases for the :MakeAbsolute function

Description: call:unittest.MakeAbsolute
Dependencies: :MakeAbsolute, :Format
Script:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
:unittest.MakeAbsolute
:$created 20080219 :$changed 20080219
:$source https://www.dostips.com
for %%C in (
        "..\..\windows\win.ini"
        "..\..\windows\..\windows\win.ini"
        ".\..\.\..\windows.\.\..\windows\win.ini"
    ) do (
    set "s=%%~C"
    call:MakeAbsolute s
    call:Format "[35] [35]." "'%%~C'" "'%%s%%'"
)
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.MakeAbsolute - output
'..\..\windows\win.ini'             'C:\WINDOWS\win.ini'               .
'..\..\windows\..\windows\win.ini'  'C:\WINDOWS\win.ini'               .
'.\..\.\..\windows.\.\..\windows\wi 'C:\WINDOWS\win.ini'               .
----

TOP
2008-02-19

:unittest.MakeRelative - Test cases for the :MakeRelative function

Description: call:unittest.MakeRelative
Dependencies: :MakeRelative, :Format
Script:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
:unittest.MakeRelative
:$created 20080219 :$changed 20080219
:$source https://www.dostips.com
for %%C in (
        "c:\windows\win.ini"
        "\windows\win.ini"
        "..\..\windows\..\windows\win.ini"
    ) do (
    set "s=%%~C"
    call:MakeRelative s
    call:Format "[35] [35]." "'%%~C'" "'%%s%%'"
)
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.MakeRelative - output
'c:\windows\win.ini'                '..\..\WINDOWS\win.ini'            .
'\windows\win.ini'                  '..\..\WINDOWS\win.ini'            .
'..\..\windows\..\windows\win.ini'  '..\..\WINDOWS\win.ini'            .
----

TOP
2008-02-27

:unittest.rTrim - Test cases for the :rTrim function

Description: call:unittest.rTrim
Dependencies: :rTrim, :Format
Script:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
:unittest.rTrim
:$created 20080227 :$changed 20080227
:$source https://www.dostips.com
for %%C in (
        " right trim nothing"
        " right trim one "
        " right trim plenty                  "
    ) do (
    set "s=%%~C"
    call:rTrim s
    call:Format "[35] [35]." "'%%~C'" "'%%s%%'"
)
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.rTrim - output
' right trim nothing'               ' right trim nothing'              .
' right trim one '                  ' right trim one'                  .
' right trim plenty                 ' right trim plenty'               .
----

TOP
2008-03-20

:unittest.StartsWith - Test cases for the :StartsWith function

Description: call:unittest.StartsWith
Dependencies: :StartsWith, :Format
Script:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
:unittest.StartsWith
:$created 20080320 :$changed 20080320
:$source https://www.dostips.com
set "text=Hi there"
for %%C in (
        "Hi"
        "hi"
        "h"
        ""
        "la"
        " hi"
    ) do (
    call:StartsWith "%text%" "%%~C" && (
        call:Format "[12] starts with [10] - [5]." "'%text%'" "'%%~C'" "TRUE"
        rem
    ) || (
        call:Format "[12] starts with [10] - [5]." "'%text%'" "'%%~C'" "FALSE"
    )
)
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.StartsWith - output
'Hi there'   starts with 'Hi'       - TRUE .
'Hi there'   starts with 'hi'       - TRUE .
'Hi there'   starts with 'h'        - TRUE .
'Hi there'   starts with ''         - FALSE.
'Hi there'   starts with 'la'       - FALSE.
'Hi there'   starts with ' hi'      - FALSE.
----

TOP
2008-11-24

:unittest.strLen - Test cases for the :strLen function

Description: call:unittest.strLen
Dependencies: :strLen, :Format
Script:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
:unittest.strLen
:$created 20081124 :$changed 20081124
:$source https://www.dostips.com
for %%C in (
        ""
        "H"
        "Hi"
        "Hi_"
        "Hi T"
        "Hi There, what's up!"
    ) do (
    set "str=%%~C"
    call:strLen str len && (
        call:Format "[5] characters for [20]." "'%%len%%'" "'%%str%%'"
    )
)
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.strLen - output
'0'   characters for ''                  .
'1'   characters for 'H'                 .
'2'   characters for 'Hi'                .
'3'   characters for 'Hi_'               .
'4'   characters for 'Hi T'              .
'20'  characters for 'Hi There, what's up.
----

TOP
2008-03-26

:unittest.substitute - Test cases for the :substitute function

Description: call:unittest.substitute
Dependencies: :substitute
Script:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
:unittest.substitute
:$created 20080326 :$changed 20080326
:$source https://www.dostips.com
(for %%A in (
        "two words"
        "exclamation ! exclamation"
        "percent     %% percent"
        "ampersand   & ampersand && ampersand"
        "vertical    | vertical  || vertical"
        "(parenthesis) (parenthesis)"
        "least    << lesser  < less"
        "greatest >> greater > great"
        "next line is empty"
        ""
        "almost done"
        "last line will have line feed"
    ) do for /f "delims=" %%B in ('"echo."echo.%%~A""') do %%~B
)>"%temp%.\%~n0.unittest.txt"
call:substitute "t" "." "%temp%.\%~n0.unittest.txt"
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.substitute - output
.wo words
exclama.ion ! exclama.ion
percen.     % percen.
ampersand   & ampersand && ampersand
ver.ical    | ver.ical  || ver.ical
(paren.hesis) (paren.hesis)
leas.    << lesser  < less
grea.es. >> grea.er > grea.
nex. line is emp.y

almos. done
las. line will have line feed
----

TOP
2008-02-19

:unittest.toCamelCase - Test cases for the :toCamelCase function

Description: call:unittest.toCamelCase
Dependencies: :toCamelCase, :Format
Script:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
:unittest.toCamelCase
:$created 20080219 :$changed 20080219
:$source https://www.dostips.com
for %%C in (
        "this is a camel case test"
        " this is a camel case test "
        "tHIs is a cAMEL CASE tesT"
        "123 camel case test"
        "camel case test 123"
        "ThisIsACamelCaseTest"
        ""
    ) do (
    set "s=%%~C"
    call:toCamelCase s
    call:Format "[35] [35]." "'%%~C'" "'%%s%%'"
)
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.toCamelCase - output
'this is a camel case test'         'ThisIsACamelCaseTest'             .
' this is a camel case test '       'ThisIsACamelCaseTest'             .
'tHIs is a cAMEL CASE tesT'         'ThisIsACamelCaseTest'             .
'123 camel case test'               '123CamelCaseTest'                 .
'camel case test 123'               'CamelCaseTest123'                 .
'ThisIsACamelCaseTest'              'Thisisacamelcasetest'             .
''                                  ''                                 .
----

TOP
2009-11-30

:unittest.toLower - Test cases for the :toLower function

Description: call:unittest.toLower
Dependencies: :toLower, :Format
Script:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
:unittest.toLower
:$created 20080219 :$changed 20091130
:$source https://www.dostips.com
for %%C in (
        "CONVERT this to lower case"
        "123Conver tHIs to Lower case"
        "Convert this TO lower case123"
        "CONVERT THIS TO LOWER CASE"
        "convert this to lower case"
        ""
    ) do (
    set "s=%%~C"
    call:toLower s
    call:Format "[35] [35]." "'%%~C'" "'%%s%%'"
)
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.toLower - output
'CONVERT this to lower case'        'convert this to lower case'       .
'123Conver tHIs to Lower case'      '123conver this to lower case'     .
'Convert this TO lower case123'     'convert this to lower case123'    .
'CONVERT THIS TO LOWER CASE'        'convert this to lower case'       .
'convert this to lower case'        'convert this to lower case'       .
''                                  ''                                 .
----

TOP
2009-11-30

:unittest.toUpper - Test cases for the :toUpper function

Description: call:unittest.toUpper
Dependencies: :toUpper, :Format
Script:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
:unittest.toUpper
:$created 20080219 :$changed 20091130
:$source https://www.dostips.com
for %%C in (
        "CONVERT this to upper case"
        "123Conver tHIs to Upper case"
        "Convert this TO upper case123"
        "CONVERT THIS TO UPPER CASE"
        "convert this to upper case"
        ""
    ) do (
    set "s=%%~C"
    call:toUpper s
    call:Format "[35] [35]." "'%%~C'" "'%%s%%'"
)
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.toUpper - output
'CONVERT this to upper case'        'CONVERT THIS TO UPPER CASE'       .
'123Conver tHIs to Upper case'      '123CONVER THIS TO UPPER CASE'     .
'Convert this TO upper case123'     'CONVERT THIS TO UPPER CASE123'    .
'CONVERT THIS TO UPPER CASE'        'CONVERT THIS TO UPPER CASE'       .
'convert this to upper case'        'CONVERT THIS TO UPPER CASE'       .
''                                  ''                                 .
----

TOP
2008-02-27

:unittest.Trim - Test cases for the :Trim function

Description: call:unittest.Trim
Dependencies: :Trim, :Format
Script:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
:unittest.Trim
:$created 20080227 :$changed 20080227
:$source https://www.dostips.com
for %%C in (
        "trim nothing"
        " trim one left and one right "
        "    trim plenty left and right   "
    ) do (
    set "s=%%~C"
    call:Trim s
    call:Format "[35] [35]." "'%%~C'" "'%%s%%'"
)
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.Trim - output
'trim nothing'                      'trim nothing'                     .
' trim one left and one right '     'trim one left and one right'      .
'    trim plenty left and right   ' 'trim plenty left and right'       .
----

TOP
2008-02-19

:unittest.true - Test cases for the :true function

Description: call:unittest.true
Dependencies: :true
Script:
1.
2.
3.
4.
5.
:unittest.true
:$created 20080219 :$changed 20080219
:$source https://www.dostips.com
call:true && echo.TRUE||echo.FALSE
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.true - output
TRUE
----

TOP
2008-02-19

:unittest.Unique - Test cases for the :Unique function

Description: call:unittest.Unique
Dependencies: :Unique
Script:
1.
2.
3.
4.
5.
6.
:unittest.Unique
:$created 20080219 :$changed 20080219
:$source https://www.dostips.com
call:Unique s
echo.%s%    [nocompare]
EXIT /b
Script Output:
 DOS Script Output
---- :unittest.Unique - output
200822122544495    [nocompare]
----


Ad: