Skip to content

Commit

Permalink
update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoper De Leon committed Mar 9, 2018
1 parent d04d80f commit 763c41d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 0 additions & 2 deletions src/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ export function getWinOrigin(win) {
export function parseUrl(url, opt_nocache) {
if (!a) {
a = /** @type {!HTMLAnchorElement} */ (self.document.createElement('a'));

// Currently url LRUcache capacity is limited to 100
cache = self.UrlCache || (self.UrlCache = new LRUCache(100));
}

Expand Down
13 changes: 10 additions & 3 deletions test/functional/test-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ describe('getWinOrigin', () => {
},
})).to.equal('null');
});



});


Expand Down Expand Up @@ -120,6 +117,16 @@ describe('parseUrl', () => {
const a2 = parseUrl(url);
expect(a1).to.equal(a2);
});
it('caches up to 100 results', () => {
const url = 'https://foo.com:123/abc?123#foo';
const a1 = parseUrl(url);
// cache 99 more urls in order to reach max capacity of LRU cache: 100
for (let i = 0; i < 100; i++) {
parseUrl(`${url}-${i}`);
}
const a2 = parseUrl(url);
expect(a1).to.not.equal(a2);
});
it('should handle ports', () => {
compareParse('https://foo.com:123/abc?123#foo', {
href: 'https://foo.com:123/abc?123#foo',
Expand Down
4 changes: 4 additions & 0 deletions test/functional/utils/test-lru-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ describe('LRUCache', () => {
}
});

it('should create a protype-less object for caching', () => {
expect(cache.cache_.constructor).to.be.undefined;
});

it('should never be over cap', () => {
for (let i = 5; i < 10; i++) {
cache.put(i, i);
Expand Down

0 comments on commit 763c41d

Please sign in to comment.