factor/basis/ui/traverse/traverse-tests.factor

66 lines
1.7 KiB
Factor
Raw Normal View History

USING: accessors ui.gadgets ui.gadgets.labels namespaces make
sequences kernel math arrays tools.test io ui.gadgets.panes
ui.traverse definitions compiler.units ;
2008-09-01 08:14:43 -04:00
IN: ui.traverse.tests
M: array children>> ;
2007-09-20 18:09:08 -04:00
GENERIC: (flatten-tree) ( node -- )
M: node (flatten-tree)
2008-09-02 02:52:22 -04:00
children>> [ (flatten-tree) ] each ;
2007-09-20 18:09:08 -04:00
M: object (flatten-tree) , ;
: flatten-tree ( seq -- newseq )
[ [ (flatten-tree) ] each ] { } make ;
: gadgets-in-range ( frompath topath gadget -- seq )
gadget-subtree flatten-tree ;
[ { "a" "b" "c" "d" } ] [
{ 0 } { } { "a" "b" "c" "d" } gadgets-in-range
] unit-test
[ { "a" "b" } ] [
{ } { 1 } { "a" "b" "c" "d" } gadgets-in-range
] unit-test
[ { "a" } ] [
{ 0 } { 0 } { "a" "b" "c" "d" } gadgets-in-range
] unit-test
[ { "a" "b" "c" } ] [
{ 0 } { 2 } { "a" "b" "c" "d" } gadgets-in-range
] unit-test
[ { "a" "b" "c" "d" } ] [
{ 0 } { 3 } { "a" "b" "c" "d" } gadgets-in-range
] unit-test
[ { "a" "b" "c" "d" } ] [
{ 0 0 } { 0 3 } { { "a" "b" "c" "d" } } gadgets-in-range
] unit-test
[ { "b" "c" "d" "e" } ] [
{ 0 1 } { 1 } { { "a" "b" "c" "d" } "e" } gadgets-in-range
] unit-test
[ { "b" "c" "d" "e" "f" } ] [
{ 0 1 } { 1 1 } { { "a" "b" "c" "d" } { "e" "f" "g" } } gadgets-in-range
] unit-test
[ { "b" "c" "d" { "e" "f" "g" } "h" "i" } ] [
{ 0 1 } { 2 1 } { { "a" "b" "c" "d" } { "e" "f" "g" } { "h" "i" } } gadgets-in-range
] unit-test
[ { "b" "c" "d" { "e" "f" "g" } "h" } ] [
{ 0 1 } { 2 0 0 } { { "a" "b" "c" "d" } { "e" "f" "g" } { { "h" "i" } "j" } } gadgets-in-range
] unit-test
[ { "b" "c" "d" { "e" "f" "g" } "h" "i" } ] [
{ 0 1 } { 2 0 1 } { { "a" "b" "c" "d" } { "e" "f" "g" } { { "h" "i" } "j" } } gadgets-in-range
] unit-test
2009-04-06 06:22:28 -04:00
[ M\ array children>> forget ] with-compilation-unit