/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
*/
package org.opensolaris.opengrok.index;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.LinkedHashSet;
import org.junit.Test;
/**
* @author Trond Norbye
*/
public class IgnoredNamesTest {
/**
* Test ignore patterns and names.
*/
@SuppressWarnings("static-method")
@Test
public void testIgnoredPatterns() {
IgnoredNames instance = new IgnoredNames();
LinkedHashSet<String> names = instance.getItems();
assertNotNull(names);
/* self-test */
for (String name : names) {
assertTrue(instance.match(name));
}
/* Make sure common paths are not ignored by default. */
assertFalse(instance.match("usr/src/foo/bin"));
assertFalse(instance.match("usr/src/foo/bin/bar.ksh"));
assertFalse(instance.match("usr/src/bar/obj"));
assertFalse(instance.match("usr/src/bar/obj/foo.ksh"));
assertFalse(instance.match("usr/src/foo/bar/usr.lib/main.c"));
assertFalse(instance.match("usr/src/foo/bar/usr.lib"));
/* cumulative test */
names = new LinkedHashSet<String>();
names.add("*.o");
instance.setItems(names);
names = instance.getItems();
assertEquals(1, names.size());
assertTrue(instance.match("foo.o"));
assertFalse(instance.match("foo"));
assertTrue(instance.match(".o"));
assertFalse(instance.match("foo.oo"));
instance.add("Makefile");
names = instance.getItems();
assertEquals(2, names.size());
assertTrue(instance.match(new File("Makefile")));
assertFalse(instance.match("main.c"));
instance.add("o*o?.a?c*");
assertTrue(instance.match("opengrok.abc"));
assertTrue(instance.match("opengrok.abcd"));
assertFalse(instance.match("opengrok.ac"));
assertFalse(instance.match("grok.abcd"));
instance.clear();
names = instance.getItems();
assertEquals(0, names.size());
}
}