From 87f6133b487dc850941cdda53c729866d26f77c4 Mon Sep 17 00:00:00 2001 From: vince-fugnitto Date: Wed, 16 Dec 2020 17:13:12 -0500 Subject: [PATCH] core: add unit tests for 'isEqualOrParent` The following commit adds missing unit tests for `uri.isEqualOrParent()`. Signed-off-by: vince-fugnitto --- packages/core/src/common/uri.spec.ts | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/packages/core/src/common/uri.spec.ts b/packages/core/src/common/uri.spec.ts index 4e8184681e4c7..82b7993358e64 100644 --- a/packages/core/src/common/uri.spec.ts +++ b/packages/core/src/common/uri.spec.ts @@ -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); + }); + }); + });