PageRenderTime 60ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/searchordertest.fth

https://gitlab.com/BGCX261/zmforth-hg-to-git
Forth | 187 lines | 94 code | 46 blank | 47 comment | 1 complexity | 1ea6e45a9c80b48f293dca4e639d0313 MD5 | raw file
Possible License(s): GPL-3.0
  1. \ To test the ANS Forth search-order word set and search order extensions
  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.4 6 March 2009 { and } replaced with T{ and }T
  11. \ 0.3 20 April 2007 ANS Forth words changed to upper case
  12. \ 0.2 30 Oct 2006 updated following GForth tests to get
  13. \ initial search order into a known state
  14. \ 0.1 Oct 2006 First version released
  15. \ ------------------------------------------------------------------------------
  16. \ The tests are based on John Hayes test program for the core word set
  17. \ and requires those files to have been loaded
  18. \ Words tested in this file are:
  19. \ FORTH-WORDLIST GET-ORDER SET-ORDER ALSO ONLY FORTH GET-CURRENT
  20. \ SET-CURRENT DEFINITIONS PREVIOUS SEARCH-WORDLIST WORDLIST FIND
  21. \ Words not fully tested:
  22. \ ORDER ONLY tests that it executes, display is implementation
  23. \ dependent
  24. \ ------------------------------------------------------------------------------
  25. \ Assumptions and dependencies:
  26. \ - tester.fr has been loaded prior to this file
  27. \ - that ONLY FORTH DEFINITIONS will work at the start of the file
  28. \ to ensure the search order is in a known state
  29. \ ------------------------------------------------------------------------------
  30. ONLY FORTH DEFINITIONS
  31. Testing Search-order word set
  32. DECIMAL
  33. VARIABLE wid1 VARIABLE wid2
  34. : save-orderlist ( widn ... wid1 n -> ) DUP , 0 ?DO , LOOP ;
  35. \ ------------------------------------------------------------------------------
  36. Testing FORTH-WORDLIST GET-ORDER SET-ORDER
  37. T{ FORTH-WORDLIST wid1 ! -> }T
  38. CREATE order-list
  39. T{ GET-ORDER save-orderlist -> }T
  40. : get-orderlist ( -- widn ... wid1 n )
  41. order-list DUP @ CELLS ( -- ad n )
  42. OVER + ( -- AD AD' )
  43. ?DO I @ -1 CELLS +LOOP ( -- )
  44. ;
  45. T{ GET-ORDER OVER -> GET-ORDER wid1 @ }T \ Forth wordlist at top
  46. T{ GET-ORDER SET-ORDER -> }T \ Effectively noop
  47. T{ GET-ORDER -> get-orderlist }T \ Check nothing changed
  48. T{ get-orderlist DROP get-orderList 2* SET-ORDER -> }T
  49. T{ GET-ORDER -> get-orderlist DROP get-orderList 2* }T
  50. T{ get-orderlist SET-ORDER GET-ORDER -> get-orderlist }T
  51. \ ------------------------------------------------------------------------------
  52. Testing ALSO ONLY FORTH
  53. T{ ALSO GET-ORDER -> get-orderlist OVER SWAP 1+ }T
  54. T{ ONLY FORTH GET-ORDER -> get-orderlist }T \ See assumptions above
  55. \ ------------------------------------------------------------------------------
  56. Testing GET-CURRENT SET-CURRENT WORDLIST (simple)
  57. T{ GET-CURRENT -> wid1 @ }T \ See assumptions above
  58. T{ WORDLIST wid2 ! -> }T
  59. T{ wid2 @ SET-CURRENT -> }T
  60. T{ GET-CURRENT -> wid2 @ }T
  61. T{ wid1 @ SET-CURRENT
  62. \ ------------------------------------------------------------------------------
  63. Testing minimum search order list contains FORTH-WORDLIST and SET-ORDER
  64. : so1 SET-ORDER ; \ In case it is unavailable in the forth wordlist
  65. T{ ONLY FORTH-WORDLIST 1 SET-ORDER get-orderlist so1 -> }T
  66. T{ GET-ORDER -> get-orderlist }T
  67. \ ------------------------------------------------------------------------------
  68. Testing GET-ORDER SET-ORDER with 0 and -1 number of wids argument
  69. : so2a GET-ORDER get-orderlist SET-ORDER ; \ To recover search order
  70. : so2 0 SET-ORDER so2a ;
  71. T{ so2 -> 0 }T \ 0 set-order leaves an empty search order
  72. : so3 -1 SET-ORDER so2a ;
  73. : so4 ONLY so2a ;
  74. T{ so3 -> so4 }T \ -1 SET-ORDER = ONLY
  75. \ ------------------------------------------------------------------------------
  76. Testing DEFINITIONS PREVIOUS
  77. T{ ONLY FORTH DEFINITIONS -> }T
  78. T{ GET-CURRENT -> FORTH-WORDLIST }T
  79. T{ GET-ORDER wid2 @ SWAP 1+ SET-ORDER DEFINITIONS GET-CURRENT -> wid2 @ }T
  80. T{ GET-ORDER -> get-orderlist wid2 @ SWAP 1+ }T
  81. T{ PREVIOUS GET-ORDER -> get-orderlist }T
  82. T{ DEFINITIONS GET-CURRENT -> forth-wordlist }T
  83. \ ------------------------------------------------------------------------------
  84. Testing SEARCH-WORDLIST WORDLIST FIND
  85. ONLY FORTH DEFINITIONS
  86. VARIABLE xt ' DUP xt !
  87. VARIABLE xti ' .( xti ! \ Immediate word
  88. T{ S" DUP" wid1 @ SEARCH-WORDLISt -> xt @ -1 }T
  89. T{ S" .(" wid1 @ SEARCH-WORDLIST -> xti @ 1 }T
  90. T{ S" DUP" wid2 @ SEARCH-WORDLIST -> 0 }T
  91. : c"dup" C" DUP" ;
  92. : c".(" C" .(" ;
  93. : c"x" C" unknown word" ;
  94. T{ c"dup" FIND -> xt @ -1 }T
  95. T{ c".(" FIND -> xti @ 1 }T
  96. T{ c"x" FIND -> c"x" 0 }T
  97. \ ------------------------------------------------------------------------------
  98. Testing new definitions are put into the correct wordlist
  99. : alsowid2 ALSO GET-ORDER wid2 @ ROT DROP SWAP SET-ORDER ;
  100. alsowid2
  101. : w1 1234 ;
  102. DEFINITIONS
  103. : w1 -9876 ; IMMEDIATE
  104. ONLY FORTH
  105. T{ w1 -> 1234 }T
  106. DEFINITIONS
  107. T{ w1 -> 1234 }T
  108. alsowid2
  109. T{ w1 -> -9876 }T
  110. DEFINITIONS
  111. T{ w1 -> -9876 }T
  112. ONLY FORTH DEFINITIONS
  113. : so5 DUP IF SWAP EXECUTE THEN ;
  114. T{ S" w1" wid1 @ SEARCH-WORDLIST so5 -> -1 1234 }T
  115. T{ S" w1" wid2 @ SEARCH-WORDLIST so5 -> 1 -9876 }T
  116. : c"w1" C" w1" ;
  117. T{ alsowid2 c"w1" FIND so5 -> 1 -9876 }T
  118. T{ previous c"w1" FIND so5 -> -1 1234 }T
  119. \ ------------------------------------------------------------------------------
  120. Testing ORDER \ Should display search order and compilation wordlist
  121. cr .( ONLY FORTH DEFINITIONS search order and compilation list) cr
  122. T{ ONLY FORTH DEFINITIONS ORDER -> }T
  123. cr .( Plus another unnamed wordlist at the head of the search order) cr
  124. T{ alsowid2 DEFINITIONS ORDER -> }T
  125. \ ------------------------------------------------------------------------------
  126. CR .( End of Search Order word tests) CR
  127. ONLY FORTH DEFINITIONS \ Leave search order in the standard state