mirror of https://github.com/alibaba/arthas.git
unit test & comments
parent
1f469f6020
commit
700c0cb441
@ -0,0 +1,20 @@
|
||||
package com.taobao.arthas.core.util.matcher;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author earayu
|
||||
*/
|
||||
public class EqualsMatcherTest {
|
||||
|
||||
@Test
|
||||
public void testMatching(){
|
||||
Assert.assertTrue(new EqualsMatcher<String>(null).matching(null));
|
||||
Assert.assertTrue(new EqualsMatcher<String>("").matching(""));
|
||||
Assert.assertTrue(new EqualsMatcher<String>("foobar").matching("foobar"));
|
||||
Assert.assertFalse(new EqualsMatcher<String>("").matching(null));
|
||||
Assert.assertFalse(new EqualsMatcher<String>("abc").matching("def"));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.taobao.arthas.core.util.matcher;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author earayu
|
||||
*/
|
||||
public class FalseMatcherTest {
|
||||
|
||||
@Test
|
||||
public void testMatching(){
|
||||
Assert.assertFalse(new FalseMatcher<String>().matching(null));
|
||||
Assert.assertFalse(new FalseMatcher<Integer>().matching(1));
|
||||
Assert.assertFalse(new FalseMatcher<String>().matching(""));
|
||||
Assert.assertFalse(new FalseMatcher<String>().matching("foobar"));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package com.taobao.arthas.core.util.matcher;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author earayu
|
||||
*/
|
||||
public class RegexMatcherTest {
|
||||
|
||||
@Test
|
||||
public void testMatchingWithNullInputs(){
|
||||
Assert.assertFalse(new RegexMatcher(null).matching(null));
|
||||
Assert.assertFalse(new RegexMatcher(null).matching("foobar"));
|
||||
Assert.assertFalse(new RegexMatcher("foobar").matching(null));
|
||||
Assert.assertTrue(new RegexMatcher("foobar").matching("foobar"));
|
||||
}
|
||||
|
||||
/**
|
||||
* test regux with . | * + ? \s \S \w \W and so on...
|
||||
*/
|
||||
@Test
|
||||
public void testMatchingWithRegularGrammar(){
|
||||
Assert.assertTrue(new RegexMatcher("foo?").matching("fo"));
|
||||
Assert.assertTrue(new RegexMatcher("foo?").matching("foo"));
|
||||
Assert.assertTrue(new RegexMatcher("foo.").matching("fooo"));
|
||||
Assert.assertTrue(new RegexMatcher("foo*").matching("fooooo"));
|
||||
Assert.assertTrue(new RegexMatcher("foo.*").matching("foobarbarbar"));
|
||||
Assert.assertFalse(new RegexMatcher("foo+").matching("fo"));
|
||||
Assert.assertTrue(new RegexMatcher("foo+").matching("fooooo"));
|
||||
|
||||
Assert.assertTrue(new RegexMatcher("foo\\s").matching("foo "));
|
||||
Assert.assertFalse(new RegexMatcher("foo\\S").matching("foo "));
|
||||
Assert.assertTrue(new RegexMatcher("foo\\w").matching("fooo"));
|
||||
Assert.assertTrue(new RegexMatcher("foo\\W").matching("foo "));
|
||||
Assert.assertFalse(new RegexMatcher("foo\\W").matching("fooo"));
|
||||
|
||||
|
||||
Assert.assertTrue(new RegexMatcher("foo[1234]").matching("foo1"));
|
||||
Assert.assertFalse(new RegexMatcher("foo[1234]").matching("foo5"));
|
||||
Assert.assertTrue(new RegexMatcher("foo\\\\").matching("foo\\"));
|
||||
Assert.assertTrue(new RegexMatcher("foo\\d").matching("foo5"));
|
||||
Assert.assertTrue(new RegexMatcher("fo{1,3}").matching("fo"));
|
||||
Assert.assertFalse(new RegexMatcher("fo{1,3}").matching("foooo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchingComplexRegex(){
|
||||
String ipAddressPattern = "((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)";
|
||||
Assert.assertTrue(new RegexMatcher(ipAddressPattern).matching("1.1.1.1"));
|
||||
Assert.assertFalse(new RegexMatcher(ipAddressPattern).matching("255.256.255.0"));
|
||||
Assert.assertFalse(new RegexMatcher(ipAddressPattern).matching("1.1.1"));
|
||||
|
||||
Assert.assertTrue(new RegexMatcher("^foobar$").matching("foobar"));
|
||||
Assert.assertFalse(new RegexMatcher("^foobar$").matching("\nfoobar"));
|
||||
Assert.assertFalse(new RegexMatcher("^foobar$").matching("foobar\n"));
|
||||
|
||||
String emailAddressPattern = "[a-z\\d]+(\\.[a-z\\d]+)*@([\\da-z](-[\\da-z])?)+(\\.{1,2}[a-z]+)+";
|
||||
Assert.assertTrue(new RegexMatcher(emailAddressPattern).matching("foo@bar.com"));
|
||||
Assert.assertFalse(new RegexMatcher(emailAddressPattern).matching("asdfghjkl"));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.taobao.arthas.core.util.matcher;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author earayu
|
||||
*/
|
||||
public class TrueMatcherTest {
|
||||
|
||||
@Test
|
||||
public void testMatching(){
|
||||
Assert.assertTrue(new TrueMatcher<String>().matching(null));
|
||||
Assert.assertTrue(new TrueMatcher<Integer>().matching(1));
|
||||
Assert.assertTrue(new TrueMatcher<String>().matching(""));
|
||||
Assert.assertTrue(new TrueMatcher<String>().matching("foobar"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue