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