File tree 2 files changed +14
-1
lines changed
lib/src/main/java/com/diffplug/spotless
testlib/src/test/java/com/diffplug/spotless
2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -119,4 +119,13 @@ public static String pathNativeToUnix(String pathNative) {
119
119
public static String pathUnixToNative (String pathUnix ) {
120
120
return LineEnding .nativeIsWin () ? pathUnix .replace ('/' , '\\' ) : pathUnix ;
121
121
}
122
+
123
+ /** Asserts that child is a subpath of root. and returns the subpath. */
124
+ public static String subpath (String root , String child ) {
125
+ if (child .startsWith (root )) {
126
+ return child .substring (root .length ());
127
+ } else {
128
+ throw new IllegalArgumentException ("Expected '" + child + "' to start with '" + root + "'" );
129
+ }
130
+ }
122
131
}
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016 DiffPlug
2
+ * Copyright 2016-2020 DiffPlug
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -56,4 +56,8 @@ private List<File> getTestFiles(final String[] paths) throws IOException {
56
56
return result ;
57
57
}
58
58
59
+ @ Test
60
+ public void testSubpath () {
61
+ assertThat (FileSignature .subpath ("root/" , "root/child" )).isEqualTo ("child" );
62
+ }
59
63
}
You can’t perform that action at this time.
0 commit comments