-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import * as assert from 'assert'; | ||
|
||
import * as manager from './patterns'; | ||
|
||
describe('Managers → Pattern', () => { | ||
describe('.transform', () => { | ||
it('should do not change patterns', () => { | ||
const expected = [ | ||
'directory/file.md', | ||
'files{.txt,/file.md}' | ||
]; | ||
|
||
const actual = manager.transform([ | ||
'directory/file.md', | ||
'files{.txt,/file.md}' | ||
]); | ||
|
||
assert.deepStrictEqual(actual, expected); | ||
}); | ||
|
||
it('should do not change the device path in patterns with UNC parts', () => { | ||
const expected = [ | ||
'//?/D:/', | ||
'//./D:/', | ||
'//LOCALHOST/d$/', | ||
'//127.0.0.1/d$/', | ||
'//./UNC/LOCALHOST/d$/' | ||
]; | ||
|
||
const actual = manager.transform([ | ||
'//?//D://', | ||
'//.//D:///', | ||
'//LOCALHOST//d$//', | ||
'//127.0.0.1///d$//', | ||
'//./UNC////LOCALHOST///d$//' | ||
]); | ||
|
||
assert.deepStrictEqual(actual, expected); | ||
}); | ||
|
||
it('should remove duplicate slashes in the middle and the of the pattern', () => { | ||
const expected = ['a/b', 'b/c', 'c/d/', '//?/D:/']; | ||
|
||
const actual = manager.transform(['a//b', 'b///c', 'c/d///', '//?//D://']); | ||
|
||
assert.deepStrictEqual(actual, expected); | ||
}); | ||
|
||
it('should form double slashes at the beginning of the pattern', () => { | ||
const expected = ['//*', '//?', '//?/D:/']; | ||
|
||
const actual = manager.transform(['///*', '////?', '///?/D:/']); | ||
|
||
assert.deepStrictEqual(actual, expected); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Matches a sequence of two or more consecutive slashes, excluding the first two slashes at the beginning of the string. | ||
* The latter is due to the presence of the device path at the beginning of the UNC path. | ||
*/ | ||
const DOUBLE_SLASH_RE = /(?<!^)\/{2,}/g; | ||
|
||
export function transform(patterns: string[]): string[] { | ||
return patterns.map((pattern) => removeDuplicatedSlashes(pattern)); | ||
} | ||
|
||
/** | ||
* This package only works with forward slashes as a path separator. | ||
* Because of this, we cannot use the standard `path.normalize` method, because on Windows platform it will use of backslashes. | ||
*/ | ||
function removeDuplicatedSlashes(pattern: string): string { | ||
return pattern.replace(DOUBLE_SLASH_RE, '/'); | ||
} |