Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 49990 invoked from network); 22 Sep 2004 04:12:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 22 Sep 2004 04:12:24 -0000 Received: (qmail 52112 invoked by uid 500); 22 Sep 2004 04:12:23 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 51894 invoked by uid 500); 22 Sep 2004 04:12:20 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 51881 invoked by uid 500); 22 Sep 2004 04:12:19 -0000 Received: (qmail 51876 invoked by uid 99); 22 Sep 2004 04:12:19 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Tue, 21 Sep 2004 21:12:19 -0700 Received: (qmail 49966 invoked by uid 1360); 22 Sep 2004 04:12:18 -0000 Date: 22 Sep 2004 04:12:18 -0000 Message-ID: <20040922041218.49965.qmail@minotaur.apache.org> From: bayard@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/io/src/test/org/apache/commons/io/find WildcardUtilsTest.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N bayard 2004/09/21 21:12:18 Modified: io/src/java/org/apache/commons/io/find WildcardUtils.java io/src/test/org/apache/commons/io/find WildcardUtilsTest.java Log: More tests for WildcardUtils.match and a new implementation of the match method. Mostly the same as Bugzilla #31115, though the old tests were kept and they showed a bug. Submitted by: Jason Anderson Revision Changes Path 1.2 +50 -27 jakarta-commons/io/src/java/org/apache/commons/io/find/WildcardUtils.java Index: WildcardUtils.java =================================================================== RCS file: /home/cvs/jakarta-commons/io/src/java/org/apache/commons/io/find/WildcardUtils.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- WildcardUtils.java 17 Sep 2004 00:14:48 -0000 1.1 +++ WildcardUtils.java 22 Sep 2004 04:12:18 -0000 1.2 @@ -28,42 +28,65 @@ * matches to a specified wildcard. */ public static boolean match(String text, String wildcard) { - // split wildcard on ? and * - // for each element of the array, find a matching block in text - // earliest matching block counts String[] wcs = splitOnTokens(wildcard); + int textIdx = 0; - for(int i=0; i text.length()) { + return false; + } + + // didnt match all text chars, only ok if any chars set + if (textIdx < text.length() && !anyChars) { + return false; + } + return true; } 1.2 +33 -0 jakarta-commons/io/src/test/org/apache/commons/io/find/WildcardUtilsTest.java Index: WildcardUtilsTest.java =================================================================== RCS file: /home/cvs/jakarta-commons/io/src/test/org/apache/commons/io/find/WildcardUtilsTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- WildcardUtilsTest.java 17 Sep 2004 00:14:49 -0000 1.1 +++ WildcardUtilsTest.java 22 Sep 2004 04:12:18 -0000 1.2 @@ -62,4 +62,37 @@ } } + private void assertMatch(String text, String wildcard, boolean expected) { + assertEquals(text + " " + wildcard, expected, WildcardUtils.match(text, wildcard)); + } + + // A separate set of tests, added to this batch + public void testMatch2() { + assertMatch("log.txt", "log.txt", true); + assertMatch("log.txt1", "log.txt", false); + + assertMatch("log.txt", "log.txt*", true); + assertMatch("log.txt", "log.txt*1", false); + assertMatch("log.txt", "*log.txt*", true); + + assertMatch("log.txt", "*.txt", true); + assertMatch("txt.log", "*.txt", false); + assertMatch("config.ini", "*.ini", true); + + assertMatch("config.txt.bak", "con*.txt", false); + + assertMatch("log.txt9", "*.txt?", true); + assertMatch("log.txt", "*.txt?", false); + + assertMatch("progtestcase.java~5~", "*test*.java~*~", true); + assertMatch("progtestcase.java;5~", "*test*.java~*~", false); + assertMatch("progtestcase.java~5", "*test*.java~*~", false); + + assertMatch("log.txt", "log.*", true); + + assertMatch("log.txt", "log?*", true); + + assertMatch("log.txt12", "log.txt??", true); + } + } --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org