Fixed line overflow to ACCEPT.

This commit is contained in:
Brad Nelson
2021-06-26 13:30:32 -07:00
parent 867348249d
commit a7e7b74e3e
3 changed files with 29 additions and 1 deletions

View File

@ -84,3 +84,17 @@ e: test-recurse
: factorial dup 0= if drop 1 else dup 1- recurse * then ; : factorial dup 0= if drop 1 else dup 1- recurse * then ;
5 factorial 120 = assert 5 factorial 120 = assert
;e ;e
e: test-accept
in: 1234567890xxxxxx
pad 10 accept
pad swap type cr
out: --> 1234567890
out: 1234567890
;e
e: test-key
in: 1
key 49 = assert
key nl = assert
;e

View File

@ -217,7 +217,10 @@ variable echo -1 echo ! variable arrow -1 arrow !
dup ?echo dup ?echo
>r rot r> over c! 1+ -rot swap 1+ swap >r rot r> over c! 1+ -rot swap 1+ swap
then then
repeat drop nip ; repeat drop nip
( Eat rest of the line if buffer too small )
begin key dup nl = over 13 = or if ?echo exit else drop then again
;
200 constant input-limit 200 constant input-limit
: tib ( -- a ) 'tib @ ; : tib ( -- a ) 'tib @ ;
create input-buffer input-limit allot create input-buffer input-limit allot

View File

@ -30,6 +30,17 @@ variable confirm-old-type
: expect-finish expected resulted str= if exit then }confirm : expect-finish expected resulted str= if exit then }confirm
cr ." Expected:" cr expected type cr ." Resulted:" cr resulted type cr 1 throw ; cr ." Expected:" cr expected type cr ." Resulted:" cr resulted type cr 1 throw ;
( Input testing )
create in-buffer 1000 allot
variable in-head variable in-tail
: >in ( c -- ) in-buffer in-head @ + c! 1 in-head +! ;
: in> ( -- c ) in-tail @ in-head @ < assert
in-buffer in-tail @ + c@ 1 in-tail +!
in-head @ in-tail @ = if 0 in-head ! 0 in-tail ! then ;
: s>in ( a n -- ) for aft dup c@ >in 1+ then next drop ;
: in: ( "line" -- ) nl parse s>in nl >in ;
' in> is key
( Testing Framework ) ( Testing Framework )
( run-tests runs all words starting with "test-", use assert to assert things. ) ( run-tests runs all words starting with "test-", use assert to assert things. )
variable tests-found variable tests-run variable tests-passed variable tests-found variable tests-run variable tests-passed