xref: /onnv-gate/usr/src/cmd/perl/contrib/Sun/Solaris/Utils/t/gmatch.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#
2*0Sstevel@tonic-gate# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*0Sstevel@tonic-gate# Use is subject to license terms.
4*0Sstevel@tonic-gate#
5*0Sstevel@tonic-gate# CDDL HEADER START
6*0Sstevel@tonic-gate#
7*0Sstevel@tonic-gate# The contents of this file are subject to the terms of the
8*0Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
9*0Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
10*0Sstevel@tonic-gate# with the License.
11*0Sstevel@tonic-gate#
12*0Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
13*0Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
14*0Sstevel@tonic-gate# See the License for the specific language governing permissions
15*0Sstevel@tonic-gate# and limitations under the License.
16*0Sstevel@tonic-gate#
17*0Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
18*0Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
19*0Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
20*0Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
21*0Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
22*0Sstevel@tonic-gate#
23*0Sstevel@tonic-gate# CDDL HEADER END
24*0Sstevel@tonic-gate#
25*0Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"
26*0Sstevel@tonic-gate#
27*0Sstevel@tonic-gate# test script for Sun::Solaris::Utils gmatch()
28*0Sstevel@tonic-gate#
29*0Sstevel@tonic-gate
30*0Sstevel@tonic-gateuse strict;
31*0Sstevel@tonic-gate
32*0Sstevel@tonic-gateBEGIN { $| = 1; print "1..49\n"; }
33*0Sstevel@tonic-gatemy $loaded;
34*0Sstevel@tonic-gateEND {print "not ok 1\n" unless $loaded;}
35*0Sstevel@tonic-gateuse Sun::Solaris::Utils qw(gmatch);
36*0Sstevel@tonic-gate$loaded = 1;
37*0Sstevel@tonic-gateprint "ok 1\n";
38*0Sstevel@tonic-gate
39*0Sstevel@tonic-gatemy ($test);
40*0Sstevel@tonic-gate$test = 2;
41*0Sstevel@tonic-gate
42*0Sstevel@tonic-gatemy @strs = ( 'a', 'aa', 'z', 'zz', '0', '0123456789' );
43*0Sstevel@tonic-gatemy @tests = (
44*0Sstevel@tonic-gate    { pattern => 'a',       results => [ 1, 0, 0, 0, 0, 0 ] },
45*0Sstevel@tonic-gate    { pattern => '*',       results => [ 1, 1, 1, 1, 1, 1 ] },
46*0Sstevel@tonic-gate    { pattern => '?',       results => [ 1, 0, 1, 0, 1, 0 ] },
47*0Sstevel@tonic-gate    { pattern => '??',      results => [ 0, 1, 0, 1, 0, 0 ] },
48*0Sstevel@tonic-gate    { pattern => '[a-z]*',  results => [ 1, 1, 1, 1, 0, 0 ] },
49*0Sstevel@tonic-gate    { pattern => '[!a-z]*', results => [ 0, 0, 0, 0, 1, 1 ] },
50*0Sstevel@tonic-gate    { pattern => '[0-9]*',  results => [ 0, 0, 0, 0, 1, 1 ] },
51*0Sstevel@tonic-gate    { pattern => '[!0-9]*', results => [ 1, 1, 1, 1, 0, 0 ] },
52*0Sstevel@tonic-gate);
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gateforeach my $t (@tests) {
55*0Sstevel@tonic-gate	for (my $i = 0; $i < @strs; $i++) {
56*0Sstevel@tonic-gate		if (gmatch($strs[$i], $t->{pattern}) == $t->{results}[$i]) {
57*0Sstevel@tonic-gate			print("ok $test\n");
58*0Sstevel@tonic-gate		} else {
59*0Sstevel@tonic-gate			print("not ok $test\n");
60*0Sstevel@tonic-gate		}
61*0Sstevel@tonic-gate		$test++;
62*0Sstevel@tonic-gate	}
63*0Sstevel@tonic-gate}
64*0Sstevel@tonic-gate
65*0Sstevel@tonic-gateexit(0);
66