Diff for /gforth/regexp-test.fs between versions 1.3 and 1.10

version 1.3, 2007/12/31 18:40:24 version 1.10, 2010/09/04 21:39:29
Line 1 Line 1
 \ regexp test  \ regexp test
   
 \ Copyright (C) 2005 Free Software Foundation, Inc.  \ Copyright (C) 2005,2007,2009 Free Software Foundation, Inc.
   
 \ This file is part of Gforth.  \ This file is part of Gforth.
   
Line 17 Line 17
 \ You should have received a copy of the GNU General Public License  \ You should have received a copy of the GNU General Public License
 \ along with this program. If not, see http://www.gnu.org/licenses/.  \ along with this program. If not, see http://www.gnu.org/licenses/.
   
 charclass [bl-]   blanks +class '- +char  charclass [bl-]   blanks +class '-' +char
 charclass [0-9(]  '( +char '0 '9 ..char  charclass [0-9(]  '(' +char '0' '9' ..char
   
 : telnum ( addr u -- flag )  : telnum ( addr u -- flag )
     (( {{ ` (  \( \d \d \d \) ` ) || \( \d \d \d \) }}  blanks c?      (( {{ ` (  \( \d \d \d \) ` ) || \( \d \d \d \) }}  blanks c?
Line 26  charclass [0-9(]  '( +char '0 '9 ..char Line 26  charclass [0-9(]  '( +char '0 '9 ..char
     \( \d \d \d \d \) {{ \$ || -\d }} )) ;      \( \d \d \d \d \) {{ \$ || -\d }} )) ;
   
 : ?tel ( addr u -- ) telnum  : ?tel ( addr u -- ) telnum
     IF  '( emit \1 type ." ) " \2 type '- emit \3 type ."  succeeded"      IF  '(' emit \1 type ." ) " \2 type '-' emit \3 type ."  succeeded"
     ELSE \0 type ."  failed " THEN ;      ELSE \0 type ."  failed " THEN ;
   
 : ?tel-s ( addr u -- ) ?tel ."  should succeed" space depth . cr ;  : ?tel-s ( addr u -- ) ?tel ."  should succeed" space depth . cr ;
Line 47  s" 123 456-78909" ?tel-f Line 47  s" 123 456-78909" ?tel-f
     \( \d \d \d \d \) {{ \$ || -\d }} )) ;      \( \d \d \d \d \) {{ \$ || -\d }} )) ;
   
 : ?tel2 ( addr u -- ) telnum2  : ?tel2 ( addr u -- ) telnum2
     IF   '( emit \1 type ." ) " \2 type '- emit \3 type ."  succeeded"      IF   '(' emit \1 type ." ) " \2 type '-' emit \3 type ."  succeeded"
     ELSE \0 type ."  failed " THEN  cr ;      ELSE \0 type ."  failed " THEN  cr ;
 ." --- Telephone number search ---" cr  ." --- Telephone number search ---" cr
 s" blabla (123) 456-7890" ?tel2  s" blabla (123) 456-7890" ?tel2
Line 65  s" abla 123 456-78909" ?tel2 Line 65  s" abla 123 456-78909" ?tel2
   
 ." --- Number extraction test ---" cr  ." --- Number extraction test ---" cr
   
 charclass [0-9,./:]  '0 '9 ..char ', +char '. +char '/ +char ': +char  charclass [0-9,./:]  '0' '9' ..char ',' +char '.' +char '/' +char ':' +char
   
 : ?num  : ?num
     (( // \( {++ [0-9,./:] c? ++} \) ))      (( // \( {++ [0-9,./:] c? ++} \) ))
Line 94  s" Hier kommt nichts vor" ?string Line 94  s" Hier kommt nichts vor" ?string
   
 : ?foobars  : ?foobars
     (( // \( {** =" foo" **} \) \( {++ =" bar" ++} \) ))      (( // \( {** =" foo" **} \) \( {++ =" bar" ++} \) ))
     IF  \1 type ', emit \2 type  ELSE  \0 type ."  failed"  THEN  cr ;      IF  \1 type ',' emit \2 type  ELSE  \0 type ."  failed"  THEN  cr ;
   
 : ?foos1  : ?foos1
     (( // \( {+ =" foo" +} \) \( {++ =" bar" ++} \) ))      (( // \( {+ =" foo" +} \) \( {++ =" bar" ++} \) ))
     IF  \1 type ', emit \2 type  ELSE  \0 type ."  failed"  THEN  cr ;      IF  \1 type ',' emit \2 type  ELSE  \0 type ."  failed"  THEN  cr ;
   
 s" foobar" ?foos  s" foobar" ?foos
 s" foofoofoobar" ?foos  s" foofoofoobar" ?foos
Line 118  s" fofoofoofofooofoobarbar" ?foos1 Line 118  s" fofoofoofofooofoobarbar" ?foos1
 s" bla baz bar" ?foos1  s" bla baz bar" ?foos1
 s" foofoofoo" ?foos1  s" foofoofoo" ?foos1
   
   \ simple replacement test
    
   ." --- delnum test ---" cr
   
   : delnum  ( addr u -- addr' u' )   s// \d s" " //g ;
   : test-delnum  ( addr u addr' u' -- )
      2swap delnum 2over 2over str= 0= IF
         ." test-delnum: got '" type ." ', expected '" type ." '"
      ELSE  2drop 2drop  THEN ;
   s" 0"  s" " test-delnum
   s" 00"  s" " test-delnum
   s" 0a"  s" a" test-delnum
   s" a0"  s" a" test-delnum
   s" aa"  s" aa" test-delnum
   
   \ replacement tests
   
   ." --- replacement tests ---" cr
   
   : hms>s ( addr u -- addr' u' )
     s// \( \d \d \) ` : \( \d \d \) ` : \( \d \d \)
     \1 s>number drop 60 *
     \2 s>number drop + 60 *
     \3 s>number drop + 0 <# 's' hold #s #> //g ;
   
   s" bla 12:34:56 fasel 00:01:57 blubber" 2dup type hms>s
   ."  replaced by " 2dup type
   s" bla 45296s fasel 117s blubber" str= [IF] .(  ok) [ELSE] .(  failed) [THEN] cr
   
 script? [IF] bye [THEN]  script? [IF] bye [THEN]

Removed from v.1.3  
changed lines
  Added in v.1.10


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