Annotation of gforth/test/other.fs, revision 1.18

1.1       anton       1: \ various tests, especially for bugs that have been fixed
                      2: 
1.17      anton       3: \ Copyright (C) 1997,1998,2000 Free Software Foundation, Inc.
1.1       anton       4: 
                      5: \ This file is part of Gforth.
                      6: 
                      7: \ Gforth is free software; you can redistribute it and/or
                      8: \ modify it under the terms of the GNU General Public License
                      9: \ as published by the Free Software Foundation; either version 2
                     10: \ of the License, or (at your option) any later version.
                     11: 
                     12: \ This program is distributed in the hope that it will be useful,
                     13: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
                     14: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     15: \ GNU General Public License for more details.
                     16: 
                     17: \ You should have received a copy of the GNU General Public License
                     18: \ along with this program; if not, write to the Free Software
1.18    ! anton      19: \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
1.1       anton      20: 
                     21: \ combination of marker and locals
                     22: marker foo1
                     23: marker foo2
                     24: foo2
                     25: 
                     26: : bar { xxx yyy } ;
                     27: 
                     28: foo1
                     29: 
                     30: \ locals in an if structure
                     31: : locals-test1
                     32:     lp@ swap
                     33:     if
                     34:        { a } a
                     35:     else
                     36:     endif
                     37:     lp@ <> abort" locals in if error 1" ;
                     38: 
                     39: 0 locals-test1
                     40: 1 locals-test1
                     41: 
                     42: 
                     43: \ recurse and locals
                     44: 
                     45: : fac { n -- n! }
                     46:     n 0>
                     47:     if
                     48:        n 1- recurse n *
                     49:     else
                     50:        1
                     51:     endif ;
                     52: 
                     53: 5 fac 120 <> throw
                     54: 
1.5       anton      55: \ TO and locals
                     56: 
                     57: : locals-test2 ( -- )
                     58:     true dup dup dup { addr1 u1 addr2 u2 -- n }
                     59:     false TO addr1
                     60:     addr1 false <> abort" TO does not work on locals" ;
                     61: locals-test2
                     62: 
1.7       anton      63: : locals-test3 ( -- )
                     64:     \ this should compile, but gives "invalid name argument" on gforth-0.3.0
                     65:     0 { a b } 0 to a ;
                     66: 
1.5       anton      67: \ multiple reveals (recursive)
                     68: 
                     69: 0
1.10      anton      70: : xxx recursive ;
1.5       anton      71: throw \ if the TOS is not 0, throw an error
                     72: 
1.1       anton      73: \ look for primitives
                     74: 
                     75: ' + look 0= throw ( nt )
                     76: s" +" find-name <> throw
                     77: 
                     78: \ represent
                     79: 
                     80: 1e pad 5 represent -1 <> swap 0 <> or swap 1 <> or throw
                     81: 
1.2       anton      82: \ -trailing
                     83: 
                     84: s" a     " 2 /string -trailing throw drop
1.1       anton      85: 
1.3       anton      86: \ convert (has to skip first char)
                     87: 
                     88: 0. s" 123  " drop convert drop 23. d<> throw
                     89: 
1.4       anton      90: \ search
                     91: 
                     92: name abc 2dup name xyza search throw d<> throw
                     93: name b 2dup name abc search throw d<> throw
1.5       anton      94: 
                     95: \ only
                     96: 
                     97: : test-only ( -- )
                     98:     get-order get-current
                     99:     0 set-current
                    100:     only
                    101:     get-current >r
                    102:     set-current set-order
                    103:     r> abort" ONLY sets current" ;
                    104: test-only
1.4       anton     105: 
1.6       anton     106: \ create-interpret/compile
                    107: 
1.7       anton     108: : my-constant ( n "name" -- )
1.6       anton     109:     create-interpret/compile
                    110:     ,
                    111: interpretation>
                    112:     @
                    113: <interpretation
                    114: compilation>
                    115:     @ postpone literal
                    116: <compilation ;
                    117: 
1.7       anton     118: 5 my-constant five
1.6       anton     119: five 5 <> throw
                    120: : five' five ;
                    121: five' 5 <> throw
                    122: 
1.7       anton     123: \ structs and alignment
                    124: 
                    125: struct
                    126:   char% field field1
                    127:   float% field field2
                    128: end-struct my-struct%
                    129: 
                    130: 0 field2 float% %alignment <> throw
                    131: 
1.11      anton     132: \ filenames with "//"
                    133: 
                    134: s" //jkfklfggfld/fjsjfk/hjfdjs" open-fpath-file 2drop
                    135: 
1.12      anton     136: \ allotting negative space
                    137: 
                    138: 1 allot
                    139: -1 allot
                    140: 
1.13      anton     141: \ unaligned input for head?
                    142: 
                    143: here 1+ head? throw
                    144: 
1.14      anton     145: \ [compile] exit = exit
                    146: 
                    147: : foo [compile] exit abort" '[compile] exit' broken" ;
                    148: foo
                    149: 
1.15      anton     150: \ restore-input
                    151: 
                    152: : test-restore-input[ ( -- )
                    153:     refill 0= abort" refill failed"
                    154:     bl word drop
                    155:     save-input
                    156:     refill 0= abort" refill failed"
                    157:     -1 ;
                    158: 
                    159: : ]test-restore-input ( -- )
                    160:     drop restore-input abort" restore-input failed" 0 ;
                    161: 
                    162: \ First input is skipped until the "]test-restore-input", then it is
                    163: \ reset to just before "0 [if]"
                    164: test-restore-input[ abort \ these aborts are skipped
                    165: abort 0 [if]
                    166:     s" oops" 2drop ]test-restore-input abort
                    167: [then]
                    168: ( 0 ) throw
                    169: 
1.16      anton     170: \ the same test with CRLF newlines
                    171: test-restore-input[ abort \ these aborts are skipped
                    172: abort 0 [if]
                    173:     s" oops" 2drop ]test-restore-input abort
                    174: [then]
                    175: ( 0 ) throw
                    176: 
1.1       anton     177: \ comments across several lines
                    178: 
                    179: ( fjklfjlas;d
                    180: abort" ( does not work across lines"
                    181: )
                    182: 
1.7       anton     183: s" ( testing ( without being delimited by newline in non-files" evaluate
1.1       anton     184: 
                    185: \ last test!
                    186: \ testing '(' without ')' at end-of-file
                    187: ." expect ``warning: ')' missing''" cr
                    188: (

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>