diff --git a/basis/tools/completion/completion-tests.factor b/basis/tools/completion/completion-tests.factor new file mode 100644 index 0000000000..316bc513cc --- /dev/null +++ b/basis/tools/completion/completion-tests.factor @@ -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 diff --git a/basis/tools/completion/completion.factor b/basis/tools/completion/completion.factor index ab675c8224..e0a43927ba 100644 --- a/basis/tools/completion/completion.factor +++ b/basis/tools/completion/completion.factor @@ -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