< prev index next >

test/java/nio/file/Path/PathOps.java

Print this page


   1 /*
   2  * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25  * @bug 4313887 6838333 6925932 7006126 8037945 8072495
  26  * @summary Unit test for java.nio.file.Path path operations
  27  */
  28 
  29 import java.nio.file.*;



  30 
  31 public class PathOps {
  32 
  33     static final java.io.PrintStream out = System.out;
  34 
  35     private String input;
  36     private Path path;
  37     private Exception exc;
  38 
  39     private PathOps(String first, String... more) {
  40         out.println();
  41         input = first;
  42         try {
  43             path = FileSystems.getDefault().getPath(first, more);
  44             out.format("%s -> %s", first, path);
  45         } catch (Exception x) {
  46             exc = x;
  47             out.format("%s -> %s", first, x);
  48         }
  49         out.println();
  50     }
  51 
  52     Path path() {
  53         return path;
  54     }
  55 
  56     void fail() {
  57         throw new RuntimeException("PathOps failed");
  58     }
  59 
  60     void checkPath() {
  61         if (path == null) {


  70             if (expected == null) return;
  71         } else {
  72             // compare string representations
  73             if (expected != null && result.toString().equals(expected.toString()))
  74                 return;
  75         }
  76         fail();
  77     }
  78 
  79     void check(Object result, boolean expected) {
  80         check(result, Boolean.toString(expected));
  81     }
  82 
  83     PathOps root(String expected) {
  84         out.println("check root");
  85         checkPath();
  86         check(path.getRoot(), expected);
  87         return this;
  88     }
  89 








  90     PathOps parent(String expected) {
  91         out.println("check parent");
  92         checkPath();
  93         check(path.getParent(), expected);
  94         return this;
  95     }
  96 
  97     PathOps name(String expected) {
  98         out.println("check name");
  99         checkPath();
 100         check(path.getFileName(), expected);
 101         return this;
 102     }
 103 
 104     PathOps element(int index, String expected) {
 105         out.format("check element %d\n", index);
 106         checkPath();
 107         check(path.getName(index), expected);
 108         return this;
 109     }


 130         check(path.startsWith(s), false);
 131         return this;
 132     }
 133 
 134     PathOps ends(String suffix) {
 135         out.format("test endsWith %s\n", suffix);
 136         checkPath();
 137         Path s = FileSystems.getDefault().getPath(suffix);
 138         check(path.endsWith(s), true);
 139         return this;
 140     }
 141 
 142     PathOps notEnds(String suffix) {
 143         out.format("test not endsWith %s\n", suffix);
 144         checkPath();
 145         Path s = FileSystems.getDefault().getPath(suffix);
 146         check(path.endsWith(s), false);
 147         return this;
 148     }
 149 





 150     PathOps absolute() {
 151         out.println("check path is absolute");
 152         checkPath();
 153         check(path.isAbsolute(), true);
 154         return this;
 155     }
 156 
 157     PathOps notAbsolute() {
 158         out.println("check path is not absolute");
 159         checkPath();
 160         check(path.isAbsolute(), false);
 161         return this;
 162     }
 163 
 164     PathOps resolve(String other, String expected) {
 165         out.format("test resolve %s\n", other);
 166         checkPath();
 167         check(path.resolve(other), expected);
 168         return this;
 169     }


 192 
 193     PathOps string(String expected) {
 194         out.println("check string representation");
 195         checkPath();
 196         check(path, expected);
 197         return this;
 198     }
 199 
 200     PathOps invalid() {
 201         if (!(exc instanceof InvalidPathException)) {
 202             out.println("InvalidPathException not thrown as expected");
 203             fail();
 204         }
 205         return this;
 206     }
 207 
 208     static PathOps test(String first, String... more) {
 209         return new PathOps(first, more);
 210     }
 211 





 212     // -- PathOpss --
 213 
 214     static void header(String s) {
 215         out.println();
 216         out.println();
 217         out.println("-- " + s + " --");
 218     }
 219 
 220     static void doWindowsTests() {
 221         header("Windows specific tests");

 222 
 223         // construction
 224         test("C:\\")
 225             .string("C:\\");
 226         test("C:\\", "")
 227             .string("C:\\");
 228         test("C:\\", "foo")
 229             .string("C:\\foo");
 230         test("C:\\", "\\foo")
 231             .string("C:\\foo");
 232         test("C:\\", "foo\\")
 233             .string("C:\\foo");
 234         test("foo", "bar", "gus")
 235             .string("foo\\bar\\gus");
 236         test("")
 237             .string("");
 238         test("", "C:\\")
 239             .string("C:\\");
 240         test("", "foo", "", "bar", "", "\\gus")
 241             .string("foo\\bar\\gus");


 400             .subpath(0, 1, "foo");
 401         test("C:\\foo\\bar\\gus")
 402             .subpath(0, 1, "foo")
 403             .subpath(0, 2, "foo\\bar")
 404             .subpath(0, 3, "foo\\bar\\gus")
 405             .subpath(1, 2, "bar")
 406             .subpath(1, 3, "bar\\gus")
 407             .subpath(2, 3, "gus");
 408         test("\\\\server\\share\\foo")
 409             .subpath(0, 1, "foo");
 410         test("")
 411             .subpath(0, 1, "");
 412 
 413         // isAbsolute
 414         test("foo").notAbsolute();
 415         test("C:").notAbsolute();
 416         test("C:\\").absolute();
 417         test("C:\\abc").absolute();
 418         test("\\\\server\\share\\").absolute();
 419         test("").notAbsolute();














































 420 
 421         // resolve
 422         test("C:\\")
 423             .resolve("foo", "C:\\foo")
 424             .resolve("D:\\bar", "D:\\bar")
 425             .resolve("\\\\server\\share\\bar", "\\\\server\\share\\bar")
 426             .resolve("C:foo", "C:\\foo")
 427             .resolve("D:foo", "D:foo")
 428             .resolve("", "C:\\");
 429         test("\\")
 430             .resolve("foo", "\\foo")
 431             .resolve("D:bar", "D:bar")
 432             .resolve("C:\\bar", "C:\\bar")
 433             .resolve("\\\\server\\share\\bar", "\\\\server\\share\\bar")
 434             .resolve("\\foo", "\\foo")
 435             .resolve("", "\\");
 436         test("\\foo")
 437             .resolve("bar", "\\foo\\bar")
 438             .resolve("D:bar", "D:bar")
 439             .resolve("C:\\bar", "C:\\bar")


 489         test("C:\\foo\\bar")
 490             .resolveSibling("gus", "C:\\foo\\gus")
 491             .resolveSibling("D:\\bar", "D:\\bar")
 492             .resolveSibling("\\\\server\\share\\bar", "\\\\server\\share\\bar")
 493             .resolveSibling("C:bar", "C:\\foo\\bar")
 494             .resolveSibling("D:foo", "D:foo")
 495             .resolveSibling("", "C:\\foo");
 496         test("\\\\server\\share\\foo")
 497             .resolveSibling("bar", "\\\\server\\share\\bar")
 498             .resolveSibling("\\bar", "\\\\server\\share\\bar")
 499             .resolveSibling("D:\\bar", "D:\\bar")
 500             .resolveSibling("\\\\other\\share\\bar", "\\\\other\\share\\bar")
 501             .resolveSibling("D:bar", "D:bar")
 502             .resolveSibling("", "\\\\server\\share\\");
 503         test("")
 504             .resolveSibling("", "")
 505             .resolveSibling("foo", "foo")
 506             .resolveSibling("C:\\", "C:\\");
 507 
 508         // relativize





 509         test("foo\\bar")
 510             .relativize("foo\\bar", "")
 511             .relativize("foo", "..");



 512         test("C:\\a\\b\\c")
 513             .relativize("C:\\a", "..\\..")
 514             .relativize("C:\\a\\b\\c", "");

 515         test("\\\\server\\share\\foo")
 516             .relativize("\\\\server\\share\\bar", "..\\bar")
 517             .relativize("\\\\server\\share\\foo", "");
 518         test("")
 519             .relativize("", "")
 520             .relativize("a", "a")
 521             .relativize("a\\b\\c", "a\\b\\c");


 522 
 523         // normalize
 524         test("C:\\")
 525             .normalize("C:\\");
 526         test("C:\\.")
 527             .normalize("C:\\");
 528         test("C:\\..")
 529             .normalize("C:\\");
 530         test("\\\\server\\share")
 531             .normalize("\\\\server\\share\\");
 532         test("\\\\server\\share\\.")
 533             .normalize("\\\\server\\share\\");
 534         test("\\\\server\\share\\..")
 535             .normalize("\\\\server\\share\\");
 536         test("C:")
 537             .normalize("C:");
 538         test("C:.")
 539             .normalize("C:");
 540         test("C:..")
 541             .normalize("C:..");


 655         // normalization at construction time (remove redundant and replace slashes)
 656         test("C:/a/b/c")
 657             .string("C:\\a\\b\\c")
 658             .root("C:\\")
 659             .parent("C:\\a\\b");
 660         test("C://a//b//c")
 661             .string("C:\\a\\b\\c")
 662             .root("C:\\")
 663             .parent("C:\\a\\b");
 664 
 665         // hashCode
 666         header("hashCode");
 667         int h1 = test("C:\\foo").path().hashCode();
 668         int h2 = test("c:\\FOO").path().hashCode();
 669         if (h1 != h2)
 670             throw new RuntimeException("PathOps failed");
 671     }
 672 
 673     static void doUnixTests() {
 674         header("Unix specific tests");

 675 
 676         // construction
 677         test("/")
 678             .string("/");
 679         test("/", "")
 680             .string("/");
 681         test("/", "foo")
 682             .string("/foo");
 683         test("/", "/foo")
 684             .string("/foo");
 685         test("/", "foo/")
 686             .string("/foo");
 687         test("foo", "bar", "gus")
 688             .string("foo/bar/gus");
 689         test("")
 690             .string("");
 691         test("", "/")
 692             .string("/");
 693         test("", "foo", "", "bar", "", "/gus")
 694             .string("foo/bar/gus");


 823             .subpath(0, 3, "foo/bar/gus");
 824         test("foo/bar/gus")
 825             .subpath(0, 1, "foo")
 826             .subpath(1, 2, "bar")
 827             .subpath(2, 3, "gus")
 828             .subpath(0, 2, "foo/bar")
 829             .subpath(1, 3, "bar/gus")
 830             .subpath(0, 3, "foo/bar/gus");
 831         test("")
 832             .subpath(0, 1, "");
 833 
 834         // isAbsolute
 835         test("/")
 836             .absolute();
 837         test("/tmp")
 838             .absolute();
 839         test("tmp")
 840             .notAbsolute();
 841         test("")
 842             .notAbsolute();


 843 













 844 
 845         // resolve
 846         test("/tmp")
 847             .resolve("foo", "/tmp/foo")
 848             .resolve("/foo", "/foo")
 849             .resolve("", "/tmp");
 850         test("tmp")
 851             .resolve("foo", "tmp/foo")
 852             .resolve("/foo", "/foo")
 853             .resolve("", "tmp");
 854         test("")
 855             .resolve("", "")
 856             .resolve("foo", "foo")
 857             .resolve("/foo", "/foo");
 858 
 859         // resolveSibling
 860         test("foo")
 861             .resolveSibling("bar", "bar")
 862             .resolveSibling("/bar", "/bar")
 863             .resolveSibling("", "");


   1 /*
   2  * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25  * @bug 4313887 6838333 6925932 7006126 8037945 8072495 8140449
  26  * @summary Unit test for java.nio.file.Path path operations
  27  */
  28 
  29 import java.nio.file.FileSystems;
  30 import java.nio.file.InvalidPathException;
  31 import java.nio.file.Path;
  32 import java.nio.file.Paths;
  33 
  34 public class PathOps {
  35 
  36     static final java.io.PrintStream out = System.out;
  37 

  38     private Path path;
  39     private Exception exc;
  40 
  41     private PathOps(String first, String... more) {
  42         out.println();

  43         try {
  44             path = FileSystems.getDefault().getPath(first, more);
  45             out.format("%s -> %s", first, path);
  46         } catch (Exception x) {
  47             exc = x;
  48             out.format("%s -> %s", first, x);
  49         }
  50         out.println();
  51     }
  52 
  53     Path path() {
  54         return path;
  55     }
  56 
  57     void fail() {
  58         throw new RuntimeException("PathOps failed");
  59     }
  60 
  61     void checkPath() {
  62         if (path == null) {


  71             if (expected == null) return;
  72         } else {
  73             // compare string representations
  74             if (expected != null && result.toString().equals(expected.toString()))
  75                 return;
  76         }
  77         fail();
  78     }
  79 
  80     void check(Object result, boolean expected) {
  81         check(result, Boolean.toString(expected));
  82     }
  83 
  84     PathOps root(String expected) {
  85         out.println("check root");
  86         checkPath();
  87         check(path.getRoot(), expected);
  88         return this;
  89     }
  90 
  91     PathOps hasRoot() {
  92         out.println("check has root");
  93         checkPath();
  94         if (path.getRoot() == null)
  95             fail();
  96         return this;
  97     }
  98 
  99     PathOps parent(String expected) {
 100         out.println("check parent");
 101         checkPath();
 102         check(path.getParent(), expected);
 103         return this;
 104     }
 105 
 106     PathOps name(String expected) {
 107         out.println("check name");
 108         checkPath();
 109         check(path.getFileName(), expected);
 110         return this;
 111     }
 112 
 113     PathOps element(int index, String expected) {
 114         out.format("check element %d\n", index);
 115         checkPath();
 116         check(path.getName(index), expected);
 117         return this;
 118     }


 139         check(path.startsWith(s), false);
 140         return this;
 141     }
 142 
 143     PathOps ends(String suffix) {
 144         out.format("test endsWith %s\n", suffix);
 145         checkPath();
 146         Path s = FileSystems.getDefault().getPath(suffix);
 147         check(path.endsWith(s), true);
 148         return this;
 149     }
 150 
 151     PathOps notEnds(String suffix) {
 152         out.format("test not endsWith %s\n", suffix);
 153         checkPath();
 154         Path s = FileSystems.getDefault().getPath(suffix);
 155         check(path.endsWith(s), false);
 156         return this;
 157     }
 158 
 159     PathOps makeAbsolute() {
 160         this.path = path.toAbsolutePath();
 161         return this;
 162     }
 163 
 164     PathOps absolute() {
 165         out.println("check path is absolute");
 166         checkPath();
 167         check(path.isAbsolute(), true);
 168         return this;
 169     }
 170 
 171     PathOps notAbsolute() {
 172         out.println("check path is not absolute");
 173         checkPath();
 174         check(path.isAbsolute(), false);
 175         return this;
 176     }
 177 
 178     PathOps resolve(String other, String expected) {
 179         out.format("test resolve %s\n", other);
 180         checkPath();
 181         check(path.resolve(other), expected);
 182         return this;
 183     }


 206 
 207     PathOps string(String expected) {
 208         out.println("check string representation");
 209         checkPath();
 210         check(path, expected);
 211         return this;
 212     }
 213 
 214     PathOps invalid() {
 215         if (!(exc instanceof InvalidPathException)) {
 216             out.println("InvalidPathException not thrown as expected");
 217             fail();
 218         }
 219         return this;
 220     }
 221 
 222     static PathOps test(String first, String... more) {
 223         return new PathOps(first, more);
 224     }
 225 
 226     static PathOps test(Path path) {
 227         return new PathOps(path.toString());
 228     }
 229 
 230 
 231     // -- PathOpss --
 232 
 233     static void header(String s) {
 234         out.println();
 235         out.println();
 236         out.println("-- " + s + " --");
 237     }
 238 
 239     static void doWindowsTests() {
 240         header("Windows specific tests");
 241         Path cwd = Paths.get("").toAbsolutePath();
 242 
 243         // construction
 244         test("C:\\")
 245             .string("C:\\");
 246         test("C:\\", "")
 247             .string("C:\\");
 248         test("C:\\", "foo")
 249             .string("C:\\foo");
 250         test("C:\\", "\\foo")
 251             .string("C:\\foo");
 252         test("C:\\", "foo\\")
 253             .string("C:\\foo");
 254         test("foo", "bar", "gus")
 255             .string("foo\\bar\\gus");
 256         test("")
 257             .string("");
 258         test("", "C:\\")
 259             .string("C:\\");
 260         test("", "foo", "", "bar", "", "\\gus")
 261             .string("foo\\bar\\gus");


 420             .subpath(0, 1, "foo");
 421         test("C:\\foo\\bar\\gus")
 422             .subpath(0, 1, "foo")
 423             .subpath(0, 2, "foo\\bar")
 424             .subpath(0, 3, "foo\\bar\\gus")
 425             .subpath(1, 2, "bar")
 426             .subpath(1, 3, "bar\\gus")
 427             .subpath(2, 3, "gus");
 428         test("\\\\server\\share\\foo")
 429             .subpath(0, 1, "foo");
 430         test("")
 431             .subpath(0, 1, "");
 432 
 433         // isAbsolute
 434         test("foo").notAbsolute();
 435         test("C:").notAbsolute();
 436         test("C:\\").absolute();
 437         test("C:\\abc").absolute();
 438         test("\\\\server\\share\\").absolute();
 439         test("").notAbsolute();
 440         test(cwd).absolute();
 441 
 442         // toAbsolutePath
 443         test("")
 444             .makeAbsolute()
 445             .absolute()
 446             .hasRoot()
 447             .string(cwd.toString());
 448         test(".")
 449             .makeAbsolute()
 450             .absolute()
 451             .hasRoot()
 452             .string(cwd.toString() + "\\.");
 453         test("foo")
 454             .makeAbsolute()
 455             .absolute()
 456             .hasRoot()
 457             .string(cwd.toString() + "\\foo");
 458 
 459         String rootAsString = cwd.getRoot().toString();
 460         if (rootAsString.length() == 3
 461                 && rootAsString.charAt(1) == ':'
 462                 && rootAsString.charAt(2) == '\\') {
 463             Path root = Paths.get(rootAsString.substring(0, 2));
 464 
 465             // C:
 466             test(root)
 467                 .makeAbsolute()
 468                 .absolute()
 469                 .hasRoot()
 470                 .string(cwd.toString());
 471 
 472             // C:.
 473             test(root + ".")
 474                 .makeAbsolute()
 475                 .absolute()
 476                 .hasRoot()
 477                 .string(cwd.toString() + "\\.");
 478 
 479             // C:foo
 480             test(root + "foo")
 481                 .makeAbsolute()
 482                 .absolute()
 483                 .hasRoot()
 484                 .string(cwd.toString() + "\\foo");
 485         }
 486 
 487         // resolve
 488         test("C:\\")
 489             .resolve("foo", "C:\\foo")
 490             .resolve("D:\\bar", "D:\\bar")
 491             .resolve("\\\\server\\share\\bar", "\\\\server\\share\\bar")
 492             .resolve("C:foo", "C:\\foo")
 493             .resolve("D:foo", "D:foo")
 494             .resolve("", "C:\\");
 495         test("\\")
 496             .resolve("foo", "\\foo")
 497             .resolve("D:bar", "D:bar")
 498             .resolve("C:\\bar", "C:\\bar")
 499             .resolve("\\\\server\\share\\bar", "\\\\server\\share\\bar")
 500             .resolve("\\foo", "\\foo")
 501             .resolve("", "\\");
 502         test("\\foo")
 503             .resolve("bar", "\\foo\\bar")
 504             .resolve("D:bar", "D:bar")
 505             .resolve("C:\\bar", "C:\\bar")


 555         test("C:\\foo\\bar")
 556             .resolveSibling("gus", "C:\\foo\\gus")
 557             .resolveSibling("D:\\bar", "D:\\bar")
 558             .resolveSibling("\\\\server\\share\\bar", "\\\\server\\share\\bar")
 559             .resolveSibling("C:bar", "C:\\foo\\bar")
 560             .resolveSibling("D:foo", "D:foo")
 561             .resolveSibling("", "C:\\foo");
 562         test("\\\\server\\share\\foo")
 563             .resolveSibling("bar", "\\\\server\\share\\bar")
 564             .resolveSibling("\\bar", "\\\\server\\share\\bar")
 565             .resolveSibling("D:\\bar", "D:\\bar")
 566             .resolveSibling("\\\\other\\share\\bar", "\\\\other\\share\\bar")
 567             .resolveSibling("D:bar", "D:bar")
 568             .resolveSibling("", "\\\\server\\share\\");
 569         test("")
 570             .resolveSibling("", "")
 571             .resolveSibling("foo", "foo")
 572             .resolveSibling("C:\\", "C:\\");
 573 
 574         // relativize
 575         test("foo")
 576             .relativize("foo", "")
 577             .relativize("bar", "..\\bar")
 578             .relativize("..", "..\\..")
 579             .relativize("", "..");
 580         test("foo\\bar")
 581             .relativize("foo\\bar", "")
 582             .relativize("foo", "..")
 583             .relativize("gus", "..\\..\\gus")
 584             .relativize("..", "..\\..\\..")
 585             .relativize("", "..\\..");
 586         test("C:\\a\\b\\c")
 587             .relativize("C:\\a", "..\\..")
 588             .relativize("C:\\a\\b\\c", "")
 589             .relativize("C:\\x", "..\\..\\..\\x");
 590         test("\\\\server\\share\\foo")
 591             .relativize("\\\\server\\share\\bar", "..\\bar")
 592             .relativize("\\\\server\\share\\foo", "");
 593         test("")

 594             .relativize("a", "a")
 595             .relativize("a\\b\\c", "a\\b\\c")
 596             .relativize("..", "..")
 597             .relativize("", "");
 598 
 599         // normalize
 600         test("C:\\")
 601             .normalize("C:\\");
 602         test("C:\\.")
 603             .normalize("C:\\");
 604         test("C:\\..")
 605             .normalize("C:\\");
 606         test("\\\\server\\share")
 607             .normalize("\\\\server\\share\\");
 608         test("\\\\server\\share\\.")
 609             .normalize("\\\\server\\share\\");
 610         test("\\\\server\\share\\..")
 611             .normalize("\\\\server\\share\\");
 612         test("C:")
 613             .normalize("C:");
 614         test("C:.")
 615             .normalize("C:");
 616         test("C:..")
 617             .normalize("C:..");


 731         // normalization at construction time (remove redundant and replace slashes)
 732         test("C:/a/b/c")
 733             .string("C:\\a\\b\\c")
 734             .root("C:\\")
 735             .parent("C:\\a\\b");
 736         test("C://a//b//c")
 737             .string("C:\\a\\b\\c")
 738             .root("C:\\")
 739             .parent("C:\\a\\b");
 740 
 741         // hashCode
 742         header("hashCode");
 743         int h1 = test("C:\\foo").path().hashCode();
 744         int h2 = test("c:\\FOO").path().hashCode();
 745         if (h1 != h2)
 746             throw new RuntimeException("PathOps failed");
 747     }
 748 
 749     static void doUnixTests() {
 750         header("Unix specific tests");
 751         Path cwd = Paths.get("").toAbsolutePath();
 752 
 753         // construction
 754         test("/")
 755             .string("/");
 756         test("/", "")
 757             .string("/");
 758         test("/", "foo")
 759             .string("/foo");
 760         test("/", "/foo")
 761             .string("/foo");
 762         test("/", "foo/")
 763             .string("/foo");
 764         test("foo", "bar", "gus")
 765             .string("foo/bar/gus");
 766         test("")
 767             .string("");
 768         test("", "/")
 769             .string("/");
 770         test("", "foo", "", "bar", "", "/gus")
 771             .string("foo/bar/gus");


 900             .subpath(0, 3, "foo/bar/gus");
 901         test("foo/bar/gus")
 902             .subpath(0, 1, "foo")
 903             .subpath(1, 2, "bar")
 904             .subpath(2, 3, "gus")
 905             .subpath(0, 2, "foo/bar")
 906             .subpath(1, 3, "bar/gus")
 907             .subpath(0, 3, "foo/bar/gus");
 908         test("")
 909             .subpath(0, 1, "");
 910 
 911         // isAbsolute
 912         test("/")
 913             .absolute();
 914         test("/tmp")
 915             .absolute();
 916         test("tmp")
 917             .notAbsolute();
 918         test("")
 919             .notAbsolute();
 920         test(cwd)
 921             .absolute();
 922 
 923         // toAbsolutePath
 924         test("/")
 925             .makeAbsolute()
 926             .absolute();
 927         test("/tmp")
 928             .makeAbsolute()
 929             .absolute();
 930         test("tmp")
 931             .makeAbsolute()
 932             .absolute();
 933         test("")
 934             .makeAbsolute()
 935             .absolute();
 936 
 937         // resolve
 938         test("/tmp")
 939             .resolve("foo", "/tmp/foo")
 940             .resolve("/foo", "/foo")
 941             .resolve("", "/tmp");
 942         test("tmp")
 943             .resolve("foo", "tmp/foo")
 944             .resolve("/foo", "/foo")
 945             .resolve("", "tmp");
 946         test("")
 947             .resolve("", "")
 948             .resolve("foo", "foo")
 949             .resolve("/foo", "/foo");
 950 
 951         // resolveSibling
 952         test("foo")
 953             .resolveSibling("bar", "bar")
 954             .resolveSibling("/bar", "/bar")
 955             .resolveSibling("", "");


< prev index next >