tools.completion: undo private change, and add tests.

db4
John Benediktsson 2011-09-13 09:22:57 -07:00
parent 2cdff2746c
commit 36da386816
2 changed files with 16 additions and 2 deletions

View File

@ -0,0 +1,14 @@
USING: assocs kernel tools.completion tools.completion.private
tools.test ;
IN: tools.completion
[ f ] [ "abc" "def" fuzzy ] unit-test
[ V{ 4 5 6 } ] [ "set-nth" "nth" fuzzy ] unit-test
[ V{ V{ 0 } V{ 4 5 6 } } ] [ V{ 0 4 5 6 } runs ] unit-test
[ { "nth" "?nth" "set-nth" } ] [
"nth" { "set-nth" "nth" "?nth" } dup zip completions keys
] unit-test

View File

@ -14,6 +14,8 @@ IN: tools.completion
rot [ ch>lower ] [ ch>upper ] bi
[ eq? ] bi-curry@ [ bi or ] 2curry find-from drop ;
PRIVATE>
:: (fuzzy) ( accum i full ch -- accum i full ? )
ch i full smart-index-from [
:> i i accum push
@ -75,8 +77,6 @@ IN: tools.completion
: completion, ( short candidate -- )
completion dup first 0 > [ , ] [ drop ] if ;
PRIVATE>
: completions ( short candidates -- seq )
[ ] [
[ [ completion, ] with each ] { } make