File:  [gforth] / gforth / test / other.fs
Revision 1.5: download - view: text, annotated - select for diffs
Fri Oct 24 17:13:31 1997 UTC (26 years, 5 months ago) by anton
Branches: MAIN
CVS tags: HEAD
bugfix (multiple REVEALs had wrong stack effect)
added test for ONLY bug

    1: \ various tests, especially for bugs that have been fixed
    2: 
    3: \ Copyright (C) 1997 Free Software Foundation, Inc.
    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
   19: \ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   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: 
   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: 
   63: \ multiple reveals (recursive)
   64: 
   65: 0
   66: : xxx recursive ;
   67: throw \ if the TOS is not 0, throw an error
   68: 
   69: \ look for primitives
   70: 
   71: ' + look 0= throw ( nt )
   72: s" +" find-name <> throw
   73: 
   74: \ represent
   75: 
   76: 1e pad 5 represent -1 <> swap 0 <> or swap 1 <> or throw
   77: 
   78: \ -trailing
   79: 
   80: s" a     " 2 /string -trailing throw drop
   81: 
   82: \ convert (has to skip first char)
   83: 
   84: 0. s" 123  " drop convert drop 23. d<> throw
   85: 
   86: \ search
   87: 
   88: name abc 2dup name xyza search throw d<> throw
   89: name b 2dup name abc search throw d<> throw
   90: 
   91: \ only
   92: 
   93: : test-only ( -- )
   94:     get-order get-current
   95:     0 set-current
   96:     only
   97:     get-current >r
   98:     set-current set-order
   99:     r> abort" ONLY sets current" ;
  100: test-only
  101: 
  102: \ comments across several lines
  103: 
  104: ( fjklfjlas;d
  105: abort" ( does not work across lines"
  106: )
  107: 
  108: s" ( testing ( without delimited by newline in non-files" evaluate
  109: 
  110: \ last test!
  111: \ testing '(' without ')' at end-of-file
  112: ." expect ``warning: ')' missing''" cr
  113: (

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