From: Michael Stapelberg Date: Mon, 10 May 2010 07:08:31 +0000 (+0200) Subject: Implement 'prev', extend testcase X-Git-Tag: tree-pr1~223 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=145ebc7584cb3c41c19c02bc6053774aa9dc651f;p=i3%2Fi3 Implement 'prev', extend testcase --- diff --git a/src/cmdparse.l b/src/cmdparse.l index 318da934..ee73c7b9 100644 --- a/src/cmdparse.l +++ b/src/cmdparse.l @@ -100,6 +100,9 @@ focus { return TOK_FOCUS; } move { return TOK_MOVE; } open { return TOK_OPEN; } next { return TOK_NEXT; } +prev { return TOK_PREV; } +horizontal { return TOK_HORIZONTAL; } +vertical { return TOK_VERTICAL; } class { BEGIN(WANT_QSTRING); return TOK_CLASS; } id { BEGIN(WANT_QSTRING); return TOK_ID; } diff --git a/src/cmdparse.y b/src/cmdparse.y index c3b19686..d77fa4ca 100644 --- a/src/cmdparse.y +++ b/src/cmdparse.y @@ -112,6 +112,9 @@ void parse_cmd(const char *new) { %token TOK_MOVE "move" %token TOK_OPEN "open" %token TOK_NEXT "next" +%token TOK_PREV "prev" +%token TOK_HORIZONTAL "horizontal" +%token TOK_VERTICAL "vertical" %token TOK_CLASS "class" %token TOK_ID "id" @@ -252,6 +255,7 @@ operation: | open | fullscreen | next + | prev ; exec: @@ -345,9 +349,17 @@ next: } ; +prev: + TOK_PREV WHITESPACE direction + { + printf("should select prev window in direction %c\n", $3); + tree_next('p', ($3 == 'v' ? VERT : HORIZ)); + } + ; + direction: - 'h' { $$ = 'h'; } - | 'horizontal' { $$ = 'h'; } + TOK_HORIZONTAL { $$ = 'h'; } + | 'h' { $$ = 'h'; } + | TOK_VERTICAL { $$ = 'v'; } | 'v' { $$ = 'v'; } - | 'vertical' { $$ = 'v'; } ; diff --git a/testcases/t/21-next-prev.t b/testcases/t/21-next-prev.t index 3759e256..8ed3ada7 100644 --- a/testcases/t/21-next-prev.t +++ b/testcases/t/21-next-prev.t @@ -3,7 +3,7 @@ # # Tests focus switching (next/prev) # -use i3test tests => 4; +use i3test tests => 13; use X11::XCB qw(:all); use v5.10; @@ -31,22 +31,60 @@ is($focus->[0], $old_focused, 'focus did not change with only one con'); ###################################################################### # Open another container, verify that 'next h' switches ###################################################################### +my $left = $old_focused; + $i3->command('open')->recv; +($nodes, $focus) = get_ws_content($tmp); +isnt($old_focused, $focus->[0], 'new container is focused'); +my $mid = $focus->[0]; +$i3->command('open')->recv; ($nodes, $focus) = get_ws_content($tmp); isnt($old_focused, $focus->[0], 'new container is focused'); -$old_focused = $focus->[0]; +my $right = $focus->[0]; + +$i3->command('next h')->recv; +($nodes, $focus) = get_ws_content($tmp); +isnt($focus->[0], $right, 'focus did change'); +is($focus->[0], $left, 'left container focused (wrapping)'); + +$i3->command('next h')->recv; +($nodes, $focus) = get_ws_content($tmp); +is($focus->[0], $mid, 'middle container focused'); $i3->command('next h')->recv; +($nodes, $focus) = get_ws_content($tmp); +is($focus->[0], $right, 'right container focused'); + +$i3->command('prev h')->recv; +($nodes, $focus) = get_ws_content($tmp); +is($focus->[0], $mid, 'middle container focused'); + +$i3->command('prev h')->recv; +($nodes, $focus) = get_ws_content($tmp); +is($focus->[0], $left, 'left container focused'); + +$i3->command('prev h')->recv; +($nodes, $focus) = get_ws_content($tmp); +is($focus->[0], $right, 'right container focused'); + +###################################################################### +# Test synonyms (horizontal/vertical instead of h/v) +###################################################################### + +$i3->command('prev horizontal')->recv; ($nodes, $focus) = get_ws_content($tmp); -isnt($focus->[0], $old_focused, 'focus did change'); +is($focus->[0], $mid, 'middle container focused'); + +$i3->command('next horizontal')->recv; +($nodes, $focus) = get_ws_content($tmp); +is($focus->[0], $right, 'right container focused'); + # -# TODO: extend this test-case: -# - implement prev +# TODO: extend this test-case (as soon as splitting is implemented): # - wrapping (no horizontal switch possible, goes level-up) # - going level-up "manually" -# - different synonyms (horizontal/vertical) diag( "Testing i3, Perl $], $^X" );