Gridarta Editor
MapPathUtilsTest.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.model.mapmodel;
21 
22 import org.junit.Assert;
23 import org.junit.Test;
24 
29 public class MapPathUtilsTest {
30 
34  @Test
35  public void testNewMapPath1() {
36  Assert.assertEquals("", MapPathUtils.newMapPath("").toString());
37  Assert.assertEquals("a", MapPathUtils.newMapPath("a").toString());
38  Assert.assertEquals("a/b/c", MapPathUtils.newMapPath("a/b/c").toString());
39  Assert.assertEquals("a/c", MapPathUtils.newMapPath("a/b/../c").toString());
40  Assert.assertEquals("../../x", MapPathUtils.newMapPath("a/../../../x").toString());
41  Assert.assertEquals("a/b", MapPathUtils.newMapPath("./a/./b/.").toString());
42  Assert.assertEquals("a/b", MapPathUtils.newMapPath("a//b///").toString());
43 
44  Assert.assertEquals("/", MapPathUtils.newMapPath("/").toString());
45  Assert.assertEquals("/a", MapPathUtils.newMapPath("/a").toString());
46  Assert.assertEquals("/a/b/c", MapPathUtils.newMapPath("/a/b/c").toString());
47  Assert.assertEquals("/a/c", MapPathUtils.newMapPath("/a/b/../c").toString());
48  Assert.assertEquals("/x", MapPathUtils.newMapPath("/a/../../../x").toString());
49  Assert.assertEquals("/a/b", MapPathUtils.newMapPath("/./a/./b/.").toString());
50  Assert.assertEquals("/a/b", MapPathUtils.newMapPath("///a//b///").toString());
51  }
52 
57  @Test
58  public void testAppendAbsolute1() {
59  Assert.assertEquals("/a/b/d/e/f", MapPathUtils.append(MapPathUtils.newAbsoluteMapPath("/a/b/c"), MapPathUtils.newMapPath("d/e/f")).toString());
60  Assert.assertEquals("/d/e/f", MapPathUtils.append(MapPathUtils.newAbsoluteMapPath("/a/b/c"), MapPathUtils.newMapPath("/d/e/f")).toString());
61  }
62 
67  @Test
68  public void testAppendRelative1() {
69  Assert.assertEquals("a/b/d/e/f", MapPathUtils.append(MapPathUtils.newRelativeMapPath("a/b/c"), MapPathUtils.newRelativeMapPath("d/e/f")).toString());
70  Assert.assertEquals("../a/b/d/e/f", MapPathUtils.append(MapPathUtils.newRelativeMapPath("../a/b/c"), MapPathUtils.newRelativeMapPath("d/e/f")).toString());
71  Assert.assertEquals("../a/d/e/f", MapPathUtils.append(MapPathUtils.newRelativeMapPath("../a/b/c"), MapPathUtils.newRelativeMapPath("../d/e/f")).toString());
72  Assert.assertEquals("../a/d/e/f", MapPathUtils.append(MapPathUtils.newRelativeMapPath("../a/b/c/d"), MapPathUtils.newRelativeMapPath("../../d/e/f")).toString());
73  Assert.assertEquals("../d/e/f", MapPathUtils.append(MapPathUtils.newRelativeMapPath("../a/b/c"), MapPathUtils.newRelativeMapPath("../../d/e/f")).toString());
74  Assert.assertEquals("../../d/e/f", MapPathUtils.append(MapPathUtils.newRelativeMapPath("../a/b/c"), MapPathUtils.newRelativeMapPath("../../../d/e/f")).toString());
75  Assert.assertEquals("../../../d/e/f", MapPathUtils.append(MapPathUtils.newRelativeMapPath("../a/b/c"), MapPathUtils.newRelativeMapPath("../../../../d/e/f")).toString());
76  Assert.assertEquals("../..", MapPathUtils.append(MapPathUtils.newRelativeMapPath(".."), MapPathUtils.newRelativeMapPath("..")).toString());
77  }
78 
79 }
net.sf.gridarta.model.mapmodel.MapPathUtils.newRelativeMapPath
static RelativeMapPath newRelativeMapPath(@NotNull final String string)
Creates a RelativeMapPath instance from string representation.
Definition: MapPathUtils.java:71
net.sf.gridarta.model.mapmodel.MapPathUtilsTest.testNewMapPath1
void testNewMapPath1()
Checks that MapPathUtils#newMapPath(String) works as expected.
Definition: MapPathUtilsTest.java:35
net.sf.gridarta.model.mapmodel.MapPathUtils.newMapPath
static MapPath newMapPath(@NotNull final String string)
Creates a MapPath instance from string representation.
Definition: MapPathUtils.java:43
net.sf.gridarta.model.mapmodel.MapPathUtils
Utility class for MapPath related functions.
Definition: MapPathUtils.java:28
net.sf.gridarta.model.mapmodel.MapPathUtils.append
static AbsoluteMapPath append(@NotNull final AbsoluteMapPath baseMapPath, @NotNull final MapPath mapPath)
Appends a map path to another map path.
Definition: MapPathUtils.java:85
net.sf.gridarta.model.mapmodel.MapPathUtils.newAbsoluteMapPath
static AbsoluteMapPath newAbsoluteMapPath(@NotNull final String string)
Creates an AbsoluteMapPath instance from string representation.
Definition: MapPathUtils.java:57
net.sf.gridarta.model.mapmodel.AbsoluteMapPath.toString
String toString()
Definition: AbsoluteMapPath.java:117
net.sf.gridarta.model.mapmodel.MapPathUtilsTest.testAppendAbsolute1
void testAppendAbsolute1()
Checks that MapPathUtils#append(AbsoluteMapPath, MapPath) works as expected.
Definition: MapPathUtilsTest.java:58
net.sf.gridarta.model.mapmodel.MapPathUtilsTest
Regression tests for MapPathUtils.
Definition: MapPathUtilsTest.java:29
net.sf.gridarta.model.mapmodel.MapPathUtilsTest.testAppendRelative1
void testAppendRelative1()
Checks that MapPathUtils#append(RelativeMapPath, RelativeMapPath) works as expected.
Definition: MapPathUtilsTest.java:68