Permalink
Browse files

[t/spec/S32-io] Add (fudged) tests for IO::Socket.get()

git-svn-id: http://svn.pugscode.org/pugs@28916 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
carlin
carlin committed Oct 27, 2009
1 parent 818faa0 commit 096645d7ee4256733fcdc563520871ee6404ba2e
Showing with 52 additions and 1 deletion.
  1. +37 −0 S32-io/IO-Socket-INET.pl
  2. +15 −1 S32-io/IO-Socket-INET.t
View
@@ -121,6 +121,43 @@
$sock.close();
}
}
+
+ when 5 { # test number 5 - get()
+ if $server_or_client eq 'server' {
+ my $server = IO::Socket::INET.socket(PF_INET, SOCK_STREAM, TCP);
+ $server.bind($host, $port.Int);
+ $server.listen();
+ my $fd = open('t/spec/S32-io/server-ready-flag', :w);
+ $fd.close();
+ while my $client = $server.accept() {
+ # default line separator
+ $client.send("'Twas brillig, and the slithy toves\n");
+ $client.send("Did gyre and gimble in the wabe;\n");
+ # custom line separator: \r\n
+ $client.send("All mimsy were the borogoves,\r\n");
+ # another custom separator: .
+ $client.send("And the mome raths outgrabe.");
+ # separator not at the end of the sent data: !
+ $client.send("O frabjous day! Callooh! Callay!");
+ $client.close();
+ }
+ } else { # client
+ my $sock = IO::Socket::INET.new;
+ until 't/spec/S32-io/server-ready-flag' ~~ :e { sleep(1) }
+ $sock.open($host, $port.Int);
+ say $sock.get();
+ say $sock.get();
+ $sock.input-line-separator = "\r\n";
+ say $sock.get();
+ $sock.input-line-separator = '.';
+ say $sock.get();
+ $sock.input-line-separator = '!';
+ say $sock.get();
+ say $sock.get(); # will begin
+ say $sock.get(); # with a space
+ $sock.close();
+ }
+ }
}
=begin pod
View
@@ -1,7 +1,7 @@
use v6;
use Test;
-plan 11;
+plan 18;
# L<S32::IO/IO::Socket::INET>
@@ -77,6 +77,20 @@ if $*OS eq any <linux darwin> { # please add more valid OS names
is $expected[$i++], 2, 'received 2 bytes of a 3 byte unicode character';
is $expected[$i++], chr(0xbabe), "combined the bytes form {chr 0xbabe}";
is $expected[$i++], 3, '... which is 3 bytes';
+
+ #?rakudo 7 skip
+ # test 5 tests get()
+ $received = qqx{sh t/spec/S32-io/IO-Socket-INET.sh 5 $port};
+ $expected = $received.split("\n");
+ $i = 0;
+ is $expected[$i++], "'Twas brillig, and the slithy toves",
+ 'get() with default separator';
+ is $expected[$i++], 'Did gyre and gimble in the wabe;', 'default separator';
+ is $expected[$i++], 'All mimsy were the borogoves,', '\r\n separator';
+ is $expected[$i++], 'And the mome raths outgrabe', '. as a separator';
+ is $expected[$i++], 'O frabjous day', '! separator not at end of string';
+ is $expected[$i++], ' Callooh', 'Multiple separators not at end of string';
+ is $expected[$i++], ' Callay', '! separator at end of string';
}
else {
# eg Win32 shell script needs writing

0 comments on commit 096645d

Please sign in to comment.