Skip to content

Commit 5ee2dff

Browse files
committed
Move the fileprovider mock to its own file and add a doCompletion unit test
1 parent e7813e5 commit 5ee2dff

File tree

3 files changed

+118
-50
lines changed

3 files changed

+118
-50
lines changed
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Simon Waelti. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
'use strict';
6+
7+
import * as assert from 'assert';
8+
import { Position } from 'vscode-languageserver-textdocument';
9+
import { FileProviderMock, documents } from './fileProviderMock';
10+
import {
11+
LanguageService,
12+
getMacroLanguageService,
13+
} from '../macroLanguageService';
14+
15+
import {
16+
TextDocument,
17+
LanguageSettings,
18+
CompletionList
19+
} from '../macroLanguageTypes';
20+
21+
import {
22+
Parser,
23+
} from '../parser/macroParser';
24+
25+
declare type completionFunction = (document, position, macroFile, settings) => CompletionList | null;
26+
27+
function assertCompletion(service: LanguageService, input: string, position:Position, expected: string, f:completionFunction) {
28+
29+
let settings:LanguageSettings = {
30+
keywords:[],
31+
sequence: {
32+
base: 1000,
33+
increment: 5
34+
}
35+
};
36+
37+
let document = TextDocument.create(`test://test/test.src`, 'macro', 0, input);
38+
let macroFile = service.parseMacroFile(document);
39+
let result = f(document, position, macroFile, settings);
40+
41+
assert.strictEqual(result.items[7].textEdit.newText, expected, input);
42+
}
43+
44+
let fileProviderMock = new FileProviderMock();
45+
let service = getMacroLanguageService({ fileProvider: fileProviderMock });
46+
47+
suite('Completion', () => {
48+
49+
test('N-Number completion', function () {
50+
51+
assertCompletion(service, 'O 100\nN10\nN\n',
52+
{ line:2,character:1},
53+
'N${1:15} $0',
54+
service.doComplete.bind(service)
55+
);
56+
});
57+
});
58+
59+
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import {
2+
TextDocument,
3+
MacroFileProvider,
4+
MacroFileType,
5+
MacroFileInfo,
6+
FileProviderParams,
7+
} from '../macroLanguageTypes';
8+
9+
import {
10+
Parser,
11+
} from '../parser/macroParser';
12+
13+
export { FileProviderMock };
14+
15+
export const documents: Map<string, TextDocument> = new Map<string, TextDocument>();
16+
17+
class FileProviderMock implements MacroFileProvider {
18+
19+
constructor() {}
20+
21+
public get(file: string): MacroFileInfo | undefined {
22+
const document = documents.get(file);
23+
const macroFile = new Parser(this).parseMacroFile(document);
24+
return {
25+
document: document,
26+
macrofile: macroFile,
27+
version: 1,
28+
type: this.getMacroFileType(file)
29+
};
30+
}
31+
32+
public getAll(param?:FileProviderParams) {
33+
let types:MacroFileInfo[] = [];
34+
for (const file of documents.keys()) {
35+
let type = this.get(file);
36+
if (type){
37+
types.push(type);
38+
}
39+
}
40+
return types;
41+
}
42+
43+
public resolveReference(ref: string, base?: string): string | undefined {
44+
return undefined;
45+
}
46+
47+
public getMacroFileType(file: string) : MacroFileType {
48+
var fileExt = file.split('.').pop().toLocaleLowerCase();
49+
switch(fileExt) {
50+
case 'def':
51+
return MacroFileType.DEF;
52+
case 'lnk':
53+
return MacroFileType.LNK;
54+
default:
55+
return MacroFileType.SRC;
56+
}
57+
}
58+
}

Diff for: server/src/macroLanguageService/test/navigation.test.ts

+1-50
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@
66

77
import * as assert from 'assert';
88
import { Position } from 'vscode-languageserver-textdocument';
9+
import { FileProviderMock, documents } from './fileProviderMock';
910
import {
1011
LanguageService,
1112
getMacroLanguageService,
1213
} from '../macroLanguageService';
1314
import {
1415
TextDocument,
15-
MacroFileProvider,
1616
Location,
17-
MacroFileType,
18-
MacroFileInfo,
19-
FileProviderParams,
2017
Range
2118
} from '../macroLanguageTypes';
2219

@@ -27,52 +24,6 @@ import {
2724
declare type locationFunction = (document, position, macroFile) => Location | null;
2825
declare type locationsFunction = (document, position, macroFile) => Location[];
2926

30-
const documents: Map<string, TextDocument> = new Map<string, TextDocument>();
31-
32-
class FileProviderMock implements MacroFileProvider {
33-
34-
constructor() {}
35-
36-
public get(file: string): MacroFileInfo | undefined {
37-
const document = documents.get(file);
38-
const macroFile = new Parser(this).parseMacroFile(document);
39-
return {
40-
document: document,
41-
macrofile: macroFile,
42-
version: 1,
43-
type: this.getMacroFileType(file)
44-
};
45-
}
46-
47-
public getAll(param?:FileProviderParams) {
48-
let types:MacroFileInfo[] = [];
49-
for (const file of documents.keys()) {
50-
let type = this.get(file);
51-
if (type){
52-
types.push(type);
53-
}
54-
}
55-
return types;
56-
}
57-
58-
public resolveReference(ref: string, base?: string): string | undefined {
59-
return undefined;
60-
}
61-
62-
public getMacroFileType(file: string) : MacroFileType {
63-
var fileExt = file.split('.').pop().toLocaleLowerCase();
64-
switch(fileExt) {
65-
case 'def':
66-
return MacroFileType.DEF;
67-
case 'lnk':
68-
return MacroFileType.LNK;
69-
default:
70-
return MacroFileType.SRC;
71-
}
72-
}
73-
}
74-
75-
7627
function assertLocation(service: LanguageService, input: string, position:Position, location:Location, f:locationFunction) {
7728

7829
let uri = 'test://test/test.src';

0 commit comments

Comments
 (0)