|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2011 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
* |
| 11 |
*******************************************************************************/ |
| 12 |
package org.eclipse.wst.jsdt.web.core.tests; |
| 13 |
|
| 14 |
import org.eclipse.core.runtime.IPath; |
| 15 |
import org.eclipse.core.runtime.Path; |
| 16 |
import org.eclipse.wst.jsdt.web.core.internal.PathUtils; |
| 17 |
|
| 18 |
import junit.framework.Assert; |
| 19 |
import junit.framework.TestCase; |
| 20 |
|
| 21 |
/** |
| 22 |
* <p>Unit tests for the {@link PathUtils} class.</p> |
| 23 |
* |
| 24 |
*/ |
| 25 |
public class PathUtilsTests extends TestCase { |
| 26 |
|
| 27 |
/** |
| 28 |
* <p>Default constructor</p> |
| 29 |
*/ |
| 30 |
public PathUtilsTests() { |
| 31 |
super("Path Utils Tests"); |
| 32 |
} |
| 33 |
|
| 34 |
public void testOneSegmentParentWithOneSegmentPattern_SegmentCountTest_0() { |
| 35 |
runCountPatternSegmentsThatMatchParentTest("foo", "foo", 1); |
| 36 |
} |
| 37 |
|
| 38 |
public void testOneSegmentParentWithOneSegmentPattern_SegmentCountTest_1() { |
| 39 |
runCountPatternSegmentsThatMatchParentTest("/foo", "foo", 1); |
| 40 |
} |
| 41 |
|
| 42 |
public void testOneSegmentParentWithOneSegmentPattern_SegmentCountTest_2() { |
| 43 |
runCountPatternSegmentsThatMatchParentTest("/foo", "foo", 1); |
| 44 |
} |
| 45 |
|
| 46 |
public void testOneSegmentParentWithOneSegmentPattern_SegmentCountTest_3() { |
| 47 |
runCountPatternSegmentsThatMatchParentTest("foo", "/foo", 1); |
| 48 |
} |
| 49 |
|
| 50 |
public void testOneSegmentParentWithOneSegmentPattern_SegmentCountTest_4() { |
| 51 |
runCountPatternSegmentsThatMatchParentTest("/foo", "/foo", 1); |
| 52 |
} |
| 53 |
|
| 54 |
public void testOneSegmentParentWithTwoSegmentPattern_SegmentCountTest_0() { |
| 55 |
runCountPatternSegmentsThatMatchParentTest("foo/bar", "foo", 1); |
| 56 |
} |
| 57 |
|
| 58 |
public void testOneSegmentParentWithTwoSegmentPattern_SegmentCountTest_1() { |
| 59 |
runCountPatternSegmentsThatMatchParentTest("/foo/bar", "foo", 1); |
| 60 |
} |
| 61 |
|
| 62 |
public void testOneSegmentParentWithTwoSegmentPattern_SegmentCountTest_2() { |
| 63 |
runCountPatternSegmentsThatMatchParentTest("/foo/bar", "foo", 1); |
| 64 |
} |
| 65 |
|
| 66 |
public void testOneSegmentParentWithTwoSegmentPattern_SegmentCountTest_3() { |
| 67 |
runCountPatternSegmentsThatMatchParentTest("foo/bar", "/foo", 1); |
| 68 |
} |
| 69 |
|
| 70 |
public void testOneSegmentParentWithTwoSegmentPattern_SegmentCountTest_4() { |
| 71 |
runCountPatternSegmentsThatMatchParentTest("/foo/bar", "/foo", 1); |
| 72 |
} |
| 73 |
|
| 74 |
public void testOneSegmentParentWithTwoSegmentPattern_SegmentCountTest_5() { |
| 75 |
runCountPatternSegmentsThatMatchParentTest("foo/bar/", "foo", 1); |
| 76 |
} |
| 77 |
|
| 78 |
public void testOneSegmentParentWithTwoSegmentPattern_SegmentCountTest_6() { |
| 79 |
runCountPatternSegmentsThatMatchParentTest("/foo/bar/", "foo", 1); |
| 80 |
} |
| 81 |
|
| 82 |
public void testOneSegmentParentWithTwoSegmentPattern_SegmentCountTest_7() { |
| 83 |
runCountPatternSegmentsThatMatchParentTest("/foo/bar/", "foo", 1); |
| 84 |
} |
| 85 |
|
| 86 |
public void testOneSegmentParentWithTwoSegmentPattern_SegmentCountTest_8() { |
| 87 |
runCountPatternSegmentsThatMatchParentTest("foo/bar/", "/foo", 1); |
| 88 |
} |
| 89 |
|
| 90 |
public void testOneSegmentParentWithTwoSegmentPattern_SegmentCountTest_9() { |
| 91 |
runCountPatternSegmentsThatMatchParentTest("/foo/bar/", "/foo", 1); |
| 92 |
} |
| 93 |
|
| 94 |
public void testOneSegmentParentWithTwoSegmentPattern_SegmentCountTest_10() { |
| 95 |
runCountPatternSegmentsThatMatchParentTest("/foo/bar/", "/boo", 0); |
| 96 |
} |
| 97 |
|
| 98 |
public void testTwoSegmentParentWithThreeSegmentPattern_SegmentCountTest_0() { |
| 99 |
runCountPatternSegmentsThatMatchParentTest("/foo/bar/blarg", "/foo/bar", 2); |
| 100 |
} |
| 101 |
|
| 102 |
public void testStar_SegmentCountTest_0() { |
| 103 |
runCountPatternSegmentsThatMatchParentTest("/foo/*/blarg", "foo/bar", 2); |
| 104 |
} |
| 105 |
|
| 106 |
public void testStar_SegmentCountTest_1() { |
| 107 |
runCountPatternSegmentsThatMatchParentTest("/foo/*", "foo", 1); |
| 108 |
} |
| 109 |
|
| 110 |
public void testStar_SegmentCountTest_2() { |
| 111 |
runCountPatternSegmentsThatMatchParentTest("/foo/*", "foo/blarg", 2); |
| 112 |
} |
| 113 |
|
| 114 |
public void testStar_SegmentCountTest_3() { |
| 115 |
runCountPatternSegmentsThatMatchParentTest("/foo/*", "foo", 1); |
| 116 |
} |
| 117 |
|
| 118 |
public void testStarStar_SegmentCountTest_0() { |
| 119 |
runCountPatternSegmentsThatMatchParentTest("/foo/**", "foo", 1); |
| 120 |
} |
| 121 |
|
| 122 |
public void testStarStar_SegmentCountTest_1() { |
| 123 |
runCountPatternSegmentsThatMatchParentTest("/foo/**", "foo/bar", 2); |
| 124 |
} |
| 125 |
|
| 126 |
public void testStarStar_SegmentCountTest_2() { |
| 127 |
runCountPatternSegmentsThatMatchParentTest("/foo/**", "foo/bar/blarg", 3); |
| 128 |
} |
| 129 |
|
| 130 |
public void testStarStar_SegmentCountTest_3() { |
| 131 |
runCountPatternSegmentsThatMatchParentTest("/foo/**/blarg", "foo/bar/blarg", 3); |
| 132 |
} |
| 133 |
|
| 134 |
public void testStarStar_SegmentCountTest_4() { |
| 135 |
runCountPatternSegmentsThatMatchParentTest("/foo/**/blarg", "foo/bar/boo/blarg", 3); |
| 136 |
} |
| 137 |
|
| 138 |
public void testStarStar_SegmentCountTest_5() { |
| 139 |
runCountPatternSegmentsThatMatchParentTest("/foo/**/blarg/nerg", "foo/bar/boo/blarg", 3); |
| 140 |
} |
| 141 |
|
| 142 |
public void testQuestionMark_SegmentCountTest_0() { |
| 143 |
runCountPatternSegmentsThatMatchParentTest("foo?bar", "/fooZbar", 1); |
| 144 |
} |
| 145 |
|
| 146 |
public void testQuestionMark_SegmentCountTest_1() { |
| 147 |
runCountPatternSegmentsThatMatchParentTest("foo?bar", "/foobar", 0); |
| 148 |
} |
| 149 |
|
| 150 |
public void testOneSegmentParentWithOneSegmentPattern_TransformPatternTest_0() { |
| 151 |
runMakePatternRelativeToParentTest("foo", "foo", null); |
| 152 |
} |
| 153 |
|
| 154 |
public void testOneSegmentParentWithOneSegmentPattern_TransformPatternTest_1() { |
| 155 |
runMakePatternRelativeToParentTest("/foo", "foo", null); |
| 156 |
} |
| 157 |
|
| 158 |
public void testOneSegmentParentWithOneSegmentPattern_TransformPatternTest_2() { |
| 159 |
runMakePatternRelativeToParentTest("/foo", "foo", null); |
| 160 |
} |
| 161 |
|
| 162 |
public void testOneSegmentParentWithOneSegmentPattern_TransformPatternTest_3() { |
| 163 |
runMakePatternRelativeToParentTest("foo", "foo", null); |
| 164 |
} |
| 165 |
|
| 166 |
public void testOneSegmentParentWithOneSegmentPattern_TransformPatternTest_4() { |
| 167 |
runMakePatternRelativeToParentTest("/foo", "foo", null); |
| 168 |
} |
| 169 |
|
| 170 |
public void testOneSegmentParentWithTwoSegmentPattern_TransformPatternTest_0() { |
| 171 |
runMakePatternRelativeToParentTest("foo/bar", "foo", "bar/"); |
| 172 |
} |
| 173 |
|
| 174 |
public void testOneSegmentParentWithTwoSegmentPattern_TransformPatternTest_1() { |
| 175 |
runMakePatternRelativeToParentTest("/foo/bar", "foo", "bar/"); |
| 176 |
} |
| 177 |
|
| 178 |
public void testOneSegmentParentWithTwoSegmentPattern_TransformPatternTest_2() { |
| 179 |
runMakePatternRelativeToParentTest("/foo/bar", "foo", "bar/"); |
| 180 |
} |
| 181 |
|
| 182 |
public void testOneSegmentParentWithTwoSegmentPattern_TransformPatternTest_3() { |
| 183 |
runMakePatternRelativeToParentTest("foo/bar", "/foo", "bar/"); |
| 184 |
} |
| 185 |
|
| 186 |
public void testOneSegmentParentWithTwoSegmentPattern_TransformPatternTest_4() { |
| 187 |
runMakePatternRelativeToParentTest("/foo/bar", "/foo", "bar/"); |
| 188 |
} |
| 189 |
|
| 190 |
public void testOneSegmentParentWithTwoSegmentPattern_TransformPatternTest_5() { |
| 191 |
runMakePatternRelativeToParentTest("foo/bar/", "foo", "bar/"); |
| 192 |
} |
| 193 |
|
| 194 |
public void testOneSegmentParentWithTwoSegmentPattern_TransformPatternTest_6() { |
| 195 |
runMakePatternRelativeToParentTest("/foo/bar/", "foo", "bar/"); |
| 196 |
} |
| 197 |
|
| 198 |
public void testOneSegmentParentWithTwoSegmentPattern_TransformPatternTest_7() { |
| 199 |
runMakePatternRelativeToParentTest("/foo/bar/", "foo", "bar/"); |
| 200 |
} |
| 201 |
|
| 202 |
public void testOneSegmentParentWithTwoSegmentPattern_TransformPatternTest_8() { |
| 203 |
runMakePatternRelativeToParentTest("foo/bar/", "/foo", "bar/"); |
| 204 |
} |
| 205 |
|
| 206 |
public void testOneSegmentParentWithTwoSegmentPattern_TransformPatternTest_9() { |
| 207 |
runMakePatternRelativeToParentTest("/foo/bar/", "/foo", "bar/"); |
| 208 |
} |
| 209 |
|
| 210 |
public void testOneSegmentParentWithTwoSegmentPattern_TransformPatternTest_10() { |
| 211 |
runMakePatternRelativeToParentTest("/foo/bar/", "/boo", null); |
| 212 |
} |
| 213 |
|
| 214 |
public void testTwoSegmentParentWithThreeSegmentPattern_TransformPatternTest_0() { |
| 215 |
runMakePatternRelativeToParentTest("/foo/bar/blarg", "/foo/bar", "blarg/"); |
| 216 |
} |
| 217 |
|
| 218 |
public void testStar_TransformPatternTest_0() { |
| 219 |
runMakePatternRelativeToParentTest("/foo/*/blarg", "foo/bar", "blarg/"); |
| 220 |
} |
| 221 |
|
| 222 |
public void testStar_TransformPatternTest_1() { |
| 223 |
runMakePatternRelativeToParentTest("/foo/*", "foo", "*/"); |
| 224 |
} |
| 225 |
|
| 226 |
public void testStar_TransformPatternTest_2() { |
| 227 |
runMakePatternRelativeToParentTest("/foo/*", "foo/blarg/", null); |
| 228 |
} |
| 229 |
|
| 230 |
public void testStar_TransformPatternTest_3() { |
| 231 |
runMakePatternRelativeToParentTest("/foo/*", "foo", "*/"); |
| 232 |
} |
| 233 |
|
| 234 |
public void testStarStar_TransformPatternTest_0() { |
| 235 |
runMakePatternRelativeToParentTest("/foo/**", "foo", "**/"); |
| 236 |
} |
| 237 |
|
| 238 |
public void testStarStar_TransformPatternTest_1() { |
| 239 |
runMakePatternRelativeToParentTest("/foo/**", "foo/bar/", null); |
| 240 |
} |
| 241 |
|
| 242 |
public void testStarStar_TransformPatternTest_2() { |
| 243 |
runMakePatternRelativeToParentTest("/foo/**", "foo/bar/blarg/", null); |
| 244 |
} |
| 245 |
|
| 246 |
public void testStarStar_TransformPatternTest_3() { |
| 247 |
runMakePatternRelativeToParentTest("/foo/**/blarg", "foo/bar/blarg/", null); |
| 248 |
} |
| 249 |
|
| 250 |
public void testStarStar_TransformPatternTest_4() { |
| 251 |
runMakePatternRelativeToParentTest("/foo/**/blarg", "foo/bar/boo/blarg/", null); |
| 252 |
} |
| 253 |
|
| 254 |
public void testStarStar_TransformPatternTest_5() { |
| 255 |
runMakePatternRelativeToParentTest("/foo/**/blarg/nerg", "foo/bar/boo/blarg", "nerg/"); |
| 256 |
} |
| 257 |
|
| 258 |
public void testQuestionMark_TransformPatternTest_0() { |
| 259 |
runMakePatternRelativeToParentTest("foo?bar", "/fooZbar", null); |
| 260 |
} |
| 261 |
|
| 262 |
public void testQuestionMark_TransformPatternTest_1() { |
| 263 |
runMakePatternRelativeToParentTest("foo?bar", "/foobar", null); |
| 264 |
} |
| 265 |
|
| 266 |
public void testQuestionMark_TransformPatternTest_2() { |
| 267 |
runMakePatternRelativeToParentTest("foo?bar/awesome", "/fooZbar", "awesome/"); |
| 268 |
} |
| 269 |
|
| 270 |
public void testQuestionMark_TransformPatternTest_3() { |
| 271 |
runMakePatternRelativeToParentTest("foo?bar/awesome", "/foobar", null); |
| 272 |
} |
| 273 |
|
| 274 |
/** |
| 275 |
* <p>Runs a test on {@link PathUtils#countPatternSegmentsThatMatchParent(IPath, IPath)}</p> |
| 276 |
* |
| 277 |
* @param pattern the pattern path to test |
| 278 |
* @param parentPath the parent path to test |
| 279 |
* @param expectedMatchedSegments the expected number of segments in the pattern that match the parent |
| 280 |
*/ |
| 281 |
private static void runCountPatternSegmentsThatMatchParentTest(String pattern, String parentPath, |
| 282 |
int expectedMatchedSegments) { |
| 283 |
int matchedSegments = PathUtils.countPatternSegmentsThatMatchParent( |
| 284 |
new Path(pattern), new Path(parentPath)); |
| 285 |
|
| 286 |
Assert.assertEquals("Number of matched path segments does not equal expected.", //$NON-NLS-1$ |
| 287 |
expectedMatchedSegments, matchedSegments); |
| 288 |
} |
| 289 |
|
| 290 |
/** |
| 291 |
* |
| 292 |
* <p>Runs a test on {@link PathUtils#makePatternRelativeToParent(IPath, IPath)}</p> |
| 293 |
* |
| 294 |
* @param pattern the pattern path to test |
| 295 |
* @param parent the parent path to test |
| 296 |
* @param expected the expected pattern path made relative to the parent path |
| 297 |
*/ |
| 298 |
private static void runMakePatternRelativeToParentTest(String pattern, String parent, String expected) { |
| 299 |
IPath transformedPattern = PathUtils.makePatternRelativeToParent( |
| 300 |
new Path(pattern), new Path(parent)); |
| 301 |
|
| 302 |
IPath expectedPath = null; |
| 303 |
if(expected != null) { |
| 304 |
expectedPath = new Path(expected); |
| 305 |
} |
| 306 |
|
| 307 |
Assert.assertEquals("Transformed pattern does not match expected.", |
| 308 |
expectedPath, transformedPattern); |
| 309 |
} |
| 310 |
} |