Skip to content

Commit

Permalink
start CompletionModel tests, #9286
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Jul 15, 2016
1 parent 9abe8bb commit e19c504
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/vs/editor/contrib/suggest/common/completionModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,24 @@ export namespace CompletionItemComparator {
}

export function snippetUpComparator(a: CompletionItem, b: CompletionItem): number {
if (a.suggestion.type === 'snippet') {
return -1;
} else if (b.suggestion.type === 'snippet') {
return 1;
if (a.suggestion.type !== b.suggestion.type) {
if (a.suggestion.type === 'snippet') {
return -1;
} else if (b.suggestion.type === 'snippet') {
return 1;
}
} else {
return defaultComparator(a, b);
}
}

export function snippetDownComparator(a: CompletionItem, b: CompletionItem): number {
if (a.suggestion.type === 'snippet') {
return 1;
} else if (b.suggestion.type === 'snippet') {
return -1;
if (a.suggestion.type !== b.suggestion.type) {
if (a.suggestion.type === 'snippet') {
return 1;
} else if (b.suggestion.type === 'snippet') {
return -1;
}
} else {
return defaultComparator(a, b);
}
Expand Down
72 changes: 72 additions & 0 deletions src/vs/editor/contrib/suggest/test/common/completionModel.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';

import * as assert from 'assert';
import {ISuggestResult2} from 'vs/editor/contrib/suggest/common/suggest';
import {CompletionModel, CompletionItemComparator} from 'vs/editor/contrib/suggest/common/completionModel';


const mixedSuggestions = <ISuggestResult2>{
currentWord: '',
incomplete: false,
support: undefined,
suggestions: [{
type: 'snippet',
label: 'zzz',
codeSnippet: 'zzz'
}, {
type: 'snippet',
label: 'aaa',
codeSnippet: 'aaa'
}, {
type: 'property',
label: 'fff',
codeSnippet: 'fff'
}]
};


suite('CompletionModel', function() {

test('sort - normal', function() {
const model = new CompletionModel([mixedSuggestions], '', CompletionItemComparator.defaultComparator, false);
assert.equal(model.items.length, 3);

const [one, two, three] = model.items;
assert.equal(one.suggestion.label, 'aaa');
assert.equal(two.suggestion.label, 'fff');
assert.equal(three.suggestion.label, 'zzz');
});

test('sort - snippet up', function() {
const model = new CompletionModel([mixedSuggestions], '', CompletionItemComparator.snippetUpComparator, false);
assert.equal(model.items.length, 3);

const [one, two, three] = model.items;
assert.equal(one.suggestion.label, 'aaa');
assert.equal(two.suggestion.label, 'zzz');
assert.equal(three.suggestion.label, 'fff');
});

test('sort - snippet down', function() {
const model = new CompletionModel([mixedSuggestions], '', CompletionItemComparator.snippetDownComparator, false);
assert.equal(model.items.length, 3);

const [one, two, three] = model.items;
assert.equal(one.suggestion.label, 'fff');
assert.equal(two.suggestion.label, 'aaa');
assert.equal(three.suggestion.label, 'zzz');
});

test('ignore snippets', function() {

const model = new CompletionModel([mixedSuggestions], '', CompletionItemComparator.defaultComparator, true);
assert.equal(model.items.length, 1);

const [one] = model.items;
assert.equal(one.suggestion.label, 'fff');
});
});

0 comments on commit e19c504

Please sign in to comment.