Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: add unit tests for 'isEqualOrParent` #8876

Merged
merged 1 commit into from
Dec 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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('a:///C:/projects/theia/foo/a.ts');
const b = new URI('b:///C:/projects/theia/foo/a.ts');
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 parent 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-parent paths', () => {
const a = new URI('file:///C:/projects/a/'); // non-parent uri.
const b = new URI('file:///C:/projects/theia/foo');
expect(a.isEqualOrParent(b)).equals(false);
});
});

});