xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/t/comp/term.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!./perl
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gate# tests that aren't important enough for base.term
4*0Sstevel@tonic-gate
5*0Sstevel@tonic-gateprint "1..23\n";
6*0Sstevel@tonic-gate
7*0Sstevel@tonic-gate$x = "\\n";
8*0Sstevel@tonic-gateprint "#1\t:$x: eq " . ':\n:' . "\n";
9*0Sstevel@tonic-gateif ($x eq '\n') {print "ok 1\n";} else {print "not ok 1\n";}
10*0Sstevel@tonic-gate
11*0Sstevel@tonic-gate$x = "#2\t:$x: eq :\\n:\n";
12*0Sstevel@tonic-gateprint $x;
13*0Sstevel@tonic-gateunless (index($x,'\\\\')>0) {print "ok 2\n";} else {print "not ok 2\n";}
14*0Sstevel@tonic-gate
15*0Sstevel@tonic-gateif (length('\\\\') == 2) {print "ok 3\n";} else {print "not ok 3\n";}
16*0Sstevel@tonic-gate
17*0Sstevel@tonic-gate$one = 'a';
18*0Sstevel@tonic-gate
19*0Sstevel@tonic-gateif (length("\\n") == 2) {print "ok 4\n";} else {print "not ok 4\n";}
20*0Sstevel@tonic-gateif (length("\\\n") == 2) {print "ok 5\n";} else {print "not ok 5\n";}
21*0Sstevel@tonic-gateif (length("$one\\n") == 3) {print "ok 6\n";} else {print "not ok 6\n";}
22*0Sstevel@tonic-gateif (length("$one\\\n") == 3) {print "ok 7\n";} else {print "not ok 7\n";}
23*0Sstevel@tonic-gateif (length("\\n$one") == 3) {print "ok 8\n";} else {print "not ok 8\n";}
24*0Sstevel@tonic-gateif (length("\\\n$one") == 3) {print "ok 9\n";} else {print "not ok 9\n";}
25*0Sstevel@tonic-gateif (length("\\${one}") == 2) {print "ok 10\n";} else {print "not ok 10\n";}
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gateif ("${one}b" eq "ab") { print "ok 11\n";} else {print "not ok 11\n";}
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate@foo = (1,2,3);
30*0Sstevel@tonic-gateif ("$foo[1]b" eq "2b") { print "ok 12\n";} else {print "not ok 12\n";}
31*0Sstevel@tonic-gateif ("@foo[0..1]b" eq "1 2b") { print "ok 13\n";} else {print "not ok 13\n";}
32*0Sstevel@tonic-gate$" = '::';
33*0Sstevel@tonic-gateif ("@foo[0..1]b" eq "1::2b") { print "ok 14\n";} else {print "not ok 14\n";}
34*0Sstevel@tonic-gate
35*0Sstevel@tonic-gate# test if C<eval "{...}"> distinguishes between blocks and hashrefs
36*0Sstevel@tonic-gate
37*0Sstevel@tonic-gate$a = "{ '\\'' , 'foo' }";
38*0Sstevel@tonic-gate$a = eval $a;
39*0Sstevel@tonic-gateif (ref($a) eq 'HASH') {print "ok 15\n";} else {print "not ok 15\n";}
40*0Sstevel@tonic-gate
41*0Sstevel@tonic-gate$a = "{ '\\\\\\'abc' => 'foo' }";
42*0Sstevel@tonic-gate$a = eval $a;
43*0Sstevel@tonic-gateif (ref($a) eq 'HASH') {print "ok 16\n";} else {print "not ok 16\n";}
44*0Sstevel@tonic-gate
45*0Sstevel@tonic-gate$a = "{'a\\\n\\'b','foo'}";
46*0Sstevel@tonic-gate$a = eval $a;
47*0Sstevel@tonic-gateif (ref($a) eq 'HASH') {print "ok 17\n";} else {print "not ok 17\n";}
48*0Sstevel@tonic-gate
49*0Sstevel@tonic-gate$a = "{'\\\\\\'\\\\'=>'foo'}";
50*0Sstevel@tonic-gate$a = eval $a;
51*0Sstevel@tonic-gateif (ref($a) eq 'HASH') {print "ok 18\n";} else {print "not ok 18\n";}
52*0Sstevel@tonic-gate
53*0Sstevel@tonic-gate$a = "{q,a'b,,'foo'}";
54*0Sstevel@tonic-gate$a = eval $a;
55*0Sstevel@tonic-gateif (ref($a) eq 'HASH') {print "ok 19\n";} else {print "not ok 19\n";}
56*0Sstevel@tonic-gate
57*0Sstevel@tonic-gate$a = "{q[[']]=>'foo'}";
58*0Sstevel@tonic-gate$a = eval $a;
59*0Sstevel@tonic-gateif (ref($a) eq 'HASH') {print "ok 20\n";} else {print "not ok 20\n";}
60*0Sstevel@tonic-gate
61*0Sstevel@tonic-gate# needs disambiguation if first term is a variable
62*0Sstevel@tonic-gate$a = "+{ \$a , 'foo'}";
63*0Sstevel@tonic-gate$a = eval $a;
64*0Sstevel@tonic-gateif (ref($a) eq 'HASH') {print "ok 21\n";} else {print "not ok 21\n";}
65*0Sstevel@tonic-gate
66*0Sstevel@tonic-gate$a = "+{ \$a=>'foo'}";
67*0Sstevel@tonic-gate$a = eval $a;
68*0Sstevel@tonic-gateif (ref($a) eq 'HASH') {print "ok 22\n";} else {print "not ok 22\n";}
69*0Sstevel@tonic-gate
70*0Sstevel@tonic-gate$a = "{ 0x01 => 'foo'}->{0x01}";
71*0Sstevel@tonic-gate$a = eval $a;
72*0Sstevel@tonic-gateif ($a eq 'foo') {print "ok 23\n";} else {print "not ok 23\n";}
73