! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: documents namespaces tools.test io.styles
-ui.tools.listener.history kernel ;
+
+USING: accessors documents io.styles kernel namespaces
+sequences tools.test ui.tools.listener.history ;
+
IN: ui.tools.listener.history.tests
[ ] [ <document> "d" set ] unit-test
[ ] [ " " "d" get set-doc-string ] unit-test
[ ] [ "h" get history-recall-previous ] unit-test
+[ 1 ] [
+ "abc" <document> [ set-doc-string ] [ <history> ] bi
+ [ history-add drop ]
+ [ history-add drop ]
+ [ elements>> length ] tri
+] unit-test
: <history> ( document -- history )
V{ } clone 0 history boa ;
+<PRIVATE
+
+: push-if-not-last ( elt seq -- )
+ dup empty? [ push ] [
+ dup last pick = [ 2drop ] [ push ] if
+ ] if ;
+
+PRIVATE>
+
: history-add ( history -- input )
dup elements>> length 1 + >>index
[ document>> doc-string [ <input> ] [ empty? ] bi ] keep
- '[ [ _ elements>> push ] keep ] unless ;
+ '[ [ _ elements>> push-if-not-last ] keep ] unless ;
<PRIVATE