Permalink
Browse files

add iostream test

  • Loading branch information...
typester committed Dec 5, 2008
1 parent 077d8c8 commit 698ca05d831bfafa269a283a15833345a104a2e4
Showing with 43 additions and 0 deletions.
  1. +43 −0 t/02_iostream.t
View
@@ -0,0 +1,43 @@
+use Test::Base;
+
+plan 'no_plan';
+
+use_ok('Kamaitachi::IOStream');
+
+my $stub_socket = bless {};
+my $io = Kamaitachi::IOStream->new( socket => $stub_socket );
+
+isa_ok($io, 'Kamaitachi::IOStream');
+
+my $str1 = join '', 'A'..'Z';
+my $str2 = join '', 'a'..'z';
+
+$io->push($str1);
+$io->push($str2);
+
+is($io->buffer, $str1 . $str2, 'buffer ok');
+is($io->buffer_length, bytes::length($str1 . $str2), 'buffer length ok');
+
+is(${ $io->read(1) }, 'A', 'read 1byte ok');
+is(${ $io->read(2) }, 'BC', 'read 2bytes ok');
+
+is($io->cursor, 3, 'cursor ok');
+
+is($io->spin, 'ABC', 'spin ok');
+
+is($io->cursor, 0, 'cursor ok after spin');
+is($io->buffer_length, bytes::length($str1 . $str2) - 3, 'buffer length ok after spin');
+
+is(${ $io->read(3) }, 'DEF', 'read ok');
+$io->reset;
+is(${ $io->read(3) }, 'DEF', 'read again ok');
+$io->reset;
+
+ok( !$io->read( $io->buffer_length + 1 ), 'return false if read larger data than buffer ok');
+is( $io->cursor, 0, 'cursor still 0 ok');
+
+$io->clear;
+is( $io->cursor, 0, 'cursor should be 0 after clear');
+is( $io->buffer, '', q[buffer should be '' after clear]);
+is( $io->buffer_length, 0, 'buffer_length should be 0 after clear');
+

0 comments on commit 698ca05

Please sign in to comment.