This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[Caffeine-Patch] Math::BigInt 1.87 take 11 (add batan2, fix batan, speedup bpi()
[perl5.git] / lib / Net / t / datasend.t
CommitLineData
f92f3fcb
GB
1#!./perl -w
2
3BEGIN {
4 package Foo;
5
6 use IO::File;
7 use Net::Cmd;
8 @ISA = qw(Net::Cmd IO::File);
9
10 sub timeout { 0 }
11
12 sub new {
13 my $fh = shift->new_tmpfile;
14 binmode($fh);
15 $fh;
16 }
17
18 sub output {
19 my $self = shift;
20 seek($self,0,0);
21 local $/ = undef;
22 scalar(<$self>);
23 }
24
25 sub response {
26 return Net::Cmd::CMD_OK;
27 }
28}
29
30(my $libnet_t = __FILE__) =~ s/datasend.t/libnet_t.pl/;
31require $libnet_t or die;
32
9714c667 33print "1..51\n";
f92f3fcb
GB
34
35sub check {
36 my $expect = pop;
37 my $cmd = Foo->new;
9714c667 38 ok($cmd->datasend, 'datasend') unless @_;
f92f3fcb 39 foreach my $line (@_) {
9714c667 40 ok($cmd->datasend($line), 'datasend');
f92f3fcb 41 }
9714c667
GB
42 ok($cmd->dataend, 'dataend');
43 is(
44 unpack("H*",$cmd->output),
45 unpack("H*",$expect)
46 );
f92f3fcb
GB
47}
48
49my $cmd;
50
51check(
52 # nothing
53
54 ".\015\012"
55);
56
57check(
58 "a",
59
60 "a\015\012.\015\012",
61);
62
63check(
64 "a\r",
65
66 "a\015\015\012.\015\012",
67);
68
69check(
70 "a\rb",
71
72 "a\015b\015\012.\015\012",
73);
74
75check(
76 "a\rb\n",
77
78 "a\015b\015\012.\015\012",
79);
80
81check(
82 "a\rb\n\n",
83
84 "a\015b\015\012\015\012.\015\012",
85);
86
87check(
88 "a\r",
89 "\nb",
90
91 "a\015\012b\015\012.\015\012",
92);
93
94check(
95 "a\r",
96 "\nb\n",
97
98 "a\015\012b\015\012.\015\012",
99);
100
101check(
102 "a\r",
103 "\nb\r\n",
104
105 "a\015\012b\015\012.\015\012",
106);
107
108check(
109 "a\r",
110 "\nb\r\n\n",
111
112 "a\015\012b\015\012\015\012.\015\012",
113);
114
115check(
116 "a\n.b\n",
117
118 "a\015\012..b\015\012.\015\012",
119);
120
121check(
122 ".a\n.b\n",
123
124 "..a\015\012..b\015\012.\015\012",
125);
126
127check(
128 ".a\n",
129 ".b\n",
130
131 "..a\015\012..b\015\012.\015\012",
132);
133
134check(
135 ".a",
136 ".b\n",
137
138 "..a.b\015\012.\015\012",
139);
140
141check(
142 "a\n.",
143
144 "a\015\012..\015\012.\015\012",
145);
146