/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 org.apache.sling.api.resource.path;

import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class PathTest {

    @Test public void testRootMatching() {
        final Path path = new Path("/");

        assertTrue(path.matches("/"));
        assertTrue(path.matches("/foo"));
        assertTrue(path.matches("/foo/bar"));
    }

    @Test public void testPathMatching() {
        final Path path = new Path("/content");

        assertFalse(path.matches("/"));
        assertFalse(path.matches("/foo"));
        assertFalse(path.matches("/foo/bar"));

        assertTrue(path.matches("/content"));
        assertTrue(path.matches("/content/a"));
        assertTrue(path.matches("/content/a/b"));

        assertFalse(path.matches("/content1"));
    }

    @Test public void testPatternMatching() {
        final Path path_1 = new Path("glob:/apps/**/*.html");
        assertTrue(path_1.matches("/apps/project/a.html"));
        assertTrue(path_1.matches("/apps/project/1/a.html"));
        assertTrue(path_1.matches("/apps/project/1/2/a.html"));
        assertFalse(path_1.matches("/apps/a.html"));
        assertFalse(path_1.matches("/apps/project/a.html/b"));

        final Path path_2 = new Path("glob:/apps/*.html");
        assertTrue(path_2.matches("/apps/a.html"));
        assertFalse(path_2.matches("/apps/a/a.html"));

        final Path path_3 = new Path("glob:/a/m-p/$structure/**/[cmp]/*.html");
        assertTrue(path_3.matches("/a/m-p/$structure/1/2/3/[cmp]/test.html"));
        assertTrue(path_3.matches("/a/m-p/$structure/1/[cmp]/test.html"));
        assertTrue(path_3.matches("/a/m-p/$structure/1/[cmp]/te-[s]t$.html"));
        assertTrue(path_3.matches("/a/m-p/$structure/1/[cmp]/.html"));
        assertFalse(path_3.matches("/a/m-p/$structure/1/[cmp]/html"));
        assertFalse(path_3.matches("/a/m-p/$structure/[cmp]/test.html"));
    }

    @Test public void testPatternRootMatching() {
        final Path path = new Path("/");
        assertTrue(path.matches("glob:/apps/myproject/components/**/*.html"));
        assertTrue(path.matches("glob:/apps/**/*.html"));
    }
}

@@ -850,32 +850,8 @@
 h;%0A%0A
-import org.junit.Test;%0A%0A
 impo
@@ -934,16 +934,40 @@
 tTrue;%0A%0A
+import org.junit.Test;%0A%0A
 public c
@@ -2972,11 +2972,253 @@
 );%0A    %7D
+%0A%0A    @Test public void testPathMatchingTrailingSlash() %7B%0A        final Path path = new Path(%22/libs/%22);%0A        assertTrue(path.matches(%22/libs%22));%0A        assertTrue(path.matches(%22/libs/foo%22));%0A        assertFalse(path.matches(%22/lib%22));%0A    %7D
 %0A%7D%0A

Add test for trailing path