|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2007 the original author or authors. |
|
|
|
|
* Copyright 2002-2015 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
|
@ -16,14 +16,17 @@
@@ -16,14 +16,17 @@
|
|
|
|
|
|
|
|
|
|
package org.springframework.util; |
|
|
|
|
|
|
|
|
|
import junit.framework.TestCase; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author Juergen Hoeller |
|
|
|
|
* @author Johan Gorter |
|
|
|
|
*/ |
|
|
|
|
public class PatternMatchUtilsTests extends TestCase { |
|
|
|
|
public class PatternMatchUtilsTests { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testTrivial() { |
|
|
|
|
assertEquals(false, PatternMatchUtils.simpleMatch((String) null, "")); |
|
|
|
|
assertEquals(false, PatternMatchUtils.simpleMatch("1", null)); |
|
|
|
|
@ -31,16 +34,19 @@ public class PatternMatchUtilsTests extends TestCase {
@@ -31,16 +34,19 @@ public class PatternMatchUtilsTests extends TestCase {
|
|
|
|
|
doTest("123", "123", true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testStartsWith() { |
|
|
|
|
doTest("get*", "getMe", true); |
|
|
|
|
doTest("get*", "setMe", false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testEndsWith() { |
|
|
|
|
doTest("*Test", "getMeTest", true); |
|
|
|
|
doTest("*Test", "setMe", false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testBetween() { |
|
|
|
|
doTest("*stuff*", "getMeTest", false); |
|
|
|
|
doTest("*stuff*", "getstuffTest", true); |
|
|
|
|
@ -49,6 +55,7 @@ public class PatternMatchUtilsTests extends TestCase {
@@ -49,6 +55,7 @@ public class PatternMatchUtilsTests extends TestCase {
|
|
|
|
|
doTest("*stuff*", "stuff", true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testStartsEnds() { |
|
|
|
|
doTest("on*Event", "onMyEvent", true); |
|
|
|
|
doTest("on*Event", "onEvent", true); |
|
|
|
|
@ -56,6 +63,7 @@ public class PatternMatchUtilsTests extends TestCase {
@@ -56,6 +63,7 @@ public class PatternMatchUtilsTests extends TestCase {
|
|
|
|
|
doTest("3*3", "33", true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testStartsEndsBetween() { |
|
|
|
|
doTest("12*45*78", "12345678", true); |
|
|
|
|
doTest("12*45*78", "123456789", false); |
|
|
|
|
@ -66,6 +74,7 @@ public class PatternMatchUtilsTests extends TestCase {
@@ -66,6 +74,7 @@ public class PatternMatchUtilsTests extends TestCase {
|
|
|
|
|
doTest("3*3*3", "333", true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testRidiculous() { |
|
|
|
|
doTest("*1*2*3*", "0011002001010030020201030", true); |
|
|
|
|
doTest("1*2*3*4", "10300204", false); |
|
|
|
|
@ -74,6 +83,22 @@ public class PatternMatchUtilsTests extends TestCase {
@@ -74,6 +83,22 @@ public class PatternMatchUtilsTests extends TestCase {
|
|
|
|
|
doTest("*1*2*3*", "132", false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testPatternVariants() { |
|
|
|
|
doTest("*a", "*", false); |
|
|
|
|
doTest("*a", "a", true); |
|
|
|
|
doTest("*a", "b", false); |
|
|
|
|
doTest("*a", "aa", true); |
|
|
|
|
doTest("*a", "ba", true); |
|
|
|
|
doTest("*a", "ab", false); |
|
|
|
|
doTest("**a", "*", false); |
|
|
|
|
doTest("**a", "a", true); |
|
|
|
|
doTest("**a", "b", false); |
|
|
|
|
doTest("**a", "aa", true); |
|
|
|
|
doTest("**a", "ba", true); |
|
|
|
|
doTest("**a", "ab", false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void doTest(String pattern, String str, boolean shouldMatch) { |
|
|
|
|
assertEquals(shouldMatch, PatternMatchUtils.simpleMatch(pattern, str)); |
|
|
|
|
} |
|
|
|
|
|