| /* |
| * Copyright (c) 2017 Cisco and/or its affiliates. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at: |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package io.fd.maintainer.plugin.parser; |
| |
| import org.junit.Assert; |
| import org.junit.Test; |
| |
| public class ComponentPathTest { |
| |
| @Test |
| public void testMatchFull() { |
| final ComponentPath base = new ComponentPath("foo/bar"); |
| Assert.assertEquals(ComponentPath.MatchLevel.FULL, base.matchAgainst("foo/bar")); |
| } |
| |
| @Test |
| public void testMatchNone() { |
| final ComponentPath base = new ComponentPath("foo/bar"); |
| Assert.assertEquals(ComponentPath.MatchLevel.NONE, base.matchAgainst("foo/bar2")); |
| } |
| |
| @Test |
| public void testMatchWildcardOnly() { |
| final ComponentPath base = new ComponentPath("foo/*"); |
| Assert.assertEquals(ComponentPath.MatchLevel.WILDCARD_ONLY, base.matchAgainst("foo/bar")); |
| } |
| |
| @Test |
| public void testMatchWildcardOnlyLower() { |
| final ComponentPath base = new ComponentPath("foo/*"); |
| Assert.assertEquals(ComponentPath.MatchLevel.WILDCARD_ONLY, base.matchAgainst("foo/de/re/li/bar")); |
| } |
| |
| @Test |
| public void testMatchWildcardOnlyMixed() { |
| final ComponentPath base = new ComponentPath("foo/*"); |
| Assert.assertEquals(ComponentPath.MatchLevel.WILDCARD_ONLY, base.matchAgainst("foo/de/re/li/bar.mk")); |
| } |
| |
| @Test |
| public void testMatchWildcardWithExtension() { |
| final ComponentPath base = new ComponentPath("foo/*.mk"); |
| Assert.assertEquals(ComponentPath.MatchLevel.WILDCARD_WITH_EXTENSION, base.matchAgainst("foo/bar2.mk")); |
| } |
| |
| @Test |
| public void testMatchWildcardWithExtensionLower() { |
| final ComponentPath base = new ComponentPath("foo/*.mk"); |
| Assert.assertEquals(ComponentPath.MatchLevel.WILDCARD_WITH_EXTENSION, base.matchAgainst("foo/de/bar2.mk")); |
| } |
| |
| @Test |
| public void testMatchPartial() { |
| final ComponentPath base = new ComponentPath("src/vlib/"); |
| Assert.assertEquals(ComponentPath.MatchLevel.PARTIAL, base.matchAgainst("src/vlib/vlib-new.file")); |
| } |
| |
| @Test |
| public void testMatchNoneWildcardExtension() { |
| final ComponentPath base = new ComponentPath("src/*.am"); |
| Assert.assertEquals(ComponentPath.MatchLevel.NONE, base.matchAgainst("src/vlib/vlib-new.file")); |
| } |
| |
| @Test |
| public void testMatchRootWildcard() { |
| final ComponentPath base = new ComponentPath("*"); |
| Assert.assertEquals(ComponentPath.MatchLevel.WILDCARD_ONLY, base.matchAgainst("src/vlib/vlib-new.file")); |
| } |
| |
| @Test |
| public void testMatchRootWildcardSubdir() { |
| final ComponentPath base = new ComponentPath("*/"); |
| Assert.assertEquals(ComponentPath.MatchLevel.WILDCARD_ONLY, base.matchAgainst("lisp/new-file")); |
| } |
| } |