-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(Glob): BC-BREAK Use RegExp to implement Glob SWITCH glob to …
…use RegExp Previously, trailing single wildcards '*' could be "zero-length" matches. The glob `foo.*` would match `foo` and `foo.bar` but not `foo.bar.baz`. Likewise, the glob `foo.*.*` would also match `foo`. Now, all single wildcards match one segment. The glob `foo.*` matches `foo.bar` but does not match `foo`. Use `foo.**` instead to match zero or more segments. test(Glob): Add more glob tests docs(Glob): Document glob Closes #2965
- Loading branch information
1 parent
4ede2fb
commit d1dff31
Showing
6 changed files
with
110 additions
and
66 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,65 @@ | ||
import {Glob} from "../../src/common/glob"; | ||
|
||
describe('Glob', function() { | ||
it('should match exact strings', function() { | ||
var state = 'about.person.item'; | ||
|
||
expect(new Glob('about.person.item').matches(state)).toBe(true); | ||
expect(new Glob('about.person.item.foo').matches(state)).toBe(false); | ||
expect(new Glob('foo.about.person.item').matches(state)).toBe(false); | ||
}); | ||
|
||
it('with a single wildcard (*) should match a top level state', function() { | ||
var glob = new Glob('*'); | ||
|
||
expect(glob.matches('foo')).toBe(true); | ||
expect(glob.matches('bar')).toBe(true); | ||
expect(glob.matches('baz')).toBe(true); | ||
expect(glob.matches('foo.bar')).toBe(false); | ||
expect(glob.matches('.baz')).toBe(false); | ||
}); | ||
|
||
it('with a single wildcard (*) should match any single non-empty segment', function() { | ||
var state = 'about.person.item'; | ||
|
||
expect(new Glob('*.person.item').matches(state)).toBe(true); | ||
expect(new Glob('*.*.item').matches(state)).toBe(true); | ||
expect(new Glob('*.person.*').matches(state)).toBe(true); | ||
expect(new Glob('*.*.*').matches(state)).toBe(true); | ||
|
||
expect(new Glob('*.*.*.*').matches(state)).toBe(false); | ||
expect(new Glob('*.*.person.item').matches(state)).toBe(false); | ||
expect(new Glob('*.person.item.foo').matches(state)).toBe(false); | ||
expect(new Glob('foo.about.person.*').matches(state)).toBe(false); | ||
}); | ||
|
||
it('with a double wildcard (**) should match any valid state name', function() { | ||
var glob = new Glob('**'); | ||
|
||
expect(glob.matches('foo')).toBe(true); | ||
expect(glob.matches('bar')).toBe(true); | ||
expect(glob.matches('foo.bar')).toBe(true); | ||
}); | ||
|
||
it('with a double wildcard (**) should match zero or more segments', function() { | ||
var state = 'about.person.item'; | ||
|
||
expect(new Glob('**').matches(state)).toBe(true); | ||
expect(new Glob('**.**').matches(state)).toBe(true); | ||
expect(new Glob('**.*').matches(state)).toBe(true); | ||
expect(new Glob('**.person.item').matches(state)).toBe(true); | ||
expect(new Glob('**.person.**').matches(state)).toBe(true); | ||
expect(new Glob('**.person.**.item').matches(state)).toBe(true); | ||
expect(new Glob('**.person.**.*').matches(state)).toBe(true); | ||
expect(new Glob('**.item').matches(state)).toBe(true); | ||
expect(new Glob('about.**').matches(state)).toBe(true); | ||
expect(new Glob('about.**.person.item').matches(state)).toBe(true); | ||
expect(new Glob('about.person.item.**').matches(state)).toBe(true); | ||
expect(new Glob('**.about.person.item').matches(state)).toBe(true); | ||
expect(new Glob('**.about.**.person.item.**').matches(state)).toBe(true); | ||
expect(new Glob('**.**.about.person.item').matches(state)).toBe(true); | ||
|
||
expect(new Glob('**.person.**.*.*').matches(state)).toBe(false); | ||
expect(new Glob('**.person.**.*.item').matches(state)).toBe(false); | ||
}); | ||
}); |
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