diff options
Diffstat (limited to 'src/vs/base/test/common/map.test.ts')
-rw-r--r-- | src/vs/base/test/common/map.test.ts | 73 |
1 files changed, 68 insertions, 5 deletions
diff --git a/src/vs/base/test/common/map.test.ts b/src/vs/base/test/common/map.test.ts index c681cf92396..1e2a792cab8 100644 --- a/src/vs/base/test/common/map.test.ts +++ b/src/vs/base/test/common/map.test.ts @@ -371,7 +371,7 @@ suite('Map', () => { }); test('URIIterator', function () { - const iter = new UriIterator(() => false); + const iter = new UriIterator(() => false, () => false); iter.reset(URI.parse('file:///usr/bin/file.txt')); assert.strictEqual(iter.value(), 'file'); @@ -429,6 +429,58 @@ suite('Map', () => { assert.strictEqual(iter.hasNext(), false); }); + test('URIIterator - ignore query/fragment', function () { + const iter = new UriIterator(() => false, () => true); + iter.reset(URI.parse('file:///usr/bin/file.txt')); + + assert.strictEqual(iter.value(), 'file'); + // assert.strictEqual(iter.cmp('FILE'), 0); + assert.strictEqual(iter.cmp('file'), 0); + assert.strictEqual(iter.hasNext(), true); + iter.next(); + + assert.strictEqual(iter.value(), 'usr'); + assert.strictEqual(iter.hasNext(), true); + iter.next(); + + assert.strictEqual(iter.value(), 'bin'); + assert.strictEqual(iter.hasNext(), true); + iter.next(); + + assert.strictEqual(iter.value(), 'file.txt'); + assert.strictEqual(iter.hasNext(), false); + + + iter.reset(URI.parse('file://share/usr/bin/file.txt?foo')); + + // scheme + assert.strictEqual(iter.value(), 'file'); + // assert.strictEqual(iter.cmp('FILE'), 0); + assert.strictEqual(iter.cmp('file'), 0); + assert.strictEqual(iter.hasNext(), true); + iter.next(); + + // authority + assert.strictEqual(iter.value(), 'share'); + assert.strictEqual(iter.cmp('SHARe'), 0); + assert.strictEqual(iter.hasNext(), true); + iter.next(); + + // path + assert.strictEqual(iter.value(), 'usr'); + assert.strictEqual(iter.hasNext(), true); + iter.next(); + + // path + assert.strictEqual(iter.value(), 'bin'); + assert.strictEqual(iter.hasNext(), true); + iter.next(); + + // path + assert.strictEqual(iter.value(), 'file.txt'); + assert.strictEqual(iter.hasNext(), false); + }); + function assertTstDfs<E>(trie: TernarySearchTree<string, E>, ...elements: [string, E][]) { assert.ok(trie._isBalanced(), 'TST is not balanced'); @@ -901,7 +953,7 @@ suite('Map', () => { }); test('TernarySearchTree (URI) - basics', function () { - let trie = new TernarySearchTree<URI, number>(new UriIterator(() => false)); + let trie = new TernarySearchTree<URI, number>(new UriIterator(() => false, () => false)); trie.set(URI.file('/user/foo/bar'), 1); trie.set(URI.file('/user/foo'), 2); @@ -919,9 +971,20 @@ suite('Map', () => { assert.strictEqual(trie.findSubstr(URI.file('/user/foo/bar/far/boo')), 1); }); + test('TernarySearchTree (URI) - query parameters', function () { + let trie = new TernarySearchTree<URI, number>(new UriIterator(() => false, () => true)); + const root = URI.parse('memfs:/?param=1'); + trie.set(root, 1); + + assert.strictEqual(trie.get(URI.parse('memfs:/?param=1')), 1); + + assert.strictEqual(trie.findSubstr(URI.parse('memfs:/?param=1')), 1); + assert.strictEqual(trie.findSubstr(URI.parse('memfs:/aaa?param=1')), 1); + }); + test('TernarySearchTree (URI) - lookup', function () { - const map = new TernarySearchTree<URI, number>(new UriIterator(() => false)); + const map = new TernarySearchTree<URI, number>(new UriIterator(() => false, () => false)); map.set(URI.parse('http://foo.bar/user/foo/bar'), 1); map.set(URI.parse('http://foo.bar/user/foo?query'), 2); map.set(URI.parse('http://foo.bar/user/foo?QUERY'), 3); @@ -938,7 +1001,7 @@ suite('Map', () => { test('TernarySearchTree (URI) - lookup, casing', function () { - const map = new TernarySearchTree<URI, number>(new UriIterator(uri => /^https?$/.test(uri.scheme))); + const map = new TernarySearchTree<URI, number>(new UriIterator(uri => /^https?$/.test(uri.scheme), () => false)); map.set(URI.parse('http://foo.bar/user/foo/bar'), 1); assert.strictEqual(map.get(URI.parse('http://foo.bar/USER/foo/bar')), 1); @@ -948,7 +1011,7 @@ suite('Map', () => { test('TernarySearchTree (URI) - superstr', function () { - const map = new TernarySearchTree<URI, number>(new UriIterator(() => false)); + const map = new TernarySearchTree<URI, number>(new UriIterator(() => false, () => false)); map.set(URI.file('/user/foo/bar'), 1); map.set(URI.file('/user/foo'), 2); map.set(URI.file('/user/foo/flip/flop'), 3); |