xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/t/op/push.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!./perl
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gate# $RCSfile: push.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:13 $
4*0Sstevel@tonic-gate
5*0Sstevel@tonic-gate@tests = split(/\n/, <<EOF);
6*0Sstevel@tonic-gate0 3,			0 1 2,		3 4 5 6 7
7*0Sstevel@tonic-gate0 0 a b c,		,		a b c 0 1 2 3 4 5 6 7
8*0Sstevel@tonic-gate8 0 a b c,		,		0 1 2 3 4 5 6 7 a b c
9*0Sstevel@tonic-gate7 0 6.5,		,		0 1 2 3 4 5 6 6.5 7
10*0Sstevel@tonic-gate1 0 a b c d e f g h i j,,		0 a b c d e f g h i j 1 2 3 4 5 6 7
11*0Sstevel@tonic-gate0 1 a,			0,		a 1 2 3 4 5 6 7
12*0Sstevel@tonic-gate1 6 x y z,		1 2 3 4 5 6,	0 x y z 7
13*0Sstevel@tonic-gate0 7 x y z,		0 1 2 3 4 5 6,	x y z 7
14*0Sstevel@tonic-gate1 7 x y z,		1 2 3 4 5 6 7,	0 x y z
15*0Sstevel@tonic-gate4,			4 5 6 7,	0 1 2 3
16*0Sstevel@tonic-gate-4,			4 5 6 7,	0 1 2 3
17*0Sstevel@tonic-gateEOF
18*0Sstevel@tonic-gate
19*0Sstevel@tonic-gateprint "1..", 4 + @tests, "\n";
20*0Sstevel@tonic-gatedie "blech" unless @tests;
21*0Sstevel@tonic-gate
22*0Sstevel@tonic-gate@x = (1,2,3);
23*0Sstevel@tonic-gatepush(@x,@x);
24*0Sstevel@tonic-gateif (join(':',@x) eq '1:2:3:1:2:3') {print "ok 1\n";} else {print "not ok 1\n";}
25*0Sstevel@tonic-gatepush(@x,4);
26*0Sstevel@tonic-gateif (join(':',@x) eq '1:2:3:1:2:3:4') {print "ok 2\n";} else {print "not ok 2\n";}
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gate# test for push/pop intuiting @ on array
29*0Sstevel@tonic-gatepush(x,3);
30*0Sstevel@tonic-gateif (join(':',@x) eq '1:2:3:1:2:3:4:3') {print "ok 3\n";} else {print "not ok 3\n";}
31*0Sstevel@tonic-gatepop(x);
32*0Sstevel@tonic-gateif (join(':',@x) eq '1:2:3:1:2:3:4') {print "ok 4\n";} else {print "not ok 4\n";}
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gate$test = 5;
35*0Sstevel@tonic-gateforeach $line (@tests) {
36*0Sstevel@tonic-gate    ($list,$get,$leave) = split(/,\t*/,$line);
37*0Sstevel@tonic-gate    ($pos, $len, @list) = split(' ',$list);
38*0Sstevel@tonic-gate    @get = split(' ',$get);
39*0Sstevel@tonic-gate    @leave = split(' ',$leave);
40*0Sstevel@tonic-gate    @x = (0,1,2,3,4,5,6,7);
41*0Sstevel@tonic-gate    if (defined $len) {
42*0Sstevel@tonic-gate	@got = splice(@x, $pos, $len, @list);
43*0Sstevel@tonic-gate    }
44*0Sstevel@tonic-gate    else {
45*0Sstevel@tonic-gate	@got = splice(@x, $pos);
46*0Sstevel@tonic-gate    }
47*0Sstevel@tonic-gate    if (join(':',@got) eq join(':',@get) &&
48*0Sstevel@tonic-gate	join(':',@x) eq join(':',@leave)) {
49*0Sstevel@tonic-gate	print "ok ",$test++,"\n";
50*0Sstevel@tonic-gate    }
51*0Sstevel@tonic-gate    else {
52*0Sstevel@tonic-gate	print "not ok ",$test++," got: @got == @get left: @x == @leave\n";
53*0Sstevel@tonic-gate    }
54*0Sstevel@tonic-gate}
55*0Sstevel@tonic-gate
56*0Sstevel@tonic-gate1;  # this file is require'd by lib/tie-stdpush.t
57