blob: e1ed3e8df8324277a898d5ffa96669ec05d8eb12 [file] [log] [blame]
Dave Borowitz9de65952012-08-13 16:09:45 -07001// 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.TreeSoyData.getTargetDisplayName;
18import static com.google.gitiles.TreeSoyData.resolveTargetUrl;
Dave Borowitz9de65952012-08-13 16:09:45 -070019import junit.framework.TestCase;
20
21import org.eclipse.jgit.lib.ObjectId;
22
Shawn Pearceb43b2d52013-03-18 10:55:15 -070023import com.google.common.base.Strings;
24
Dave Borowitz9de65952012-08-13 16:09:45 -070025/** Tests for {@link TreeSoyData}. */
26public class TreeSoyDataTest extends TestCase {
27 public void testGetTargetDisplayName() throws Exception {
28 assertEquals("foo", getTargetDisplayName("foo"));
29 assertEquals("foo/bar", getTargetDisplayName("foo/bar"));
30 assertEquals("a/a/a/a/a/a/a/a/a/a/bar",
31 getTargetDisplayName(Strings.repeat("a/", 10) + "bar"));
32 assertEquals("a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/bar",
33 getTargetDisplayName(Strings.repeat("a/", 34) + "bar"));
34 assertEquals(".../bar", getTargetDisplayName(Strings.repeat("a/", 35) + "bar"));
35 assertEquals(".../bar", getTargetDisplayName(Strings.repeat("a/", 100) + "bar"));
36 assertEquals("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
37 getTargetDisplayName(Strings.repeat("a", 80)));
38 }
39
40 public void testResolveTargetUrl() throws Exception {
41 ObjectId id = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
42 GitilesView view = GitilesView.path()
43 .setServletPath("/x")
44 .setHostName("host")
45 .setRepositoryName("repo")
46 .setRevision(Revision.unpeeled("m", id))
Dave Borowitzdd3c3d92013-03-11 16:38:41 -070047 .setPathPart("a/b/c")
Dave Borowitz9de65952012-08-13 16:09:45 -070048 .build();
49 assertNull(resolveTargetUrl(view, "/foo"));
50 assertEquals("/x/repo/+/m/a", resolveTargetUrl(view, "../../"));
51 assertEquals("/x/repo/+/m/a", resolveTargetUrl(view, ".././../"));
52 assertEquals("/x/repo/+/m/a", resolveTargetUrl(view, "..//../"));
53 assertEquals("/x/repo/+/m/a/d", resolveTargetUrl(view, "../../d"));
54 assertEquals("/x/repo/+/m/", resolveTargetUrl(view, "../../.."));
55 assertEquals("/x/repo/+/m/a/d/e", resolveTargetUrl(view, "../../d/e"));
56 assertEquals("/x/repo/+/m/a/b", resolveTargetUrl(view, "../d/../e/../"));
57 assertNull(resolveTargetUrl(view, "../../../../"));
58 assertNull(resolveTargetUrl(view, "../../a/../../.."));
59 }
60}