From a7e7b74e3efc09af94e417ae46647ebc301a367f Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Sat, 26 Jun 2021 13:30:32 -0700 Subject: [PATCH] Fixed line overflow to ACCEPT. --- ueforth/common/base_tests.fs | 14 ++++++++++++++ ueforth/common/boot.fs | 5 ++++- ueforth/common/testing.fs | 11 +++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/ueforth/common/base_tests.fs b/ueforth/common/base_tests.fs index f042fc1..4aff468 100644 --- a/ueforth/common/base_tests.fs +++ b/ueforth/common/base_tests.fs @@ -84,3 +84,17 @@ e: test-recurse : factorial dup 0= if drop 1 else dup 1- recurse * then ; 5 factorial 120 = assert ;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 diff --git a/ueforth/common/boot.fs b/ueforth/common/boot.fs index 9eb9744..22c86bc 100644 --- a/ueforth/common/boot.fs +++ b/ueforth/common/boot.fs @@ -217,7 +217,10 @@ variable echo -1 echo ! variable arrow -1 arrow ! dup ?echo >r rot r> over c! 1+ -rot swap 1+ swap 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 : tib ( -- a ) 'tib @ ; create input-buffer input-limit allot diff --git a/ueforth/common/testing.fs b/ueforth/common/testing.fs index b6ac1f1..d4a2f88 100644 --- a/ueforth/common/testing.fs +++ b/ueforth/common/testing.fs @@ -30,6 +30,17 @@ variable confirm-old-type : expect-finish expected resulted str= if exit then }confirm 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 ) ( run-tests runs all words starting with "test-", use assert to assert things. ) variable tests-found variable tests-run variable tests-passed