source: proiecte/HadoopJUnit/hadoop-0.20.1/src/test/org/apache/hadoop/fs/TestGlobExpander.java @ 120

Last change on this file since 120 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1/**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18package org.apache.hadoop.fs;
19
20import java.io.IOException;
21import java.util.List;
22
23import junit.framework.TestCase;
24
25public class TestGlobExpander extends TestCase {
26
27  public void testExpansionIsIdentical() throws IOException {
28    checkExpansionIsIdentical("");
29    checkExpansionIsIdentical("/}");
30    checkExpansionIsIdentical("/}{a,b}");
31    checkExpansionIsIdentical("{/");
32    checkExpansionIsIdentical("{a}");
33    checkExpansionIsIdentical("{a,b}/{b,c}");
34    checkExpansionIsIdentical("p\\{a/b,c/d\\}s");
35    checkExpansionIsIdentical("p{a\\/b,c\\/d}s");
36  }
37
38  public void testExpansion() throws IOException {
39    checkExpansion("{a/b}", "a/b");
40    checkExpansion("/}{a/b}", "/}a/b");
41    checkExpansion("p{a/b,c/d}s", "pa/bs", "pc/ds");
42    checkExpansion("{a/b,c/d,{e,f}}", "a/b", "c/d", "{e,f}");
43    checkExpansion("{a/b,c/d}{e,f}", "a/b{e,f}", "c/d{e,f}");
44    checkExpansion("{a,b}/{b,{c/d,e/f}}", "{a,b}/b", "{a,b}/c/d", "{a,b}/e/f");
45    checkExpansion("{a,b}/{c/\\d}", "{a,b}/c/d");
46  }
47
48  private void checkExpansionIsIdentical(String filePattern) throws IOException {
49    checkExpansion(filePattern, filePattern);
50  }
51
52  private void checkExpansion(String filePattern, String... expectedExpansions)
53      throws IOException {
54    List<String> actualExpansions = GlobExpander.expand(filePattern);
55    assertEquals("Different number of expansions", expectedExpansions.length,
56        actualExpansions.size());
57    for (int i = 0; i < expectedExpansions.length; i++) {
58      assertEquals("Expansion of " + filePattern, expectedExpansions[i],
59          actualExpansions.get(i));
60    }
61  }
62}
Note: See TracBrowser for help on using the repository browser.