home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rximc175.zip / rexxtest.rexx < prev    next >
OS/2 REXX Batch file  |  1999-01-21  |  8KB  |  229 lines

  1. /* test program for interpreter */
  2.  
  3. signal on syntax
  4. parse source sys how me nick env
  5. parse version spec ver date
  6. parse arg args
  7.  
  8. say "This is REXX test program "me", called"
  9. say "from "sys" by "how" with name '"nick"'."
  10. say "Commands are addressed to '"env"' by default."
  11. say
  12. say "Running "spec" language level "ver", last updated "date
  13. say
  14. say "Running loop tests, 10 times each"
  15. do 10;sayn"*";end;say
  16. do i=.1 to 1 by .1;sayn"*";end;say
  17. do i=0 while i<10;sayn i;end;say
  18. call time 'r'
  19. say "Running loop speed test"
  20. do 20000;end
  21. say "Completed in time" time('r')
  22. say "Running variable access speed test"
  23. do i=1 to 1000;a=a||i;end
  24. say "Completed in time" time('r')
  25. say "Running compound variable speed test"
  26. do i=1 to 500;a.i=a.(i-1)||i;end
  27. say "Completed in time" time('r')
  28. if right(a.500,9)^=="498499500"|right(a,10)^=='9989991000' then
  29.    say "Error in variable tests"
  30. say
  31. say "Running statement tests"
  32. nop
  33. drop a;if a^=='A' then say "Error in drop test"
  34. numeric digits 12
  35. numeric fuzz 1
  36. numeric form engineering
  37. if 1/3^=="0.333333333333" then say "Error in numeric digits test"
  38. if 1/3^=0.333333333331 then say "Error in numeric fuzz test"
  39. numeric digits 2
  40. if 100+1^=='100'|610*23^=='14E+3' then say "Error in numeric form test"
  41. if 1 then do
  42.    a=5
  43.    if 0 then do
  44.       a=1
  45.    end
  46. end
  47. else a=6
  48. if a^==5 then say "Error in if/do test"
  49. a=''
  50. do i=1
  51.    if i=5 then iterate i
  52.    a=a||i
  53.    do j=i
  54.       if j=10 then leave i
  55.       else iterate i
  56.    end j
  57. end i
  58. if a^=="1234678910" then say "Error in iterate/leave test"
  59. a=0
  60. select 5
  61.    when 0 then a=1
  62.    when 5 then nop
  63.    otherwise a=1
  64. end select
  65. if a then say "Error in select test"
  66. parse value "abcdefg hijklmn o","123 456 789" with a b,c '4' x +1 d 8 e
  67. parse upper var a a 'F'
  68. a= a^=="ABCDE"|b^=="hijklmn o"|c^=="123 "|x^=="4"|d^=="56"|e^==" 789"
  69. parse value "1.hello there. 234  567" with 2 b +1 c d e (b) f g 1 (b) (b) h
  70. b= b^=='.'|c^=='hello'|d^=='there'|e^==''|f^=='234'|g^==' 567'|h^==' 234  567'
  71. if a|b then say "Error in parse test"
  72.  
  73. a=0
  74. b=1
  75. call test1
  76. if result^=="result" then a=1
  77. call test2
  78. if result^=="RESULT" then a=1
  79. if a|b then say "Error in call tests"
  80. interpret "a=1";if ^a then say "Error in interpret test"
  81. signal next
  82. say "Error in signal test"
  83. Next:
  84. signal on novalue
  85. j=novalue
  86. say "Error in novalue test"
  87. Novalue:
  88. q=queued()
  89. "echo 'echo test worked OK'|rxstack -lifo"
  90. if queued()^==q+1 then say "Echo/stack test failed"
  91. else do;parse pull q;say q;end
  92.  
  93. say "Running function tests"
  94. numeric digits 9
  95. numeric form scientific
  96. if (0|0)(1|0)(0|1)(1|1)^==0111 then say "Error in OR test"
  97. if 1+2*3**4^==163|'abc'^=' abc '|'abc'==' abc '|1<0|'a'<<'A'|,
  98.    10//3^==1|10%3^==3
  99.    then say "Arithmetic test failed"
  100.  
  101. if test1()^=='result' then say "Function call test failed"
  102. if ^abbrev('information','info')|abbrev('INFORMATION','info') then
  103.    say "Error in abbrev test"
  104. if test3(1,2)^=='21' then say "error in arg test"
  105. if c2x('A')c2d('A')b2d(01000001)d2c(65)d2x(65)x2c(41)x2d(41)^=="416565A41A65"
  106.    then say "Error in base conversion test"
  107. if centre(1,3,0)^=='010' then say "Error in centre test"
  108. if compare(123,1234,4)|compare(1234,1235)^==4 then say "Error in compare test"
  109. if copies("test",3)^=="testtesttest" then say "Error in copies test"
  110. if ^datatype("abcABC123",'a')|datatype(".",'a')|,
  111.    ^datatype("010101010",'b')|datatype("2","b")|,
  112.    ^datatype("abcdefghi",'l')|datatype("A",'l')|,
  113.    ^datatype("abcDEFGhi",'m')|datatype("2","m")|,
  114.    ^datatype("1456.4E+4","n")|datatype("e","n")|,
  115.    ^datatype("sf45_retf","s")|datatype("*","s")|,
  116.    ^datatype("ABCDEFGHI","u")|datatype("a","u")|,
  117.    ^datatype("123456554","w")|datatype("1.2","w")|,
  118.    ^datatype("1 4e cd21","x")|datatype("r","x")
  119.    then say "Error in datatype test"
  120. say "Date test: "date('w') date()
  121. if delstr("abcdefg",3,1)^=="abdefg" then say "Error in delstr test"
  122. if delword("this is a test",2,1)^=="this a test" then say "Error in delword test"
  123. if digits()^==9 then say "Error in digits test"
  124. if errortext(41)^=="Bad arithmetic conversion" then say "Error in errortext test"
  125. if form()^=="SCIENTIFIC" then say "Error in form test"
  126. if format('1234567e5',,3,0)^=='123456700000.000'|,
  127.    format('1.2345',,3,2,0)^== '1.235    '       |,
  128.    format('12345.73',,,2,2)^=='1.234573E+04' then say "Error in format test"
  129. if fuzz()^==0 then say "Error in fuzz test"
  130. if insert("a","1234",2,2,"z")^=="12az34" then say "Error in insert test"
  131. if justify("this is a test",16)^=="this  is a  test" then say "Error in justify test"
  132. if lastpos(4,"98765432123456789")^==12 then say "Error in lastpos test"
  133. if left("hi",4)^=='hi  '|left("there",2)^=="th" then say "Error in left test"
  134. if length("hello")^==5 then say "Error in length test"
  135. if max(4,2,6,5)^==6 then say "Error in max test"
  136. if min(4,2,6,5)^==2 then say "Error in min test"
  137. if overlay("1","abcdefg",3,2,0)^=="ab10efg" then say "Error in overlay test"
  138. if pos("23","21234")^==3 then say "Error in pos test"
  139. say "Random test:" random() random() random()
  140. if reverse("1abcde2")^=="2edcba1" then say "Error in reverse test"
  141. if right(1,2,0)^=="01"|right(123,1)^=="3" then say "Error in right test"
  142. signal srctest
  143. SrcTest:
  144. if sourceline(sigl)^=="signal srctest" then say "Error in sourceline test"
  145. if space("  hi    there",2,0)^=="hi00there" then say "Error in space test"
  146. if strip("  hi  there  ","l")^=="hi  there  " then say "Error in strip test"
  147. if substr("abc",2,4,"0")^=="bc00"|substr("abc",-1)^=="  abc"|,
  148.    substr("12345",2,2)^=="23" then say "Error in substr test"
  149. if subword(" this is  a   test ",2,2)^=="is  a" then say "Error in subword test"
  150. if symbol("123f")^=="LIT"|symbol(123)^=="LIT"|,
  151.    symbol("a")^=="VAR"|symbol("lit")^=="LIT" then say "Error in symbol test"
  152. say "Time test:" time('c')
  153. if trace()^=="F" then say "Error in trace test"
  154. if translate('abc123DEF')^=='ABC123DEF'|,
  155.    translate('abbc','&','b')^=='a&&c'|,
  156.    translate('abcdef','12','ec')^=='ab2d1f' then say "Error in translate test"
  157. if trunc(12.6)^==12|trunc(345e-2,1)^==3.4|trunc(26,5)^==26.00000 then
  158.    say "Error in trunc test"
  159. a=1;b.a=2
  160. if value("b.a")^==2 then say "Error in value test"
  161. if verify('123','1234567890')^==0|,
  162.    verify('1Z3','1234567890')^==2|,
  163.    verify('AB4T','1234567890','M')^==3|,
  164.    verify('1P3Q4','1234567890',,3)^==4 then say "Error in verify test"
  165. if word(" this  is a  test",2)^=="is" then say "Error in word test"
  166. if wordindex("This is a test",2)^==6 then say "Error in wordindex test"
  167. if wordlength("This  is a test",2)^==2 then say "Error in wordlength test"
  168. if wordpos("is a","  this  is   a test")^==2 then say "Error in wordpos test"
  169. if words(" this  is a  test")^==4 then say "Error in words test"
  170. if xrange("a","g")^=="abcdefg" then say "Error in xrange test"
  171. say "Function tests completed."
  172. say "Testing I/O"
  173. f="/tmp/testfile"
  174. rc=stream(f,'c','open w')
  175. if rc then say "Open of test file failed with "errortext(100+rc)
  176. if lineout(f,"Testing, testing, 1, 2, 3") then
  177.    say "lineout failed with" stream(f,'d')
  178. rc=stream(f,'c','close')
  179. if rc then say "Close of test file failed with" errortext(100+rc)
  180. if linein(f)^="Testing, testing, 1, 2, 3" then
  181.    say "linein failed with" stream(f,'d')
  182. do i=1 to 10
  183.    do j=1 to 20
  184.       if charout(f,j) then say "charout filed with" stream(f,'d')
  185.    end
  186.    call lineout f,"<-"i
  187. end
  188. if linein(f)^="1234567891011121314151617181920<-1" then say "linein failed"
  189. say "Line 5 is:" linein(f,6)
  190. if lineout(f,"blah-blah",2) then say "lineout failed with" stream(f,'d')
  191. call lineout f
  192. call lineout f,"another test"
  193. if charin(f,27,9)^="blah-blah" | linein(f,13)^="another test" then
  194.    say "charin/linein failed"
  195. call stream f,'c','close'
  196.  
  197. c="ls -alg" f
  198. rc=stream('ls','c','popen r,'c)
  199. if rc then say "popen failed with" errortext(100+rc)
  200. parse value linein('ls') with . . . s1 s . . n1 n .
  201. rc=stream('ls','c','pclose')
  202. if rc then say "pclose gave rc="rc
  203. if s1=390 then parse value s1 n1 with s n /* we are on HP-UX */
  204. if s^=390|n^=f then say "pipe read failed"
  205. call stream f,'c','open'
  206. fd=stream(f,'c','fileno')
  207. rc=stream(fd,'c','fdopen')
  208. if rc then say "fdopen failed with" errortext(100+rc)
  209. if linein(fd,3)^="011121314151617181920<-1" then
  210.    say "linein from fd" fd "failed"
  211. call stream fd,'c','close'
  212. call stream f,'c','close'
  213. say "I/O test completed"
  214.  
  215. exit
  216.  
  217. Test1:return 'result'
  218. TEST2:procedure expose b
  219. b=0
  220. a=1
  221. return
  222. Test3:return arg()arg(1)
  223.  
  224. Syntax:
  225. say left(sigl,5) "+++" sourceline(sigl)
  226. say "Error" rc "running rexxtest.rexx, line" sigl":" errortext(rc)
  227. trace ?r
  228. say "Trace mode"
  229.