PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/stringtest.fth

https://gitlab.com/BGCX261/zmforth-hg-to-git
Forth | 133 lines | 96 code | 37 blank | 0 comment | 1 complexity | 75a7d30edf75138f605df84b82f0923b MD5 | raw file
Possible License(s): GPL-3.0
  1. \ To test the ANS Forth String word set
  2. \ Copyright (C) Gerry Jackson 2006, 2007
  3. \ This program is free software; you can redistribute it and/or
  4. \ modify it any way.
  5. \ This program is distributed in the hope that it will be useful,
  6. \ but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. \ The tests are not claimed to be comprehensive or correct
  9. \ --------------------------------------------------------------------
  10. \ Version 0.3 6 March 2009 { and } replaced with T{ and }T
  11. \ 0.2 20 April 2007 ANS Forth words changed to upper case
  12. \ 0.1 Oct 2006 First version released
  13. \ --------------------------------------------------------------------
  14. \ The tests are based on John Hayes test program for the core word set
  15. \ and requires those files to have been loaded
  16. \ Words tested in this file are:
  17. \ -TRAILING /STRING BLANK COMPARE SEARCH SLITERAL
  18. \
  19. \ Tests to be added:
  20. \ CMOVE CMOVE>
  21. \
  22. \ --------------------------------------------------------------------
  23. \ Assumptions and dependencies:
  24. \ - tester.fr has been loaded prior to this file
  25. \ - COMPARE is case sensitive
  26. \ --------------------------------------------------------------------
  27. Testing String word set
  28. DECIMAL
  29. 0 INVERT CONSTANT <true>
  30. 0 CONSTANT <false>
  31. T{ : s1 S" abcdefghijklmnopqrstuvwxyz" ; -> }T
  32. T{ : s2 S" abc" ; -> }T
  33. T{ : s3 S" jklmn" ; -> }T
  34. T{ : s4 S" z" ; -> }T
  35. T{ : s5 S" mnoq" ; -> }T
  36. T{ : s6 S" 12345" ; -> }T
  37. T{ : s7 S" " ; -> }T
  38. T{ : s8 S" abc " ; -> }T
  39. T{ : s9 S" " ; -> }T
  40. T{ : s10 S" a " ; -> }T
  41. \ --------------------------------------------------------------------
  42. Testing -TRAILING
  43. T{ s1 -TRAILING -> s1 }T
  44. T{ s8 -TRAILING -> s8 2 - }T
  45. T{ s7 -TRAILING -> s7 }T
  46. T{ s9 -TRAILING -> s9 DROP 0 }T
  47. T{ s10 -TRAILING -> s10 1- }T
  48. \ --------------------------------------------------------------------
  49. Testing /STRING
  50. T{ s1 5 /STRING -> s1 SWAP 5 + SWAP 5 - }T
  51. T{ s1 10 /STRING -4 /STRING -> s1 6 /STRING }T
  52. T{ s1 0 /STRING -> s1 }T
  53. \ --------------------------------------------------------------------
  54. Testing SEARCH
  55. T{ s1 s2 SEARCH -> s1 <true> }T
  56. T{ s1 s3 SEARCH -> s1 9 /STRING <true> }T
  57. T{ s1 s4 SEARCH -> s1 25 /STRING <true> }T
  58. T{ s1 s5 SEARCH -> s1 <false> }T
  59. T{ s1 s6 SEARCH -> s1 <false> }T
  60. T{ s1 s7 SEARCH -> s1 <true> }T
  61. \ --------------------------------------------------------------------
  62. Testing COMPARE
  63. T{ s1 s1 COMPARE -> 0 }T
  64. T{ s1 PAD SWAP CMOVE -> }T
  65. T{ s1 PAD OVER COMPARE -> 0 }T
  66. T{ s1 PAD 6 COMPARE -> 1 }T
  67. T{ PAD 10 s1 COMPARE -> -1 }T
  68. T{ s1 PAD 0 COMPARE -> 1 }T
  69. T{ PAD 0 s1 COMPARE -> -1 }T
  70. T{ s1 s6 COMPARE -> 1 }T
  71. T{ s6 s1 COMPARE -> -1 }T
  72. : "abdde" S" abdde" ;
  73. : "abbde" S" abbde" ;
  74. : "abcdf" S" abcdf" ;
  75. : "abcdee" S" abcdee" ;
  76. T{ s1 "abdde" COMPARE -> -1 }T
  77. T{ s1 "abbde" COMPARE -> 1 }T
  78. T{ s1 "abcdf" COMPARE -> -1 }T
  79. T{ s1 "abcdee" COMPARE -> 1 }T
  80. : s11 S" 0abc" ;
  81. : s12 S" 0aBc" ;
  82. T{ s11 s12 COMPARE -> 1 }T
  83. T{ s12 s11 COMPARE -> -1 }T
  84. \ --------------------------------------------------------------------
  85. Testing BLANK
  86. : s13 S" aaaaa a" ; \ Don't move this down or might corrupt PAD
  87. T{ PAD 25 CHAR a FILL -> }T
  88. T{ PAD 5 CHARS + 6 BLANK -> }T
  89. T{ PAD 12 s13 COMPARE -> 0 }T
  90. \ --------------------------------------------------------------------
  91. Testing SLITERAL
  92. T{ : s14 [ s1 ] SLITERAL ; -> }T
  93. T{ s1 s14 COMPARE -> 0 }T
  94. T{ s1 s14 ROT = ROT ROT = -> <true> <false> }T
  95. \ --------------------------------------------------------------------
  96. CR .( End of String word tests) CR