Skip to content

Commit

Permalink
core: add unit tests for 'isEqualOrParent`
Browse files Browse the repository at this point in the history
The following commit adds missing unit tests for
`uri.isEqualOrParent()`.

Signed-off-by: vince-fugnitto <[email protected]>
  • Loading branch information
vince-fugnitto committed Dec 16, 2020
1 parent 0761dcf commit 87f6133
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/core/src/common/uri.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,46 @@ describe('uri', () => {
expect(String(path)).equals('node_modules/typescript/lib');
});
});

describe('#isEqualOrParent()', () => {
it('should return `true` for `uris` which are equal', () => {
const a = new URI('file:///C:/projects/theia/foo/a.ts');
const b = new URI('file:///C:/projects/theia/foo/a.ts');
expect(a.isEqualOrParent(b)).equals(true);
});
it('should return `false` for `uris` which are not equal', () => {
const a = new URI('file:///C:/projects/theia/foo/a.ts');
const b = new URI('file:///C:/projects/theia/foo/b.ts');
expect(a.isEqualOrParent(b)).equals(false);
});

it('should return `false` for `uris` which are not the same scheme', () => {
const a = new URI('file:///C:/projects/theia/foo/a.ts').withScheme('a');
const b = new URI('file:///C:/projects/theia/foo/a.ts').withScheme('b');
expect(a.isEqualOrParent(b)).equals(false);
});

it('should return `true` for `uris` that are not case-sensitive equal, with case-sensitivity `off`', () => {
const a = new URI('file:///C:/projects/theia/foo/a.ts');
const b = new URI('file:///C:/projects/theia/foo/A.ts');
expect(a.isEqualOrParent(b, false)).equals(true);
});
it('should return `false` for `uris` that are not case-sensitive equal, with case-sensitivity `on`', () => {
const a = new URI('file:///C:/projects/theia/foo/a.ts');
const b = new URI('file:///C:/projects/theia/foo/A.ts');
expect(a.isEqualOrParent(b, true)).equals(false);
});

it('should return `true` for relative paths', () => {
const a = new URI('file:///C:/projects/'); // parent uri.
const b = new URI('file:///C:/projects/theia/foo');
expect(a.isEqualOrParent(b)).equals(true);
});
it('should return `false` for non-relative paths', () => {
const a = new URI('file:///C:/projects/a/'); // parent uri.
const b = new URI('file:///C:/projects/theia/foo');
expect(a.isEqualOrParent(b)).equals(false);
});
});

});

0 comments on commit 87f6133

Please sign in to comment.