xref: /openbsd-src/gnu/usr.bin/perl/t/comp/term.t (revision e2e5c5d36e4398ba94879f0a31b0307421edcfdb)
14a4f25f9Sdownsj#!./perl
24a4f25f9Sdownsj
34a4f25f9Sdownsj# tests that aren't important enough for base.term
44a4f25f9Sdownsj
5*e2e5c5d3Smillertprint "1..23\n";
64a4f25f9Sdownsj
74a4f25f9Sdownsj$x = "\\n";
84a4f25f9Sdownsjprint "#1\t:$x: eq " . ':\n:' . "\n";
94a4f25f9Sdownsjif ($x eq '\n') {print "ok 1\n";} else {print "not ok 1\n";}
104a4f25f9Sdownsj
114a4f25f9Sdownsj$x = "#2\t:$x: eq :\\n:\n";
124a4f25f9Sdownsjprint $x;
134a4f25f9Sdownsjunless (index($x,'\\\\')>0) {print "ok 2\n";} else {print "not ok 2\n";}
144a4f25f9Sdownsj
154a4f25f9Sdownsjif (length('\\\\') == 2) {print "ok 3\n";} else {print "not ok 3\n";}
164a4f25f9Sdownsj
174a4f25f9Sdownsj$one = 'a';
184a4f25f9Sdownsj
194a4f25f9Sdownsjif (length("\\n") == 2) {print "ok 4\n";} else {print "not ok 4\n";}
204a4f25f9Sdownsjif (length("\\\n") == 2) {print "ok 5\n";} else {print "not ok 5\n";}
214a4f25f9Sdownsjif (length("$one\\n") == 3) {print "ok 6\n";} else {print "not ok 6\n";}
224a4f25f9Sdownsjif (length("$one\\\n") == 3) {print "ok 7\n";} else {print "not ok 7\n";}
234a4f25f9Sdownsjif (length("\\n$one") == 3) {print "ok 8\n";} else {print "not ok 8\n";}
244a4f25f9Sdownsjif (length("\\\n$one") == 3) {print "ok 9\n";} else {print "not ok 9\n";}
254a4f25f9Sdownsjif (length("\\${one}") == 2) {print "ok 10\n";} else {print "not ok 10\n";}
264a4f25f9Sdownsj
274a4f25f9Sdownsjif ("${one}b" eq "ab") { print "ok 11\n";} else {print "not ok 11\n";}
284a4f25f9Sdownsj
294a4f25f9Sdownsj@foo = (1,2,3);
304a4f25f9Sdownsjif ("$foo[1]b" eq "2b") { print "ok 12\n";} else {print "not ok 12\n";}
314a4f25f9Sdownsjif ("@foo[0..1]b" eq "1 2b") { print "ok 13\n";} else {print "not ok 13\n";}
324a4f25f9Sdownsj$" = '::';
334a4f25f9Sdownsjif ("@foo[0..1]b" eq "1::2b") { print "ok 14\n";} else {print "not ok 14\n";}
34ba47ec9dSmillert
35ba47ec9dSmillert# test if C<eval "{...}"> distinguishes between blocks and hashrefs
36ba47ec9dSmillert
37ba47ec9dSmillert$a = "{ '\\'' , 'foo' }";
38ba47ec9dSmillert$a = eval $a;
39ba47ec9dSmillertif (ref($a) eq 'HASH') {print "ok 15\n";} else {print "not ok 15\n";}
40ba47ec9dSmillert
41ba47ec9dSmillert$a = "{ '\\\\\\'abc' => 'foo' }";
42ba47ec9dSmillert$a = eval $a;
43ba47ec9dSmillertif (ref($a) eq 'HASH') {print "ok 16\n";} else {print "not ok 16\n";}
44ba47ec9dSmillert
45ba47ec9dSmillert$a = "{'a\\\n\\'b','foo'}";
46ba47ec9dSmillert$a = eval $a;
47ba47ec9dSmillertif (ref($a) eq 'HASH') {print "ok 17\n";} else {print "not ok 17\n";}
48ba47ec9dSmillert
49ba47ec9dSmillert$a = "{'\\\\\\'\\\\'=>'foo'}";
50ba47ec9dSmillert$a = eval $a;
51ba47ec9dSmillertif (ref($a) eq 'HASH') {print "ok 18\n";} else {print "not ok 18\n";}
52ba47ec9dSmillert
53ba47ec9dSmillert$a = "{q,a'b,,'foo'}";
54ba47ec9dSmillert$a = eval $a;
55ba47ec9dSmillertif (ref($a) eq 'HASH') {print "ok 19\n";} else {print "not ok 19\n";}
56ba47ec9dSmillert
57ba47ec9dSmillert$a = "{q[[']]=>'foo'}";
58ba47ec9dSmillert$a = eval $a;
59ba47ec9dSmillertif (ref($a) eq 'HASH') {print "ok 20\n";} else {print "not ok 20\n";}
60ba47ec9dSmillert
61ba47ec9dSmillert# needs disambiguation if first term is a variable
62ba47ec9dSmillert$a = "+{ \$a , 'foo'}";
63ba47ec9dSmillert$a = eval $a;
64ba47ec9dSmillertif (ref($a) eq 'HASH') {print "ok 21\n";} else {print "not ok 21\n";}
65ba47ec9dSmillert
66ba47ec9dSmillert$a = "+{ \$a=>'foo'}";
67ba47ec9dSmillert$a = eval $a;
68ba47ec9dSmillertif (ref($a) eq 'HASH') {print "ok 22\n";} else {print "not ok 22\n";}
69*e2e5c5d3Smillert
70*e2e5c5d3Smillert$a = "{ 0x01 => 'foo'}->{0x01}";
71*e2e5c5d3Smillert$a = eval $a;
72*e2e5c5d3Smillertif ($a eq 'foo') {print "ok 23\n";} else {print "not ok 23\n";}
73