xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/t/comp/colon.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!./perl
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gate#
4*0Sstevel@tonic-gate# Ensure that syntax using colons (:) is parsed correctly.
5*0Sstevel@tonic-gate# The tests are done on the following tokens (by default):
6*0Sstevel@tonic-gate# ABC LABEL XYZZY m q qq qw qx s tr y AUTOLOAD and alarm
7*0Sstevel@tonic-gate#	-- Robin Barker <rmb@cise.npl.co.uk>
8*0Sstevel@tonic-gate#
9*0Sstevel@tonic-gate
10*0Sstevel@tonic-gateBEGIN {
11*0Sstevel@tonic-gate    chdir 't' if -d 't';
12*0Sstevel@tonic-gate    @INC = '../lib';
13*0Sstevel@tonic-gate}
14*0Sstevel@tonic-gate
15*0Sstevel@tonic-gateuse strict;
16*0Sstevel@tonic-gate
17*0Sstevel@tonic-gate$_ = '';	# to avoid undef warning on m// etc.
18*0Sstevel@tonic-gate
19*0Sstevel@tonic-gatesub ok {
20*0Sstevel@tonic-gate    my($test,$ok) = @_;
21*0Sstevel@tonic-gate    print "not " unless $ok;
22*0Sstevel@tonic-gate    print "ok $test\n";
23*0Sstevel@tonic-gate}
24*0Sstevel@tonic-gate
25*0Sstevel@tonic-gate$SIG{__WARN__} = sub { 1; }; # avoid some spurious warnings
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gateprint "1..25\n";
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gateok 1, (eval "package ABC; sub zyx {1}; 1;" and
30*0Sstevel@tonic-gate	eval "ABC::zyx" and
31*0Sstevel@tonic-gate	not eval "ABC:: eq ABC||" and
32*0Sstevel@tonic-gate	not eval "ABC::: >= 0");
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gateok 2, (eval "package LABEL; sub zyx {1}; 1;" and
35*0Sstevel@tonic-gate	eval "LABEL::zyx" and
36*0Sstevel@tonic-gate	not eval "LABEL:: eq LABEL||" and
37*0Sstevel@tonic-gate	not eval "LABEL::: >= 0");
38*0Sstevel@tonic-gate
39*0Sstevel@tonic-gateok 3, (eval "package XYZZY; sub zyx {1}; 1;" and
40*0Sstevel@tonic-gate	eval "XYZZY::zyx" and
41*0Sstevel@tonic-gate	not eval "XYZZY:: eq XYZZY||" and
42*0Sstevel@tonic-gate	not eval "XYZZY::: >= 0");
43*0Sstevel@tonic-gate
44*0Sstevel@tonic-gateok 4, (eval "package m; sub zyx {1}; 1;" and
45*0Sstevel@tonic-gate	not eval "m::zyx" and
46*0Sstevel@tonic-gate	eval "m:: eq m||" and
47*0Sstevel@tonic-gate	not eval "m::: >= 0");
48*0Sstevel@tonic-gate
49*0Sstevel@tonic-gateok 5, (eval "package q; sub zyx {1}; 1;" and
50*0Sstevel@tonic-gate	not eval "q::zyx" and
51*0Sstevel@tonic-gate	eval "q:: eq q||" and
52*0Sstevel@tonic-gate	not eval "q::: >= 0");
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gateok 6, (eval "package qq; sub zyx {1}; 1;" and
55*0Sstevel@tonic-gate	not eval "qq::zyx" and
56*0Sstevel@tonic-gate	eval "qq:: eq qq||" and
57*0Sstevel@tonic-gate	not eval "qq::: >= 0");
58*0Sstevel@tonic-gate
59*0Sstevel@tonic-gateok 7, (eval "package qw; sub zyx {1}; 1;" and
60*0Sstevel@tonic-gate	not eval "qw::zyx" and
61*0Sstevel@tonic-gate	eval "qw:: eq qw||" and
62*0Sstevel@tonic-gate	not eval "qw::: >= 0");
63*0Sstevel@tonic-gate
64*0Sstevel@tonic-gateok 8, (eval "package qx; sub zyx {1}; 1;" and
65*0Sstevel@tonic-gate	not eval "qx::zyx" and
66*0Sstevel@tonic-gate	eval "qx:: eq qx||" and
67*0Sstevel@tonic-gate	not eval "qx::: >= 0");
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gateok 9, (eval "package s; sub zyx {1}; 1;" and
70*0Sstevel@tonic-gate	not eval "s::zyx" and
71*0Sstevel@tonic-gate	not eval "s:: eq s||" and
72*0Sstevel@tonic-gate	eval "s::: >= 0");
73*0Sstevel@tonic-gate
74*0Sstevel@tonic-gateok 10, (eval "package tr; sub zyx {1}; 1;" and
75*0Sstevel@tonic-gate	not eval "tr::zyx" and
76*0Sstevel@tonic-gate	not eval "tr:: eq tr||" and
77*0Sstevel@tonic-gate	eval "tr::: >= 0");
78*0Sstevel@tonic-gate
79*0Sstevel@tonic-gateok 11, (eval "package y; sub zyx {1}; 1;" and
80*0Sstevel@tonic-gate	not eval "y::zyx" and
81*0Sstevel@tonic-gate	not eval "y:: eq y||" and
82*0Sstevel@tonic-gate	eval "y::: >= 0");
83*0Sstevel@tonic-gate
84*0Sstevel@tonic-gateok 12, (eval "ABC:1" and
85*0Sstevel@tonic-gate	not eval "ABC:echo: eq ABC|echo|" and
86*0Sstevel@tonic-gate	not eval "ABC:echo:ohce: >= 0");
87*0Sstevel@tonic-gate
88*0Sstevel@tonic-gateok 13, (eval "LABEL:1" and
89*0Sstevel@tonic-gate	not eval "LABEL:echo: eq LABEL|echo|" and
90*0Sstevel@tonic-gate	not eval "LABEL:echo:ohce: >= 0");
91*0Sstevel@tonic-gate
92*0Sstevel@tonic-gateok 14, (eval "XYZZY:1" and
93*0Sstevel@tonic-gate	not eval "XYZZY:echo: eq XYZZY|echo|" and
94*0Sstevel@tonic-gate	not eval "XYZZY:echo:ohce: >= 0");
95*0Sstevel@tonic-gate
96*0Sstevel@tonic-gateok 15, (not eval "m:1" and
97*0Sstevel@tonic-gate	eval "m:echo: eq m|echo|" and
98*0Sstevel@tonic-gate	not eval "m:echo:ohce: >= 0");
99*0Sstevel@tonic-gate
100*0Sstevel@tonic-gateok 16, (not eval "q:1" and
101*0Sstevel@tonic-gate	eval "q:echo: eq q|echo|" and
102*0Sstevel@tonic-gate	not eval "q:echo:ohce: >= 0");
103*0Sstevel@tonic-gate
104*0Sstevel@tonic-gateok 17, (not eval "qq:1" and
105*0Sstevel@tonic-gate	eval "qq:echo: eq qq|echo|" and
106*0Sstevel@tonic-gate	not eval "qq:echo:ohce: >= 0");
107*0Sstevel@tonic-gate
108*0Sstevel@tonic-gateok 18, (not eval "qw:1" and
109*0Sstevel@tonic-gate	eval "qw:echo: eq qw|echo|" and
110*0Sstevel@tonic-gate	not eval "qw:echo:ohce: >= 0");
111*0Sstevel@tonic-gate
112*0Sstevel@tonic-gateok 19, (not eval "qx:1" and
113*0Sstevel@tonic-gate	eval "qx:echo 1: eq qx|echo 1|" and	# echo without args may warn
114*0Sstevel@tonic-gate	not eval "qx:echo:ohce: >= 0");
115*0Sstevel@tonic-gate
116*0Sstevel@tonic-gateok 20, (not eval "s:1" and
117*0Sstevel@tonic-gate	not eval "s:echo: eq s|echo|" and
118*0Sstevel@tonic-gate	eval "s:echo:ohce: >= 0");
119*0Sstevel@tonic-gate
120*0Sstevel@tonic-gateok 21, (not eval "tr:1" and
121*0Sstevel@tonic-gate	not eval "tr:echo: eq tr|echo|" and
122*0Sstevel@tonic-gate	eval "tr:echo:ohce: >= 0");
123*0Sstevel@tonic-gate
124*0Sstevel@tonic-gateok 22, (not eval "y:1" and
125*0Sstevel@tonic-gate	not eval "y:echo: eq y|echo|" and
126*0Sstevel@tonic-gate	eval "y:echo:ohce: >= 0");
127*0Sstevel@tonic-gate
128*0Sstevel@tonic-gateok 23, (eval "AUTOLOAD:1" and
129*0Sstevel@tonic-gate	not eval "AUTOLOAD:echo: eq AUTOLOAD|echo|" and
130*0Sstevel@tonic-gate	not eval "AUTOLOAD:echo:ohce: >= 0");
131*0Sstevel@tonic-gate
132*0Sstevel@tonic-gateok 24, (eval "and:1" and
133*0Sstevel@tonic-gate	not eval "and:echo: eq and|echo|" and
134*0Sstevel@tonic-gate	not eval "and:echo:ohce: >= 0");
135*0Sstevel@tonic-gate
136*0Sstevel@tonic-gateok 25, (eval "alarm:1" and
137*0Sstevel@tonic-gate	not eval "alarm:echo: eq alarm|echo|" and
138*0Sstevel@tonic-gate	not eval "alarm:echo:ohce: >= 0");
139