Package org.lilyproject.indexer.model.indexerconf

Examples of org.lilyproject.indexer.model.indexerconf.WildcardPattern


import static org.junit.Assert.assertTrue;

public class WildcardPatternTest {
    @Test
    public void testStartsWith() throws Exception {
        WildcardPattern pattern = new WildcardPattern("foo*");
        Pair<Boolean, String> result = pattern.match("foobar");
        assertTrue(result.getV1());
        assertEquals("bar", result.getV2());

        result = pattern.match("fobar");
        assertFalse(result.getV1());
        assertNull(result.getV2());

        result = pattern.match("foo");
        assertTrue(result.getV1());
        assertEquals("", result.getV2());
    }
View Full Code Here


        assertEquals("", result.getV2());
    }

    @Test
    public void testEndsWith() throws Exception {
        WildcardPattern pattern = new WildcardPattern("*bar");
        Pair<Boolean, String> result = pattern.match("foobar");
        assertTrue(result.getV1());
        assertEquals("foo", result.getV2());

        result = pattern.match("fooba");
        assertFalse(result.getV1());
        assertNull(result.getV2());

        result = pattern.match("bar");
        assertTrue(result.getV1());
        assertEquals("", result.getV2());
    }
View Full Code Here

        assertEquals("", result.getV2());
    }

    @Test
    public void testEquals() throws Exception {
        WildcardPattern pattern = new WildcardPattern("foobar");
        Pair<Boolean, String> result = pattern.match("foobar");
        assertTrue(result.getV1());
        assertNull(result.getV2());

        // A star at any other position than end or start is not recognized as a wildcard
        pattern = new WildcardPattern("foo*bar");
        result = pattern.match("foo*bar");
        assertTrue(result.getV1());
        assertNull(result.getV2());

        result = pattern.match("foo1bar");
        assertFalse(result.getV1());
    }
View Full Code Here

    }

    @Test
    public void testSpecial() throws Exception {
        // A star by itself is not a wildcard
        WildcardPattern pattern = new WildcardPattern("*");
        Pair<Boolean, String> result = pattern.match("foo");
        assertTrue(result.getV1());
        assertEquals("foo", result.getV2());

        result = pattern.match("");
        assertTrue(result.getV1());
        assertEquals("", result.getV2());

        // first occurrence of star takes precedence
        pattern = new WildcardPattern("*foo*");
        result = pattern.match("barfoo*");
        assertTrue(result.getV1());
        assertEquals("bar", result.getV2());

        result = pattern.match("barfoobar");
        assertFalse(result.getV1());
        assertNull(result.getV2());
    }
View Full Code Here

TOP

Related Classes of org.lilyproject.indexer.model.indexerconf.WildcardPattern

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.