brighterscript 1.0.0-alpha.14 → 1.0.0-alpha.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +83 -1
- package/README.md +28 -9
- package/dist/Cache.d.ts +2 -7
- package/dist/Cache.js +4 -13
- package/dist/Cache.js.map +1 -1
- package/dist/DependencyGraph.js +5 -4
- package/dist/DependencyGraph.js.map +1 -1
- package/dist/DiagnosticMessages.d.ts +21 -1
- package/dist/DiagnosticMessages.js +21 -1
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/Logger.js +5 -5
- package/dist/Logger.js.map +1 -1
- package/dist/Program.d.ts +3 -3
- package/dist/Program.js +9 -7
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.js +1 -1
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +16 -11
- package/dist/Scope.js +42 -12
- package/dist/Scope.js.map +1 -1
- package/dist/XmlScope.d.ts +3 -3
- package/dist/XmlScope.js +1 -1
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/AstEditor.d.ts +6 -0
- package/dist/astUtils/AstEditor.js +10 -0
- package/dist/astUtils/AstEditor.js.map +1 -1
- package/dist/astUtils/AstEditor.spec.js +37 -0
- package/dist/astUtils/AstEditor.spec.js.map +1 -1
- package/dist/astUtils/creators.d.ts +10 -6
- package/dist/astUtils/creators.js +93 -12
- package/dist/astUtils/creators.js.map +1 -1
- package/dist/astUtils/creators.spec.js +10 -0
- package/dist/astUtils/creators.spec.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +7 -2
- package/dist/astUtils/reflection.js +19 -3
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +5 -4
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +3 -1
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +2 -0
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.d.ts +4 -1
- package/dist/bscPlugin/BscPlugin.js +16 -0
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +1 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +38 -2
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +28 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.d.ts +8 -0
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js +40 -0
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +1 -0
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +32 -0
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/validation/BrsFileValidator.d.ts +9 -0
- package/dist/bscPlugin/validation/BrsFileValidator.js +66 -0
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -0
- package/dist/bscPlugin/validation/ScopeValidator.d.ts +11 -0
- package/dist/bscPlugin/validation/ScopeValidator.js +94 -0
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -0
- package/dist/diagnosticUtils.js +3 -3
- package/dist/diagnosticUtils.js.map +1 -1
- package/dist/examples/plugins/removePrint.js +12 -14
- package/dist/examples/plugins/removePrint.js.map +1 -1
- package/dist/files/BrsFile.Class.spec.js +22 -23
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +10 -3
- package/dist/files/BrsFile.js +133 -49
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +299 -123
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.d.ts +5 -5
- package/dist/files/XmlFile.js +3 -3
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/XmlFile.spec.js +9 -9
- package/dist/files/XmlFile.spec.js.map +1 -1
- package/dist/interfaces.d.ts +29 -37
- package/dist/lexer/Lexer.spec.js +8 -0
- package/dist/lexer/Lexer.spec.js.map +1 -1
- package/dist/lexer/TokenKind.d.ts +2 -0
- package/dist/lexer/TokenKind.js +5 -0
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/parser/Expression.d.ts +85 -21
- package/dist/parser/Expression.js +177 -53
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +1 -1
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +12 -3
- package/dist/parser/Parser.js +156 -56
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.js +57 -2
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/Statement.d.ts +94 -30
- package/dist/parser/Statement.js +281 -106
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/tests/statement/Enum.spec.d.ts +1 -0
- package/dist/parser/tests/statement/Enum.spec.js +774 -0
- package/dist/parser/tests/statement/Enum.spec.js.map +1 -0
- package/dist/parser/tests/statement/For.spec.d.ts +1 -0
- package/dist/parser/tests/statement/For.spec.js +46 -0
- package/dist/parser/tests/statement/For.spec.js.map +1 -0
- package/dist/parser/tests/statement/ForEach.spec.d.ts +1 -0
- package/dist/parser/tests/statement/ForEach.spec.js +37 -0
- package/dist/parser/tests/statement/ForEach.spec.js.map +1 -0
- package/dist/types/BooleanType.d.ts +4 -2
- package/dist/types/BooleanType.js +5 -1
- package/dist/types/BooleanType.js.map +1 -1
- package/dist/types/DoubleType.d.ts +2 -0
- package/dist/types/DoubleType.js +5 -1
- package/dist/types/DoubleType.js.map +1 -1
- package/dist/types/DynamicType.d.ts +2 -0
- package/dist/types/DynamicType.js +5 -1
- package/dist/types/DynamicType.js.map +1 -1
- package/dist/types/FloatType.d.ts +3 -1
- package/dist/types/FloatType.js +5 -1
- package/dist/types/FloatType.js.map +1 -1
- package/dist/types/FunctionType.d.ts +2 -1
- package/dist/types/FunctionType.js +11 -8
- package/dist/types/FunctionType.js.map +1 -1
- package/dist/types/FunctionType.spec.js +6 -0
- package/dist/types/FunctionType.spec.js.map +1 -1
- package/dist/types/IntegerType.d.ts +3 -1
- package/dist/types/IntegerType.js +5 -1
- package/dist/types/IntegerType.js.map +1 -1
- package/dist/types/InvalidType.d.ts +4 -2
- package/dist/types/InvalidType.js +5 -1
- package/dist/types/InvalidType.js.map +1 -1
- package/dist/types/LongIntegerType.d.ts +3 -1
- package/dist/types/LongIntegerType.js +5 -1
- package/dist/types/LongIntegerType.js.map +1 -1
- package/dist/types/ObjectType.d.ts +2 -1
- package/dist/types/ObjectType.js +4 -2
- package/dist/types/ObjectType.js.map +1 -1
- package/dist/types/StringType.d.ts +4 -2
- package/dist/types/StringType.js +5 -1
- package/dist/types/StringType.js.map +1 -1
- package/dist/types/UninitializedType.js.map +1 -1
- package/dist/types/UniversalFunctionType.d.ts +9 -0
- package/dist/types/UniversalFunctionType.js +25 -0
- package/dist/types/UniversalFunctionType.js.map +1 -0
- package/dist/types/VoidType.d.ts +4 -2
- package/dist/types/VoidType.js +5 -1
- package/dist/types/VoidType.js.map +1 -1
- package/dist/util.d.ts +12 -2
- package/dist/util.js +74 -44
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.js +3 -3
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +2 -3
|
@@ -0,0 +1,774 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const chai_1 = require("chai");
|
|
4
|
+
const Expression_1 = require("../../Expression");
|
|
5
|
+
const DiagnosticMessages_1 = require("../../../DiagnosticMessages");
|
|
6
|
+
const testHelpers_spec_1 = require("../../../testHelpers.spec");
|
|
7
|
+
const Parser_1 = require("../../Parser");
|
|
8
|
+
const util_1 = require("../../../util");
|
|
9
|
+
const Statement_1 = require("../../Statement");
|
|
10
|
+
const Program_1 = require("../../../Program");
|
|
11
|
+
const sinon_1 = require("sinon");
|
|
12
|
+
const vscode_languageserver_protocol_1 = require("vscode-languageserver-protocol");
|
|
13
|
+
const visitors_1 = require("../../../astUtils/visitors");
|
|
14
|
+
const reflection_1 = require("../../../astUtils/reflection");
|
|
15
|
+
const vscode_uri_1 = require("vscode-uri");
|
|
16
|
+
const sinon = (0, sinon_1.createSandbox)();
|
|
17
|
+
describe('EnumStatement', () => {
|
|
18
|
+
let rootDir = (0, util_1.standardizePath) `${process.cwd()}/.tmp/rootDir`;
|
|
19
|
+
let program;
|
|
20
|
+
let testTranspile = (0, testHelpers_spec_1.getTestTranspile)(() => [program, rootDir]);
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
program = new Program_1.Program({ rootDir: rootDir, sourceMap: true });
|
|
23
|
+
});
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
sinon.restore();
|
|
26
|
+
program.dispose();
|
|
27
|
+
});
|
|
28
|
+
it('parses empty enum statement', () => {
|
|
29
|
+
const parser = Parser_1.Parser.parse(`
|
|
30
|
+
enum SomeEnum
|
|
31
|
+
end enum
|
|
32
|
+
`, { mode: Parser_1.ParseMode.BrighterScript });
|
|
33
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
|
|
34
|
+
(0, chai_1.expect)(parser.ast.statements[0]).to.be.instanceOf(Statement_1.EnumStatement);
|
|
35
|
+
});
|
|
36
|
+
it('supports annotations above', () => {
|
|
37
|
+
const parser = Parser_1.Parser.parse(`
|
|
38
|
+
@someAnnotation
|
|
39
|
+
enum SomeEnum
|
|
40
|
+
end enum
|
|
41
|
+
`, { mode: Parser_1.ParseMode.BrighterScript });
|
|
42
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
|
|
43
|
+
(0, chai_1.expect)(parser.ast.statements[0].annotations[0].name).to.eql('someAnnotation');
|
|
44
|
+
});
|
|
45
|
+
it('constructs when missing enum name', () => {
|
|
46
|
+
const parser = Parser_1.Parser.parse(`
|
|
47
|
+
enum
|
|
48
|
+
end enum
|
|
49
|
+
`, { mode: Parser_1.ParseMode.BrighterScript });
|
|
50
|
+
(0, testHelpers_spec_1.expectDiagnostics)(parser, [
|
|
51
|
+
DiagnosticMessages_1.DiagnosticMessages.expectedIdentifier()
|
|
52
|
+
]);
|
|
53
|
+
(0, chai_1.expect)(parser.ast.statements[0]).to.be.instanceOf(Statement_1.EnumStatement);
|
|
54
|
+
});
|
|
55
|
+
it('collects uninitialized members', () => {
|
|
56
|
+
const parser = Parser_1.Parser.parse(`
|
|
57
|
+
enum Direction
|
|
58
|
+
up
|
|
59
|
+
down
|
|
60
|
+
left
|
|
61
|
+
right
|
|
62
|
+
end enum
|
|
63
|
+
`, { mode: Parser_1.ParseMode.BrighterScript });
|
|
64
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
|
|
65
|
+
(0, chai_1.expect)(parser.ast.statements[0].getMembers().map(x => x.tokens.name.text)).to.eql([
|
|
66
|
+
'up',
|
|
67
|
+
'down',
|
|
68
|
+
'left',
|
|
69
|
+
'right'
|
|
70
|
+
]);
|
|
71
|
+
});
|
|
72
|
+
it('collects int-initialized members', () => {
|
|
73
|
+
const parser = Parser_1.Parser.parse(`
|
|
74
|
+
enum Direction
|
|
75
|
+
up = 1
|
|
76
|
+
down = 2
|
|
77
|
+
left = 3
|
|
78
|
+
right = 4
|
|
79
|
+
end enum
|
|
80
|
+
`, { mode: Parser_1.ParseMode.BrighterScript });
|
|
81
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
|
|
82
|
+
const values = parser.ast.statements[0].getMembers().map(x => x.value);
|
|
83
|
+
(0, testHelpers_spec_1.expectInstanceOf)(values, [
|
|
84
|
+
Expression_1.LiteralExpression,
|
|
85
|
+
Expression_1.LiteralExpression,
|
|
86
|
+
Expression_1.LiteralExpression,
|
|
87
|
+
Expression_1.LiteralExpression
|
|
88
|
+
]);
|
|
89
|
+
(0, chai_1.expect)(values.map(x => x.token.text)).to.eql([
|
|
90
|
+
'1',
|
|
91
|
+
'2',
|
|
92
|
+
'3',
|
|
93
|
+
'4'
|
|
94
|
+
]);
|
|
95
|
+
});
|
|
96
|
+
it('collects string-initialized members', () => {
|
|
97
|
+
const parser = Parser_1.Parser.parse(`
|
|
98
|
+
enum Direction
|
|
99
|
+
up = "u"
|
|
100
|
+
down = "d"
|
|
101
|
+
left = "l"
|
|
102
|
+
right = "r"
|
|
103
|
+
end enum
|
|
104
|
+
`, { mode: Parser_1.ParseMode.BrighterScript });
|
|
105
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
|
|
106
|
+
const values = parser.ast.statements[0].getMembers().map(x => x.value);
|
|
107
|
+
(0, testHelpers_spec_1.expectInstanceOf)(values, [
|
|
108
|
+
Expression_1.LiteralExpression,
|
|
109
|
+
Expression_1.LiteralExpression,
|
|
110
|
+
Expression_1.LiteralExpression,
|
|
111
|
+
Expression_1.LiteralExpression
|
|
112
|
+
]);
|
|
113
|
+
(0, chai_1.expect)(values.map(x => x.token.text)).to.eql([
|
|
114
|
+
'"u"',
|
|
115
|
+
'"d"',
|
|
116
|
+
'"l"',
|
|
117
|
+
'"r"'
|
|
118
|
+
]);
|
|
119
|
+
});
|
|
120
|
+
it('flags when used in brs mode', () => {
|
|
121
|
+
const parser = Parser_1.Parser.parse(`
|
|
122
|
+
enum Direction
|
|
123
|
+
up = "u"
|
|
124
|
+
down = "d"
|
|
125
|
+
left = "l"
|
|
126
|
+
right = "r"
|
|
127
|
+
end enum
|
|
128
|
+
`, { mode: Parser_1.ParseMode.BrightScript });
|
|
129
|
+
(0, testHelpers_spec_1.expectDiagnostics)(parser, [
|
|
130
|
+
DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('enum declarations')
|
|
131
|
+
]);
|
|
132
|
+
});
|
|
133
|
+
it('allows enum at top of file', () => {
|
|
134
|
+
const parser = Parser_1.Parser.parse(`
|
|
135
|
+
enum Direction
|
|
136
|
+
value1
|
|
137
|
+
end enum
|
|
138
|
+
|
|
139
|
+
interface Person
|
|
140
|
+
name as string
|
|
141
|
+
end interface
|
|
142
|
+
`, { mode: Parser_1.ParseMode.BrighterScript });
|
|
143
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
|
|
144
|
+
(0, chai_1.expect)(parser.statements[0]).instanceof(Statement_1.EnumStatement);
|
|
145
|
+
(0, chai_1.expect)(parser.statements[1]).instanceof(Statement_1.InterfaceStatement);
|
|
146
|
+
});
|
|
147
|
+
it('allows enum at bottom of file', () => {
|
|
148
|
+
const parser = Parser_1.Parser.parse(`
|
|
149
|
+
interface Person
|
|
150
|
+
name as string
|
|
151
|
+
end interface
|
|
152
|
+
|
|
153
|
+
enum Direction
|
|
154
|
+
value1
|
|
155
|
+
end enum
|
|
156
|
+
`, { mode: Parser_1.ParseMode.BrighterScript });
|
|
157
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
|
|
158
|
+
(0, chai_1.expect)(parser.statements[0]).instanceof(Statement_1.InterfaceStatement);
|
|
159
|
+
(0, chai_1.expect)(parser.statements[1]).instanceof(Statement_1.EnumStatement);
|
|
160
|
+
});
|
|
161
|
+
it('allows enum in namespace', () => {
|
|
162
|
+
const parser = Parser_1.Parser.parse(`
|
|
163
|
+
namespace entities
|
|
164
|
+
enum Person
|
|
165
|
+
name
|
|
166
|
+
end enum
|
|
167
|
+
end namespace
|
|
168
|
+
|
|
169
|
+
enum Direction
|
|
170
|
+
up
|
|
171
|
+
end enum
|
|
172
|
+
`, { mode: Parser_1.ParseMode.BrighterScript });
|
|
173
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
|
|
174
|
+
(0, chai_1.expect)(parser.references.enumStatements.map(x => x.fullName)).to.eql([
|
|
175
|
+
'entities.Person',
|
|
176
|
+
'Direction'
|
|
177
|
+
]);
|
|
178
|
+
});
|
|
179
|
+
describe('validation', () => {
|
|
180
|
+
it('catches duplicate enums from same file', () => {
|
|
181
|
+
program.setFile('source/main.bs', `
|
|
182
|
+
enum Direction
|
|
183
|
+
up
|
|
184
|
+
end enum
|
|
185
|
+
|
|
186
|
+
enum Direction
|
|
187
|
+
up
|
|
188
|
+
end enum
|
|
189
|
+
`);
|
|
190
|
+
program.validate();
|
|
191
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.duplicateEnumDeclaration('source', 'Direction')), { relatedInformation: [{
|
|
192
|
+
location: vscode_languageserver_protocol_1.Location.create(vscode_uri_1.URI.file((0, util_1.standardizePath) `${rootDir}/source/main.bs`).toString(), util_1.util.createRange(1, 21, 1, 30)),
|
|
193
|
+
message: 'Enum declared here'
|
|
194
|
+
}] })]);
|
|
195
|
+
});
|
|
196
|
+
it('catches duplicate enums from different files in same scope', () => {
|
|
197
|
+
program.setFile('source/main.bs', `
|
|
198
|
+
enum Direction
|
|
199
|
+
up
|
|
200
|
+
end enum
|
|
201
|
+
`);
|
|
202
|
+
program.setFile('source/lib.bs', `
|
|
203
|
+
enum Direction
|
|
204
|
+
up
|
|
205
|
+
end enum
|
|
206
|
+
`);
|
|
207
|
+
program.validate();
|
|
208
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.duplicateEnumDeclaration('source', 'Direction')), { relatedInformation: [{
|
|
209
|
+
location: vscode_languageserver_protocol_1.Location.create(vscode_uri_1.URI.file((0, util_1.standardizePath) `${rootDir}/source/lib.bs`).toString(), util_1.util.createRange(1, 21, 1, 30)),
|
|
210
|
+
message: 'Enum declared here'
|
|
211
|
+
}] })]);
|
|
212
|
+
});
|
|
213
|
+
it('allows duplicate enums across different scopes', () => {
|
|
214
|
+
program.setFile('source/main.bs', `
|
|
215
|
+
enum Direction
|
|
216
|
+
up
|
|
217
|
+
end enum
|
|
218
|
+
`);
|
|
219
|
+
program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
220
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
|
221
|
+
<component name="Comp1" extends="Scene">
|
|
222
|
+
<script uri="comp1.bs" />
|
|
223
|
+
</component>
|
|
224
|
+
`);
|
|
225
|
+
program.setFile('components/comp1.bs', `
|
|
226
|
+
enum Direction
|
|
227
|
+
up
|
|
228
|
+
end enum
|
|
229
|
+
`);
|
|
230
|
+
program.validate();
|
|
231
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
232
|
+
});
|
|
233
|
+
it('flags duplicate members', () => {
|
|
234
|
+
program.setFile('source/main.bs', `
|
|
235
|
+
enum Direction
|
|
236
|
+
name
|
|
237
|
+
name
|
|
238
|
+
end enum
|
|
239
|
+
`);
|
|
240
|
+
program.validate();
|
|
241
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.duplicateIdentifier('name')), { range: util_1.util.createRange(3, 20, 3, 24) })]);
|
|
242
|
+
});
|
|
243
|
+
it('flags mixed enum value types with int first', () => {
|
|
244
|
+
program.setFile('source/main.bs', `
|
|
245
|
+
enum Direction
|
|
246
|
+
a = 1
|
|
247
|
+
b = "c"
|
|
248
|
+
end enum
|
|
249
|
+
`);
|
|
250
|
+
program.validate();
|
|
251
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.enumValueMustBeType('integer')), { range: util_1.util.createRange(3, 24, 3, 27) })]);
|
|
252
|
+
});
|
|
253
|
+
it('flags mixed enum value types with string first', () => {
|
|
254
|
+
program.setFile('source/main.bs', `
|
|
255
|
+
enum Direction
|
|
256
|
+
a = "a"
|
|
257
|
+
b = 1
|
|
258
|
+
end enum
|
|
259
|
+
`);
|
|
260
|
+
program.validate();
|
|
261
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.enumValueMustBeType('string')), { range: util_1.util.createRange(3, 24, 3, 25) })]);
|
|
262
|
+
});
|
|
263
|
+
it('flags missing value for string enum when string is first item', () => {
|
|
264
|
+
program.setFile('source/main.bs', `
|
|
265
|
+
enum Direction
|
|
266
|
+
a = "a"
|
|
267
|
+
b
|
|
268
|
+
end enum
|
|
269
|
+
`);
|
|
270
|
+
program.validate();
|
|
271
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.enumValueIsRequired('string')), { range: util_1.util.createRange(3, 20, 3, 21) })]);
|
|
272
|
+
});
|
|
273
|
+
it('allows mixing-and-matching int and hex int', () => {
|
|
274
|
+
program.setFile('source/main.bs', `
|
|
275
|
+
enum Direction
|
|
276
|
+
a = 1
|
|
277
|
+
b = &HFF
|
|
278
|
+
end enum
|
|
279
|
+
`);
|
|
280
|
+
program.validate();
|
|
281
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
282
|
+
});
|
|
283
|
+
it('allows floats', () => {
|
|
284
|
+
program.setFile('source/main.bs', `
|
|
285
|
+
enum Direction
|
|
286
|
+
a = 1.2
|
|
287
|
+
b = 5.2345
|
|
288
|
+
end enum
|
|
289
|
+
`);
|
|
290
|
+
program.validate();
|
|
291
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
292
|
+
});
|
|
293
|
+
it('only support non-object literals', () => {
|
|
294
|
+
program.setFile('source/main.bs', `
|
|
295
|
+
enum AppConfig
|
|
296
|
+
serverInfo = {}
|
|
297
|
+
end enum
|
|
298
|
+
`);
|
|
299
|
+
program.validate();
|
|
300
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.enumValueMustBeType('integer')), { range: util_1.util.createRange(2, 33, 2, 35) })]);
|
|
301
|
+
});
|
|
302
|
+
it('flags missing value for string enum where string is not first item', () => {
|
|
303
|
+
program.setFile('source/main.bs', `
|
|
304
|
+
enum Direction
|
|
305
|
+
a
|
|
306
|
+
b = "b" 'since this is the only value present, this is a string enum
|
|
307
|
+
end enum
|
|
308
|
+
`);
|
|
309
|
+
program.validate();
|
|
310
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.enumValueIsRequired('string')), { range: util_1.util.createRange(2, 20, 2, 21) })]);
|
|
311
|
+
});
|
|
312
|
+
it('catches unknown non-namespaced enum members', () => {
|
|
313
|
+
program.setFile('source/main.bs', `
|
|
314
|
+
enum Direction
|
|
315
|
+
up
|
|
316
|
+
end enum
|
|
317
|
+
|
|
318
|
+
sub main()
|
|
319
|
+
print Direction.up
|
|
320
|
+
print Direction.DOWN
|
|
321
|
+
print Direction.down
|
|
322
|
+
end sub
|
|
323
|
+
`);
|
|
324
|
+
program.validate();
|
|
325
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.unknownEnumValue('DOWN', 'Direction')), { range: util_1.util.createRange(7, 36, 7, 40) }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.unknownEnumValue('down', 'Direction')), { range: util_1.util.createRange(8, 36, 8, 40) })]);
|
|
326
|
+
});
|
|
327
|
+
it('catches unknown namespaced enum members', () => {
|
|
328
|
+
program.setFile('source/main.bs', `
|
|
329
|
+
namespace Enums
|
|
330
|
+
enum Direction
|
|
331
|
+
up
|
|
332
|
+
end enum
|
|
333
|
+
end namespace
|
|
334
|
+
|
|
335
|
+
sub main()
|
|
336
|
+
print Enums.Direction.up
|
|
337
|
+
print Enums.Direction.DOWN
|
|
338
|
+
print Enums.Direction.down
|
|
339
|
+
end sub
|
|
340
|
+
`);
|
|
341
|
+
program.validate();
|
|
342
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.unknownEnumValue('DOWN', 'Enums.Direction')), { range: util_1.util.createRange(9, 42, 9, 46) }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.unknownEnumValue('down', 'Enums.Direction')), { range: util_1.util.createRange(10, 42, 10, 46) })]);
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
describe('getMemberValueMap', () => {
|
|
346
|
+
function expectMemberValueMap(code, expected) {
|
|
347
|
+
const file = program.setFile('source/lib.brs', code);
|
|
348
|
+
const cancel = new vscode_languageserver_protocol_1.CancellationTokenSource();
|
|
349
|
+
let firstEnum;
|
|
350
|
+
file.ast.walk(statement => {
|
|
351
|
+
if ((0, reflection_1.isEnumStatement)(statement)) {
|
|
352
|
+
firstEnum = statement;
|
|
353
|
+
cancel.cancel();
|
|
354
|
+
}
|
|
355
|
+
}, {
|
|
356
|
+
walkMode: visitors_1.WalkMode.visitStatements,
|
|
357
|
+
cancel: cancel.token
|
|
358
|
+
});
|
|
359
|
+
(0, chai_1.expect)(firstEnum).to.exist;
|
|
360
|
+
const values = firstEnum.getMemberValueMap();
|
|
361
|
+
(0, chai_1.expect)([...values].reduce((prev, [key, value]) => {
|
|
362
|
+
prev[key] = value;
|
|
363
|
+
return prev;
|
|
364
|
+
}, {})).to.eql(expected);
|
|
365
|
+
}
|
|
366
|
+
it('defaults first enum value to 0', () => {
|
|
367
|
+
expectMemberValueMap(`
|
|
368
|
+
enum Direction
|
|
369
|
+
up
|
|
370
|
+
down
|
|
371
|
+
left
|
|
372
|
+
right
|
|
373
|
+
end enum
|
|
374
|
+
`, {
|
|
375
|
+
up: '0',
|
|
376
|
+
down: '1',
|
|
377
|
+
left: '2',
|
|
378
|
+
right: '3'
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
it('continues incrementing after defined int value', () => {
|
|
382
|
+
expectMemberValueMap(`
|
|
383
|
+
enum Direction
|
|
384
|
+
up
|
|
385
|
+
down = 9
|
|
386
|
+
left
|
|
387
|
+
right = 20
|
|
388
|
+
other
|
|
389
|
+
end enum
|
|
390
|
+
`, {
|
|
391
|
+
up: '0',
|
|
392
|
+
down: '9',
|
|
393
|
+
left: '10',
|
|
394
|
+
right: '20',
|
|
395
|
+
other: '21'
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
it('returns string values when defined', () => {
|
|
399
|
+
expectMemberValueMap(`
|
|
400
|
+
enum Direction
|
|
401
|
+
up = "up"
|
|
402
|
+
down = "DOWN"
|
|
403
|
+
left = "LeFt"
|
|
404
|
+
right = "righT"
|
|
405
|
+
end enum
|
|
406
|
+
`, {
|
|
407
|
+
up: '"up"',
|
|
408
|
+
down: '"DOWN"',
|
|
409
|
+
left: '"LeFt"',
|
|
410
|
+
right: '"righT"'
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
describe('transpile', () => {
|
|
415
|
+
it('includes original value when no value could be computed', () => {
|
|
416
|
+
testTranspile(`
|
|
417
|
+
sub main()
|
|
418
|
+
print Direction.up
|
|
419
|
+
end sub
|
|
420
|
+
enum Direction
|
|
421
|
+
up = {}
|
|
422
|
+
end enum
|
|
423
|
+
`, `
|
|
424
|
+
sub main()
|
|
425
|
+
print invalid
|
|
426
|
+
end sub
|
|
427
|
+
`, undefined, undefined, false);
|
|
428
|
+
});
|
|
429
|
+
it('writes all literal values as-is (even if there are errors)', () => {
|
|
430
|
+
testTranspile(`
|
|
431
|
+
sub main()
|
|
432
|
+
print Direction.up
|
|
433
|
+
print Direction.down
|
|
434
|
+
print Direction.left
|
|
435
|
+
print Direction.right
|
|
436
|
+
print Direction.upRight
|
|
437
|
+
end sub
|
|
438
|
+
enum Direction
|
|
439
|
+
up = 1
|
|
440
|
+
down = "asdf"
|
|
441
|
+
left = 3.14
|
|
442
|
+
right = &HFF '255
|
|
443
|
+
upRight ' will be 256 since hex ints are parsed as ints
|
|
444
|
+
end enum
|
|
445
|
+
`, `
|
|
446
|
+
sub main()
|
|
447
|
+
print 1
|
|
448
|
+
print "asdf"
|
|
449
|
+
print 3.14
|
|
450
|
+
print &HFF
|
|
451
|
+
print 256
|
|
452
|
+
end sub
|
|
453
|
+
`, 'trim', undefined, false);
|
|
454
|
+
});
|
|
455
|
+
it('supports default-as-integer', () => {
|
|
456
|
+
testTranspile(`
|
|
457
|
+
enum Direction
|
|
458
|
+
up
|
|
459
|
+
down
|
|
460
|
+
left
|
|
461
|
+
right
|
|
462
|
+
end enum
|
|
463
|
+
sub main()
|
|
464
|
+
print Direction.up, Direction.down, Direction.left, Direction.right
|
|
465
|
+
end sub
|
|
466
|
+
`, `
|
|
467
|
+
sub main()
|
|
468
|
+
print 0, 1, 2, 3
|
|
469
|
+
end sub
|
|
470
|
+
`);
|
|
471
|
+
});
|
|
472
|
+
it('supports string enums', () => {
|
|
473
|
+
testTranspile(`
|
|
474
|
+
enum Direction
|
|
475
|
+
up = "up"
|
|
476
|
+
down = "down"
|
|
477
|
+
left = "left"
|
|
478
|
+
right = "right"
|
|
479
|
+
end enum
|
|
480
|
+
sub main()
|
|
481
|
+
print Direction.up, Direction.down, Direction.left, Direction.right
|
|
482
|
+
end sub
|
|
483
|
+
`, `
|
|
484
|
+
sub main()
|
|
485
|
+
print "up", "down", "left", "right"
|
|
486
|
+
end sub
|
|
487
|
+
`);
|
|
488
|
+
});
|
|
489
|
+
it('replaces enum values from separate file with literals', () => {
|
|
490
|
+
program.setFile('source/enum.bs', `
|
|
491
|
+
enum CharacterType
|
|
492
|
+
Human = "Human"
|
|
493
|
+
Zombie = "Zombie"
|
|
494
|
+
end enum
|
|
495
|
+
namespace Locations
|
|
496
|
+
enum Houses
|
|
497
|
+
TownHouse
|
|
498
|
+
FarmHouse
|
|
499
|
+
end enum
|
|
500
|
+
end namespace
|
|
501
|
+
`);
|
|
502
|
+
testTranspile(`
|
|
503
|
+
sub test()
|
|
504
|
+
print CharacterType.Human
|
|
505
|
+
print CharacterType.Zombie
|
|
506
|
+
print Locations.Houses.TownHouse
|
|
507
|
+
print Locations.Houses.FarmHouse
|
|
508
|
+
end sub
|
|
509
|
+
`, `
|
|
510
|
+
sub test()
|
|
511
|
+
print "Human"
|
|
512
|
+
print "Zombie"
|
|
513
|
+
print 0
|
|
514
|
+
print 1
|
|
515
|
+
end sub
|
|
516
|
+
`);
|
|
517
|
+
});
|
|
518
|
+
});
|
|
519
|
+
describe('completions', () => {
|
|
520
|
+
it('does not crash when completing enum members with unsupported values', () => {
|
|
521
|
+
program.setFile('source/main.bs', `
|
|
522
|
+
sub Main()
|
|
523
|
+
direction.obj
|
|
524
|
+
end sub
|
|
525
|
+
enum Direction
|
|
526
|
+
up
|
|
527
|
+
down
|
|
528
|
+
obj = {}
|
|
529
|
+
end enum
|
|
530
|
+
`);
|
|
531
|
+
// direction.|obj
|
|
532
|
+
(0, testHelpers_spec_1.expectCompletionsIncludes)(program.getCompletions('source/main.bs', util_1.util.createPosition(2, 30)), [{
|
|
533
|
+
label: 'up',
|
|
534
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.EnumMember
|
|
535
|
+
}, {
|
|
536
|
+
label: 'down',
|
|
537
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.EnumMember
|
|
538
|
+
}, {
|
|
539
|
+
label: 'obj',
|
|
540
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.EnumMember
|
|
541
|
+
}]);
|
|
542
|
+
});
|
|
543
|
+
it('gets enum statement completions from global enum', () => {
|
|
544
|
+
program.setFile('source/main.bs', `
|
|
545
|
+
sub Main()
|
|
546
|
+
direction.down
|
|
547
|
+
end sub
|
|
548
|
+
enum Direction
|
|
549
|
+
up
|
|
550
|
+
down
|
|
551
|
+
end enum
|
|
552
|
+
`);
|
|
553
|
+
// |direction.down
|
|
554
|
+
(0, testHelpers_spec_1.expectCompletionsIncludes)(program.getCompletions('source/main.bs', util_1.util.createPosition(2, 20)), [{
|
|
555
|
+
label: 'Direction',
|
|
556
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.Enum
|
|
557
|
+
}]);
|
|
558
|
+
// dire|ction.down
|
|
559
|
+
(0, testHelpers_spec_1.expectCompletionsIncludes)(program.getCompletions('source/main.bs', util_1.util.createPosition(2, 24)), [{
|
|
560
|
+
label: 'Direction',
|
|
561
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.Enum
|
|
562
|
+
}]);
|
|
563
|
+
// direction|.down
|
|
564
|
+
(0, testHelpers_spec_1.expectCompletionsIncludes)(program.getCompletions('source/main.bs', util_1.util.createPosition(2, 29)), [{
|
|
565
|
+
label: 'Direction',
|
|
566
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.Enum
|
|
567
|
+
}]);
|
|
568
|
+
});
|
|
569
|
+
it('gets enum member completions from global enum', () => {
|
|
570
|
+
program.setFile('source/main.bs', `
|
|
571
|
+
sub Main()
|
|
572
|
+
direction.down
|
|
573
|
+
end sub
|
|
574
|
+
enum Direction
|
|
575
|
+
up
|
|
576
|
+
down
|
|
577
|
+
end enum
|
|
578
|
+
`);
|
|
579
|
+
// direction.|down
|
|
580
|
+
(0, testHelpers_spec_1.expectCompletionsIncludes)(program.getCompletions('source/main.bs', util_1.util.createPosition(2, 30)), [{
|
|
581
|
+
label: 'up',
|
|
582
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.EnumMember
|
|
583
|
+
}, {
|
|
584
|
+
label: 'down',
|
|
585
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.EnumMember
|
|
586
|
+
}]);
|
|
587
|
+
// direction.do|wn
|
|
588
|
+
(0, testHelpers_spec_1.expectCompletionsIncludes)(program.getCompletions('source/main.bs', util_1.util.createPosition(2, 32)), [{
|
|
589
|
+
label: 'up',
|
|
590
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.EnumMember
|
|
591
|
+
}, {
|
|
592
|
+
label: 'down',
|
|
593
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.EnumMember
|
|
594
|
+
}]);
|
|
595
|
+
// direction.down|
|
|
596
|
+
(0, testHelpers_spec_1.expectCompletionsIncludes)(program.getCompletions('source/main.bs', util_1.util.createPosition(2, 34)), [{
|
|
597
|
+
label: 'up',
|
|
598
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.EnumMember
|
|
599
|
+
}, {
|
|
600
|
+
label: 'down',
|
|
601
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.EnumMember
|
|
602
|
+
}]);
|
|
603
|
+
});
|
|
604
|
+
it('gets enum statement completions from namespaced enum', () => {
|
|
605
|
+
program.setFile('source/main.bs', `
|
|
606
|
+
sub Main()
|
|
607
|
+
enums.direction.down
|
|
608
|
+
end sub
|
|
609
|
+
namespace enums
|
|
610
|
+
enum Direction
|
|
611
|
+
up
|
|
612
|
+
down
|
|
613
|
+
end enum
|
|
614
|
+
end namespace
|
|
615
|
+
`);
|
|
616
|
+
// enums.|direction.down
|
|
617
|
+
(0, testHelpers_spec_1.expectCompletionsIncludes)(program.getCompletions('source/main.bs', util_1.util.createPosition(2, 26)), [{
|
|
618
|
+
label: 'Direction',
|
|
619
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.Enum
|
|
620
|
+
}]);
|
|
621
|
+
// enums.dire|ction.down
|
|
622
|
+
(0, testHelpers_spec_1.expectCompletionsIncludes)(program.getCompletions('source/main.bs', util_1.util.createPosition(2, 30)), [{
|
|
623
|
+
label: 'Direction',
|
|
624
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.Enum
|
|
625
|
+
}]);
|
|
626
|
+
// enums.direction|.down
|
|
627
|
+
(0, testHelpers_spec_1.expectCompletionsIncludes)(program.getCompletions('source/main.bs', util_1.util.createPosition(2, 35)), [{
|
|
628
|
+
label: 'Direction',
|
|
629
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.Enum
|
|
630
|
+
}]);
|
|
631
|
+
});
|
|
632
|
+
it('gets enum member completions from namespaced enum', () => {
|
|
633
|
+
program.setFile('source/main.bs', `
|
|
634
|
+
sub Main()
|
|
635
|
+
enums.direction.down
|
|
636
|
+
end sub
|
|
637
|
+
namespace enums
|
|
638
|
+
enum Direction
|
|
639
|
+
up
|
|
640
|
+
down
|
|
641
|
+
end enum
|
|
642
|
+
end namespace
|
|
643
|
+
`);
|
|
644
|
+
// enums.direction.|down
|
|
645
|
+
(0, testHelpers_spec_1.expectCompletionsIncludes)(program.getCompletions('source/main.bs', util_1.util.createPosition(2, 36)), [{
|
|
646
|
+
label: 'up',
|
|
647
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.EnumMember
|
|
648
|
+
}, {
|
|
649
|
+
label: 'down',
|
|
650
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.EnumMember
|
|
651
|
+
}]);
|
|
652
|
+
// enums.direction.do|wn
|
|
653
|
+
(0, testHelpers_spec_1.expectCompletionsIncludes)(program.getCompletions('source/main.bs', util_1.util.createPosition(2, 38)), [{
|
|
654
|
+
label: 'up',
|
|
655
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.EnumMember
|
|
656
|
+
}, {
|
|
657
|
+
label: 'down',
|
|
658
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.EnumMember
|
|
659
|
+
}]);
|
|
660
|
+
// enums.direction.down|
|
|
661
|
+
(0, testHelpers_spec_1.expectCompletionsIncludes)(program.getCompletions('source/main.bs', util_1.util.createPosition(2, 40)), [{
|
|
662
|
+
label: 'up',
|
|
663
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.EnumMember
|
|
664
|
+
}, {
|
|
665
|
+
label: 'down',
|
|
666
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.EnumMember
|
|
667
|
+
}]);
|
|
668
|
+
});
|
|
669
|
+
it('excludes enum member completions from namespace enum', () => {
|
|
670
|
+
program.setFile('source/main.bs', `
|
|
671
|
+
sub Main()
|
|
672
|
+
direction.ba
|
|
673
|
+
end sub
|
|
674
|
+
namespace enums
|
|
675
|
+
enum Direction
|
|
676
|
+
up
|
|
677
|
+
down
|
|
678
|
+
end enum
|
|
679
|
+
end namespace
|
|
680
|
+
`);
|
|
681
|
+
//should NOT find Direction because it's not directly available at the top level (you need to go through `enums.` to get at it)
|
|
682
|
+
// dire|ction.down
|
|
683
|
+
(0, testHelpers_spec_1.expectCompletionsExcludes)(program.getCompletions('source/main.bs', util_1.util.createPosition(2, 24)), [{
|
|
684
|
+
label: 'Direction',
|
|
685
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.Enum
|
|
686
|
+
}]);
|
|
687
|
+
});
|
|
688
|
+
it('infers namespace for enum statement completions', () => {
|
|
689
|
+
program.setFile('source/main.bs', `
|
|
690
|
+
namespace enums
|
|
691
|
+
sub Main()
|
|
692
|
+
direction.down
|
|
693
|
+
end sub
|
|
694
|
+
enum Direction
|
|
695
|
+
up
|
|
696
|
+
down
|
|
697
|
+
end enum
|
|
698
|
+
end namespace
|
|
699
|
+
enum Logic
|
|
700
|
+
yes
|
|
701
|
+
no
|
|
702
|
+
end enum
|
|
703
|
+
`);
|
|
704
|
+
// dire|ction.down
|
|
705
|
+
(0, testHelpers_spec_1.expectCompletionsIncludes)(program.getCompletions('source/main.bs', util_1.util.createPosition(3, 33)), [{
|
|
706
|
+
label: 'Direction',
|
|
707
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.Enum
|
|
708
|
+
}, {
|
|
709
|
+
label: 'Logic',
|
|
710
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.Enum
|
|
711
|
+
}]);
|
|
712
|
+
});
|
|
713
|
+
it('infers namespace for enum member completions', () => {
|
|
714
|
+
program.setFile('source/main.bs', `
|
|
715
|
+
namespace enums
|
|
716
|
+
sub Main()
|
|
717
|
+
direction.down
|
|
718
|
+
end sub
|
|
719
|
+
enum Direction
|
|
720
|
+
up
|
|
721
|
+
down
|
|
722
|
+
end enum
|
|
723
|
+
end namespace
|
|
724
|
+
`);
|
|
725
|
+
// direction.do|wn
|
|
726
|
+
(0, testHelpers_spec_1.expectCompletionsIncludes)(program.getCompletions('source/main.bs', util_1.util.createPosition(3, 36)), [{
|
|
727
|
+
label: 'up',
|
|
728
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.EnumMember
|
|
729
|
+
}, {
|
|
730
|
+
label: 'down',
|
|
731
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.EnumMember
|
|
732
|
+
}]);
|
|
733
|
+
});
|
|
734
|
+
it('supports explicit namespace for enum statement completions', () => {
|
|
735
|
+
program.setFile('source/main.bs', `
|
|
736
|
+
namespace enums
|
|
737
|
+
sub Main()
|
|
738
|
+
enums.direction.down
|
|
739
|
+
end sub
|
|
740
|
+
enum Direction
|
|
741
|
+
up
|
|
742
|
+
down
|
|
743
|
+
end enum
|
|
744
|
+
end namespace
|
|
745
|
+
`);
|
|
746
|
+
// enums.dire|ction.down
|
|
747
|
+
(0, testHelpers_spec_1.expectCompletionsIncludes)(program.getCompletions('source/main.bs', util_1.util.createPosition(3, 38)), [{
|
|
748
|
+
label: 'Direction',
|
|
749
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.Enum
|
|
750
|
+
}]);
|
|
751
|
+
});
|
|
752
|
+
it('supports explicit namespace for enum statement completions', () => {
|
|
753
|
+
program.setFile('source/main.bs', `
|
|
754
|
+
namespace logger
|
|
755
|
+
sub log()
|
|
756
|
+
enums.direction.down
|
|
757
|
+
end sub
|
|
758
|
+
end namespace
|
|
759
|
+
namespace enums
|
|
760
|
+
enum Direction
|
|
761
|
+
up
|
|
762
|
+
down
|
|
763
|
+
end enum
|
|
764
|
+
end namespace
|
|
765
|
+
`);
|
|
766
|
+
// enums.dire|ction.down
|
|
767
|
+
(0, testHelpers_spec_1.expectCompletionsIncludes)(program.getCompletions('source/main.bs', util_1.util.createPosition(3, 38)), [{
|
|
768
|
+
label: 'Direction',
|
|
769
|
+
kind: vscode_languageserver_protocol_1.CompletionItemKind.Enum
|
|
770
|
+
}]);
|
|
771
|
+
});
|
|
772
|
+
});
|
|
773
|
+
});
|
|
774
|
+
//# sourceMappingURL=Enum.spec.js.map
|