blob: 09d4ccbb24ebf08cfc6053546982ee25620b0838 [file] [log] [blame]
Dave Borowitzbcd753d2013-02-08 11:10:19 -08001// Copyright 2012 Google Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package com.google.gitiles;
16
17import static com.google.gitiles.Paths.simplifyPathUpToRoot;
Dave Borowitzbcd753d2013-02-08 11:10:19 -080018import junit.framework.TestCase;
19
20/** Tests for {@link Paths}. */
21public class PathsTest extends TestCase {
22 public void testSimplifyPathUpToRoot() throws Exception {
23 String root = "a/b/c";
24 assertNull(simplifyPathUpToRoot("/foo", root));
25 assertEquals("a", simplifyPathUpToRoot("../../", root));
26 assertEquals("a", simplifyPathUpToRoot(".././../", root));
27 assertEquals("a", simplifyPathUpToRoot("..//../", root));
28 assertEquals("a/d", simplifyPathUpToRoot("../../d", root));
29 assertEquals("", simplifyPathUpToRoot("../../..", root));
30 assertEquals("a/d/e", simplifyPathUpToRoot("../../d/e", root));
31 assertEquals("a/b", simplifyPathUpToRoot("../d/../e/../", root));
32 assertNull(simplifyPathUpToRoot("../../../../", root));
33 assertNull(simplifyPathUpToRoot("../../a/../../..", root));
34 }
35
36 public void testSimplifyPathUpToNullRoot() throws Exception {
37 assertNull(simplifyPathUpToRoot("/foo", null));
38 assertNull(simplifyPathUpToRoot("../", null));
39 assertNull(simplifyPathUpToRoot("../../", null));
40 assertNull(simplifyPathUpToRoot(".././../", null));
41 assertEquals("a/b", simplifyPathUpToRoot("a/b", null));
42 assertEquals("a/c", simplifyPathUpToRoot("a/b/../c", null));
43 }
44}