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