The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/bin/perl

use strict;
use warnings;

BEGIN {
   # We need to force TERM=xterm so that we can guarantee the right byte
   # sequences for testing
   $ENV{TERM} = "xterm";
}

use Test::More;
use Test::Identity;

use Tickit::Term;

my $term = Tickit::Term->new();
$term->set_size( 25, 80 );

{
   is( $term->lines, 25, '$term->lines 25 initially' );
   is( $term->cols,  80, '$term->cols 80 initially' );

   my ( $lines, $cols );
   my $id = $term->bind_event( resize => sub {
      my ( undef, $ev, $args ) = @_;
      identical( $_[0], $term, '$_[0] is term for resize event' );
      is( $ev, "resize", '$ev is resize for resize event' );
      $lines = $args->{lines};
      $cols  = $args->{cols};
   } );

   ok( defined $id, '$id defined for $term->bind_event' );

   $term->set_size( 30, 100 );

   is( $term->lines,  30, '$term->lines 30 after set_size' );
   is( $term->cols,  100, '$term->cols 100 after set_size' );

   is( $lines,  30, '$lines to bind_event sub after set_size' );
   is( $cols,  100, '$cols to bind_event sub after set_size' );

   $term->unbind_event_id( $id );
}

done_testing;