Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
8bc4d854
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
8bc4d854
编写于
3月 08, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Minor cleanup in tests
上级
458a1c46
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
129 addition
and
258 deletion
+129
-258
src/vs/editor/test/common/commands/shiftCommand.test.ts
src/vs/editor/test/common/commands/shiftCommand.test.ts
+4
-11
src/vs/editor/test/common/commands/trimTrailingWhitespaceCommand.test.ts
...est/common/commands/trimTrailingWhitespaceCommand.test.ts
+6
-5
src/vs/editor/test/common/config/commonEditorConfig.test.ts
src/vs/editor/test/common/config/commonEditorConfig.test.ts
+0
-76
src/vs/editor/test/common/editorTestUtils.ts
src/vs/editor/test/common/editorTestUtils.ts
+0
-8
src/vs/editor/test/common/mocks/mockMode.ts
src/vs/editor/test/common/mocks/mockMode.ts
+24
-0
src/vs/editor/test/common/model/textModel.test.ts
src/vs/editor/test/common/model/textModel.test.ts
+65
-0
src/vs/editor/test/common/modes/textToHtmlTokenizer.test.ts
src/vs/editor/test/common/modes/textToHtmlTokenizer.test.ts
+3
-9
src/vs/editor/test/common/modes/tokenization.test.ts
src/vs/editor/test/common/modes/tokenization.test.ts
+8
-23
src/vs/editor/test/common/modesTestUtils.ts
src/vs/editor/test/common/modesTestUtils.ts
+6
-15
src/vs/editor/test/common/modesUtil.ts
src/vs/editor/test/common/modesUtil.ts
+3
-19
src/vs/editor/test/common/testModes.ts
src/vs/editor/test/common/testModes.ts
+8
-90
src/vs/languages/javascript/test/common/javascript.test.ts
src/vs/languages/javascript/test/common/javascript.test.ts
+2
-2
未找到文件。
src/vs/editor/test/common/commands/shiftCommand.test.ts
浏览文件 @
8bc4d854
...
...
@@ -8,10 +8,11 @@ import * as assert from 'assert';
import
{
ShiftCommand
}
from
'
vs/editor/common/commands/shiftCommand
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
IIdentifiedSingleEditOperation
}
from
'
vs/editor/common/editorCommon
'
;
import
{
I
Mode
,
I
RichEditSupport
,
IndentAction
}
from
'
vs/editor/common/modes
'
;
import
{
IRichEditSupport
,
IndentAction
}
from
'
vs/editor/common/modes
'
;
import
{
RichEditSupport
}
from
'
vs/editor/common/modes/supports/richEditSupport
'
;
import
{
createSingleEditOp
,
getEditOperation
,
testCommand
}
from
'
vs/editor/test/common/commands/commandTestUtils
'
;
import
{
withEditorModel
}
from
'
vs/editor/test/common/editorTestUtils
'
;
import
{
MockMode
}
from
'
vs/editor/test/common/mocks/mockMode
'
;
function
testShiftCommand
(
lines
:
string
[],
selection
:
Selection
,
expectedLines
:
string
[],
expectedSelection
:
Selection
):
void
{
testCommand
(
lines
,
null
,
selection
,
(
sel
)
=>
new
ShiftCommand
(
sel
,
{
...
...
@@ -29,11 +30,12 @@ function testUnshiftCommand(lines: string[], selection: Selection, expectedLines
}),
expectedLines
,
expectedSelection
);
}
class
DocBlockCommentMode
implements
I
Mode
{
class
DocBlockCommentMode
extends
Mock
Mode
{
public
richEditSupport
:
IRichEditSupport
;
constructor
()
{
super
();
this
.
richEditSupport
=
new
RichEditSupport
(
this
.
getId
(),
null
,
{
brackets
:
[
[
'
(
'
,
'
)
'
],
...
...
@@ -66,15 +68,6 @@ class DocBlockCommentMode implements IMode {
]
});
}
public
getId
():
string
{
return
'
docBlockCommentMode
'
;
}
public
toSimplifiedMode
():
IMode
{
return
this
;
}
}
function
testShiftCommandInDocBlockCommentMode
(
lines
:
string
[],
selection
:
Selection
,
expectedLines
:
string
[],
expectedSelection
:
Selection
):
void
{
...
...
src/vs/editor/test/common/commands/trimTrailingWhitespaceCommand.test.ts
浏览文件 @
8bc4d854
...
...
@@ -7,9 +7,10 @@
import
*
as
assert
from
'
assert
'
;
import
{
TrimTrailingWhitespaceCommand
,
trimTrailingWhitespace
}
from
'
vs/editor/common/commands/trimTrailingWhitespaceCommand
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
IIdentifiedSingleEditOperation
,
IPosition
}
from
'
vs/editor/common/editorCommon
'
;
import
{
createInsertDeleteSingleEditOp
,
createSingleEditOp
,
getEditOperation
}
from
'
vs/editor/test/common/commands/commandTestUtils
'
;
import
{
pos
,
withEditorModel
}
from
'
vs/editor/test/common/editorTestUtils
'
;
import
{
withEditorModel
}
from
'
vs/editor/test/common/editorTestUtils
'
;
function
assertTrimTrailingWhitespaceCommand
(
text
:
string
[],
expected
:
IIdentifiedSingleEditOperation
[]):
void
{
return
withEditorModel
(
text
,
(
model
)
=>
{
...
...
@@ -49,9 +50,9 @@ suite('Editor Commands - Trim Trailing Whitespace Command', () => {
]);
assertTrimTrailingWhitespace
([
'
text
'
],
[
pos
(
1
,
1
),
pos
(
1
,
2
),
pos
(
1
,
3
)],
[
createInsertDeleteSingleEditOp
(
null
,
1
,
5
,
1
,
8
)]);
assertTrimTrailingWhitespace
([
'
text
'
],
[
pos
(
1
,
1
),
pos
(
1
,
5
)],
[
createInsertDeleteSingleEditOp
(
null
,
1
,
5
,
1
,
8
)]);
assertTrimTrailingWhitespace
([
'
text
'
],
[
pos
(
1
,
1
),
pos
(
1
,
5
),
pos
(
1
,
6
)],
[
createInsertDeleteSingleEditOp
(
null
,
1
,
6
,
1
,
8
)]);
assertTrimTrailingWhitespace
([
'
text
'
],
[
new
Position
(
1
,
1
),
new
Position
(
1
,
2
),
new
Position
(
1
,
3
)],
[
createInsertDeleteSingleEditOp
(
null
,
1
,
5
,
1
,
8
)]);
assertTrimTrailingWhitespace
([
'
text
'
],
[
new
Position
(
1
,
1
),
new
Position
(
1
,
5
)],
[
createInsertDeleteSingleEditOp
(
null
,
1
,
5
,
1
,
8
)]);
assertTrimTrailingWhitespace
([
'
text
'
],
[
new
Position
(
1
,
1
),
new
Position
(
1
,
5
),
new
Position
(
1
,
6
)],
[
createInsertDeleteSingleEditOp
(
null
,
1
,
6
,
1
,
8
)]);
assertTrimTrailingWhitespace
([
'
some text
\t
'
,
'
some more text
'
,
...
...
@@ -70,7 +71,7 @@ suite('Editor Commands - Trim Trailing Whitespace Command', () => {
'
\t
'
,
'
even more text
'
,
'
and some mixed
\t
\t
'
],
[
pos
(
1
,
11
),
pos
(
3
,
2
),
pos
(
5
,
1
),
pos
(
4
,
1
),
pos
(
5
,
10
)],
[
],
[
new
Position
(
1
,
11
),
new
Position
(
3
,
2
),
new
Position
(
5
,
1
),
new
Position
(
4
,
1
),
new
Position
(
5
,
10
)],
[
createInsertDeleteSingleEditOp
(
null
,
3
,
2
,
3
,
4
),
createInsertDeleteSingleEditOp
(
null
,
4
,
15
,
4
,
17
),
createInsertDeleteSingleEditOp
(
null
,
5
,
15
,
5
,
20
)
...
...
src/vs/editor/test/common/config/commonEditorConfig.test.ts
已删除
100644 → 0
浏览文件 @
458a1c46
/*---------------------------------------------------------------------------------------------
* 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
{
TextModel
}
from
'
vs/editor/common/model/textModel
'
;
import
{
DefaultEndOfLine
}
from
'
vs/editor/common/editorCommon
'
;
suite
(
'
Editor Config - CommonEditorConfig
'
,
()
=>
{
test
(
'
Configuration.normalizeIndentation
'
,
()
=>
{
var
model
=
new
TextModel
([],
{
length
:
0
,
lines
:
[],
BOM
:
''
,
EOL
:
'
\n
'
,
options
:
{
tabSize
:
4
,
insertSpaces
:
false
,
defaultEOL
:
DefaultEndOfLine
.
LF
}
});
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
'
),
'
\t
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
'
),
'
\t
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
'
),
'
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
'
),
'
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
'
),
'
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
''
),
''
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
'
),
'
\t\t
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
'
),
'
\t
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
'
),
'
\t
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
'
),
'
\t
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
a
'
),
'
\t
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
a
'
),
'
\t
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
a
'
),
'
\t\t
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
a
'
),
'
\t
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
a
'
),
'
\t
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
a
'
),
'
\t
a
'
);
model
.
dispose
();
model
=
new
TextModel
([],
{
length
:
0
,
lines
:
[],
BOM
:
''
,
EOL
:
'
\n
'
,
options
:
{
tabSize
:
4
,
insertSpaces
:
true
,
defaultEOL
:
DefaultEndOfLine
.
LF
}
});
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
a
'
),
'
a
'
);
model
.
dispose
();
});
});
src/vs/editor/test/common/editorTestUtils.ts
浏览文件 @
8bc4d854
...
...
@@ -4,16 +4,8 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
IPosition
}
from
'
vs/editor/common/editorCommon
'
;
import
{
Model
}
from
'
vs/editor/common/model/model
'
;
export
function
pos
(
lineNumber
:
number
,
column
:
number
):
IPosition
{
return
{
lineNumber
:
lineNumber
,
column
:
column
};
}
export
function
withEditorModel
(
text
:
string
[],
callback
:(
model
:
Model
)
=>
void
):
void
{
var
model
=
new
Model
(
text
.
join
(
'
\n
'
),
Model
.
DEFAULT_CREATION_OPTIONS
,
null
);
callback
(
model
);
...
...
src/vs/editor/test/common/mocks/mockMode.ts
0 → 100644
浏览文件 @
8bc4d854
/*---------------------------------------------------------------------------------------------
* 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
modes
from
'
vs/editor/common/modes
'
;
export
class
MockMode
implements
modes
.
IMode
{
private
_id
:
string
;
constructor
(
id
:
string
=
'
mockMode
'
)
{
this
.
_id
=
id
;
}
public
getId
():
string
{
return
this
.
_id
;
}
public
toSimplifiedMode
():
modes
.
IMode
{
return
this
;
}
}
src/vs/editor/test/common/model/textModel.test.ts
浏览文件 @
8bc4d854
...
...
@@ -454,4 +454,69 @@ suite('Editor Model - TextModel', () => {
assert
.
throws
(()
=>
m
.
modifyPosition
(
new
Position
(
2
,
2
),
-
100
));
assert
.
throws
(()
=>
m
.
modifyPosition
(
new
Position
(
2
,
9
),
-
18
));
});
test
(
'
normalizeIndentation 1
'
,
()
=>
{
let
model
=
new
TextModel
([],
{
length
:
0
,
lines
:
[],
BOM
:
''
,
EOL
:
'
\n
'
,
options
:
{
tabSize
:
4
,
insertSpaces
:
false
,
defaultEOL
:
DefaultEndOfLine
.
LF
}
});
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
'
),
'
\t
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
'
),
'
\t
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
'
),
'
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
'
),
'
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
'
),
'
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
''
),
''
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
'
),
'
\t\t
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
'
),
'
\t
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
'
),
'
\t
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
'
),
'
\t
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
a
'
),
'
\t
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
a
'
),
'
\t
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
a
'
),
'
\t\t
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
a
'
),
'
\t
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
a
'
),
'
\t
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
a
'
),
'
\t
a
'
);
model
.
dispose
();
});
test
(
'
normalizeIndentation 2
'
,
()
=>
{
let
model
=
new
TextModel
([],
{
length
:
0
,
lines
:
[],
BOM
:
''
,
EOL
:
'
\n
'
,
options
:
{
tabSize
:
4
,
insertSpaces
:
true
,
defaultEOL
:
DefaultEndOfLine
.
LF
}
});
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
a
'
),
'
a
'
);
assert
.
equal
(
model
.
normalizeIndentation
(
'
\t
a
'
),
'
a
'
);
model
.
dispose
();
});
});
src/vs/editor/test/common/modes/textToHtmlTokenizer.test.ts
浏览文件 @
8bc4d854
...
...
@@ -9,6 +9,7 @@ import {IMode, IStream, ITokenizationResult, ITokenizationSupport} from 'vs/edit
import
{
AbstractState
}
from
'
vs/editor/common/modes/abstractState
'
;
import
{
TokenizationSupport
}
from
'
vs/editor/common/modes/supports/tokenizationSupport
'
;
import
{
tokenizeToHtmlContent
}
from
'
vs/editor/common/modes/textToHtmlTokenizer
'
;
import
{
MockMode
}
from
'
vs/editor/test/common/mocks/mockMode
'
;
suite
(
'
Editor Modes - textToHtmlTokenizer
'
,
()
=>
{
test
(
'
TextToHtmlTokenizer
'
,
()
=>
{
...
...
@@ -71,21 +72,14 @@ class State extends AbstractState {
}
}
class
Mode
implements
I
Mode
{
class
Mode
extends
Mock
Mode
{
public
tokenizationSupport
:
ITokenizationSupport
;
constructor
()
{
super
();
this
.
tokenizationSupport
=
new
TokenizationSupport
(
this
,
{
getInitialState
:
()
=>
new
State
(
this
)
},
false
,
false
);
}
public
getId
():
string
{
return
'
testMode
'
;
}
public
toSimplifiedMode
():
IMode
{
return
this
;
}
}
src/vs/editor/test/common/modes/tokenization.test.ts
浏览文件 @
8bc4d854
...
...
@@ -11,7 +11,8 @@ import * as modes from 'vs/editor/common/modes';
import
{
AbstractState
}
from
'
vs/editor/common/modes/abstractState
'
;
import
{
handleEvent
}
from
'
vs/editor/common/modes/supports
'
;
import
{
IEnteringNestedModeData
,
ILeavingNestedModeData
,
TokenizationSupport
}
from
'
vs/editor/common/modes/supports/tokenizationSupport
'
;
import
{
createLineContext
}
from
'
vs/editor/test/common/modesTestUtils
'
;
import
{
createMockLineContext
}
from
'
vs/editor/test/common/modesTestUtils
'
;
import
{
MockMode
}
from
'
vs/editor/test/common/mocks/mockMode
'
;
export
class
State
extends
AbstractState
{
...
...
@@ -28,23 +29,16 @@ export class State extends AbstractState {
}
}
export
class
Mode
implements
modes
.
I
Mode
{
export
class
Mode
extends
Mock
Mode
{
public
tokenizationSupport
:
modes
.
ITokenizationSupport
;
constructor
()
{
super
();
this
.
tokenizationSupport
=
new
TokenizationSupport
(
this
,
{
getInitialState
:
()
=>
new
State
(
this
)
},
false
,
false
);
}
public
getId
():
string
{
return
'
testMode
'
;
}
public
toSimplifiedMode
():
modes
.
IMode
{
return
this
;
}
}
...
...
@@ -98,27 +92,18 @@ export class StateMemorizingLastWord extends AbstractState {
}
}
export
class
SwitchingMode
implements
modes
.
I
Mode
{
export
class
SwitchingMode
extends
Mock
Mode
{
private
_id
:
string
;
private
_switchingModeDescriptor
:
IModeSwitchingDescriptor
;
public
tokenizationSupport
:
modes
.
ITokenizationSupport
;
constructor
(
id
:
string
,
descriptor
:
IModeSwitchingDescriptor
)
{
this
.
_id
=
id
;
super
(
id
)
;
this
.
_switchingModeDescriptor
=
descriptor
;
this
.
tokenizationSupport
=
new
TokenizationSupport
(
this
,
this
,
true
,
false
);
}
public
getId
():
string
{
return
this
.
_id
;
}
public
toSimplifiedMode
():
modes
.
IMode
{
return
this
;
}
public
addSupportChangedListener
(
callback
:
(
e
:
IModeSupportChangedEvent
)
=>
void
):
IDisposable
{
return
EmptyDisposable
;
}
...
...
@@ -354,7 +339,7 @@ suite('Editor Modes - Tokenization', () => {
{
startIndex
:
5
,
id
:
'
B
'
}
]);
handleEvent
(
createLineContext
(
'
abc (def
'
,
lineTokens
),
0
,
(
mode
:
modes
.
IMode
,
context
:
modes
.
ILineContext
,
offset
:
number
)
=>
{
handleEvent
(
create
Mock
LineContext
(
'
abc (def
'
,
lineTokens
),
0
,
(
mode
:
modes
.
IMode
,
context
:
modes
.
ILineContext
,
offset
:
number
)
=>
{
assert
.
deepEqual
(
mode
.
getId
(),
'
A
'
);
assert
.
equal
(
context
.
getTokenCount
(),
3
);
assert
.
equal
(
context
.
getTokenStartIndex
(
0
),
0
);
...
...
@@ -367,7 +352,7 @@ suite('Editor Modes - Tokenization', () => {
assert
.
equal
(
context
.
getLineContent
(),
'
abc (
'
);
});
handleEvent
(
createLineContext
(
'
abc (def
'
,
lineTokens
),
6
,
(
mode
:
modes
.
IMode
,
context
:
modes
.
ILineContext
,
offset
:
number
)
=>
{
handleEvent
(
create
Mock
LineContext
(
'
abc (def
'
,
lineTokens
),
6
,
(
mode
:
modes
.
IMode
,
context
:
modes
.
ILineContext
,
offset
:
number
)
=>
{
assert
.
deepEqual
(
mode
.
getId
(),
'
B
'
);
assert
.
equal
(
context
.
getTokenCount
(),
1
);
assert
.
equal
(
context
.
getTokenStartIndex
(
0
),
0
);
...
...
src/vs/editor/test/common/modesTestUtils.ts
浏览文件 @
8bc4d854
...
...
@@ -7,31 +7,22 @@
import
{
Arrays
}
from
'
vs/editor/common/core/arrays
'
;
import
*
as
modes
from
'
vs/editor/common/modes
'
;
import
{
RichEditSupport
}
from
'
vs/editor/common/modes/supports/richEditSupport
'
;
import
{
MockMode
}
from
'
vs/editor/test/common/mocks/mockMode
'
;
class
SimpleTokenTypeClassificationMode
implements
modes
.
IMode
{
private
_id
:
string
;
class
ModeWithRichEditSupport
extends
MockMode
{
public
richEditSupport
:
modes
.
IRichEditSupport
;
constructor
(
id
:
string
,
wordRegExp
:
RegExp
)
{
this
.
_id
=
id
;
this
.
richEditSupport
=
new
RichEditSupport
(
this
.
_
id
,
null
,
{
super
(
id
)
;
this
.
richEditSupport
=
new
RichEditSupport
(
id
,
null
,
{
wordPattern
:
wordRegExp
});
}
public
getId
():
string
{
return
this
.
_id
;
}
public
toSimplifiedMode
():
modes
.
IMode
{
return
this
;
}
}
export
function
createMockMode
(
id
:
string
,
wordRegExp
:
RegExp
=
null
):
modes
.
IMode
{
return
new
SimpleTokenTypeClassificationMode
(
id
,
wordRegExp
);
return
new
ModeWithRichEditSupport
(
id
,
wordRegExp
);
}
export
interface
TokenText
{
...
...
@@ -53,7 +44,7 @@ export function createLineContextFromTokenText(tokens: TokenText[]): modes.ILine
return
new
TestLineContext
(
line
,
processedTokens
,
null
);
}
export
function
createLineContext
(
line
:
string
,
tokens
:
modes
.
ILineTokens
):
modes
.
ILineContext
{
export
function
create
Mock
LineContext
(
line
:
string
,
tokens
:
modes
.
ILineTokens
):
modes
.
ILineContext
{
return
new
TestLineContext
(
line
,
tokens
.
tokens
,
tokens
.
modeTransitions
);
}
...
...
src/vs/editor/test/common/modesUtil.ts
浏览文件 @
8bc4d854
...
...
@@ -12,6 +12,7 @@ import {compile} from 'vs/editor/common/modes/monarch/monarchCompile';
import
{
createTokenizationSupport
}
from
'
vs/editor/common/modes/monarch/monarchLexer
'
;
import
{
ILanguage
}
from
'
vs/editor/common/modes/monarch/monarchTypes
'
;
import
{
createMockModeService
}
from
'
vs/editor/test/common/servicesTestUtils
'
;
import
{
MockMode
}
from
'
vs/editor/test/common/mocks/mockMode
'
;
export
interface
IRelaxedToken
{
startIndex
:
number
;
...
...
@@ -59,29 +60,12 @@ export interface IOnEnterAsserter {
indentsOutdents
(
oneLineAboveText
:
string
,
beforeText
:
string
,
afterText
:
string
):
void
;
}
class
SimpleMode
implements
modes
.
IMode
{
private
_id
:
string
;
constructor
(
id
:
string
)
{
this
.
_id
=
id
;
}
public
getId
():
string
{
return
this
.
_id
;
}
public
toSimplifiedMode
():
modes
.
IMode
{
return
this
;
}
}
export
function
createOnEnterAsserter
(
modeId
:
string
,
richEditSupport
:
modes
.
IRichEditSupport
):
IOnEnterAsserter
{
var
assertOne
=
(
oneLineAboveText
:
string
,
beforeText
:
string
,
afterText
:
string
,
expected
:
modes
.
IndentAction
)
=>
{
var
model
=
new
Model
(
[
oneLineAboveText
,
beforeText
+
afterText
].
join
(
'
\n
'
),
Model
.
DEFAULT_CREATION_OPTIONS
,
new
Simple
Mode
(
modeId
)
new
Mock
Mode
(
modeId
)
);
var
actual
=
richEditSupport
.
onEnter
.
onEnter
(
model
,
{
lineNumber
:
2
,
column
:
beforeText
.
length
+
1
});
if
(
expected
===
modes
.
IndentAction
.
None
)
{
...
...
@@ -120,7 +104,7 @@ export function executeMonarchTokenizationTests(name:string, language:ILanguage,
var
modeService
=
createMockModeService
();
var
tokenizationSupport
=
createTokenizationSupport
(
modeService
,
new
SimpleMode
(
'
mock.mode
'
),
lexer
);
var
tokenizationSupport
=
createTokenizationSupport
(
modeService
,
new
MockMode
(
),
lexer
);
executeTests
(
tokenizationSupport
,
tests
);
}
...
...
src/vs/editor/test/common/testModes.ts
浏览文件 @
8bc4d854
...
...
@@ -8,6 +8,7 @@ import * as modes from 'vs/editor/common/modes';
import
{
AbstractState
}
from
'
vs/editor/common/modes/abstractState
'
;
import
{
RichEditSupport
}
from
'
vs/editor/common/modes/supports/richEditSupport
'
;
import
{
TokenizationSupport
}
from
'
vs/editor/common/modes/supports/tokenizationSupport
'
;
import
{
MockMode
}
from
'
vs/editor/test/common/mocks/mockMode
'
;
export
class
CommentState
extends
AbstractState
{
...
...
@@ -29,12 +30,13 @@ export class CommentState extends AbstractState {
}
}
export
class
CommentMode
implements
modes
.
I
Mode
{
export
class
CommentMode
extends
Mock
Mode
{
public
tokenizationSupport
:
modes
.
ITokenizationSupport
;
public
richEditSupport
:
modes
.
IRichEditSupport
;
constructor
(
commentsConfig
:
modes
.
ICommentsConfiguration
)
{
super
();
this
.
tokenizationSupport
=
new
TokenizationSupport
(
this
,
{
getInitialState
:
()
=>
new
CommentState
(
this
,
0
)
},
false
,
false
);
...
...
@@ -43,27 +45,9 @@ export class CommentMode implements modes.IMode {
comments
:
commentsConfig
};
}
public
getId
():
string
{
return
'
tests.commentMode
'
;
}
public
toSimplifiedMode
():
modes
.
IMode
{
return
this
;
}
}
export
class
TestingMode
implements
modes
.
IMode
{
public
getId
():
string
{
return
'
testing
'
;
}
public
toSimplifiedMode
():
modes
.
IMode
{
return
this
;
}
}
export
abstract
class
AbstractIndentingMode
extends
Testing
Mode
{
export
abstract
class
AbstractIndentingMode
extends
Mock
Mode
{
public
getElectricCharacters
():
string
[]
{
return
null
;
...
...
@@ -100,7 +84,7 @@ export class ModelState1 extends AbstractState {
}
}
export
class
ModelMode1
extends
Testing
Mode
{
export
class
ModelMode1
extends
Mock
Mode
{
public
calledFor
:
string
[];
public
tokenizationSupport
:
modes
.
ITokenizationSupport
;
...
...
@@ -141,7 +125,7 @@ export class ModelState2 extends AbstractState {
}
}
export
class
ModelMode2
extends
Testing
Mode
{
export
class
ModelMode2
extends
Mock
Mode
{
public
calledFor
:
any
[];
public
tokenizationSupport
:
modes
.
ITokenizationSupport
;
...
...
@@ -155,78 +139,12 @@ export class ModelMode2 extends TestingMode {
}
}
export
class
BracketState
extends
AbstractState
{
private
allResults
:{
[
key
:
string
]:
modes
.
ITokenizationResult
;
};
constructor
(
mode
:
modes
.
IMode
)
{
super
(
mode
);
this
.
allResults
=
null
;
}
public
makeClone
():
BracketState
{
return
this
;
}
public
equals
(
other
:
modes
.
IState
):
boolean
{
return
true
;
}
public
tokenize
(
stream
:
modes
.
IStream
):
modes
.
ITokenizationResult
{
this
.
initializeAllResults
();
stream
.
setTokenRules
(
'
{}[]()
'
,
''
);
var
token
=
stream
.
nextToken
();
// Strade compiler bug: can't reference self in Object return creation.
var
state
:
modes
.
IState
=
this
;
if
(
this
.
allResults
.
hasOwnProperty
(
token
))
{
return
this
.
allResults
[
token
];
}
else
{
return
{
type
:
''
,
nextState
:
state
};
}
}
public
initializeAllResults
():
void
{
if
(
this
.
allResults
!==
null
)
{
return
;
}
this
.
allResults
=
{};
var
brackets
:
any
=
{
'
{
'
:
'
}
'
,
'
[
'
:
'
]
'
,
'
(
'
:
'
)
'
};
var
type
=
1
;
var
state
:
modes
.
IState
=
this
;
for
(
var
x
in
brackets
)
{
this
.
allResults
[
x
]
=
{
type
:
'
bracket
'
+
type
,
nextState
:
state
};
this
.
allResults
[
brackets
[
x
]]
=
{
type
:
'
bracket
'
+
type
,
nextState
:
state
};
type
++
;
}
}
}
export
class
BracketMode
extends
TestingMode
{
export
class
BracketMode
extends
MockMode
{
public
tokenizationSupport
:
modes
.
ITokenizationSupport
;
public
richEditSupport
:
modes
.
IRichEditSupport
;
constructor
()
{
super
();
this
.
tokenizationSupport
=
new
TokenizationSupport
(
this
,
{
getInitialState
:
()
=>
new
BracketState
(
this
)
},
false
,
false
);
this
.
richEditSupport
=
new
RichEditSupport
(
this
.
getId
(),
null
,
{
brackets
:
[
[
'
{
'
,
'
}
'
],
...
...
@@ -267,7 +185,7 @@ export class NState extends AbstractState {
}
}
export
class
NMode
extends
Testing
Mode
{
export
class
NMode
extends
Mock
Mode
{
private
n
:
number
;
...
...
src/vs/languages/javascript/test/common/javascript.test.ts
浏览文件 @
8bc4d854
...
...
@@ -10,7 +10,7 @@ import javascriptMode = require('vs/languages/javascript/common/javascript');
import
EditorCommon
=
require
(
'
vs/editor/common/editorCommon
'
);
import
Modes
=
require
(
'
vs/editor/common/modes
'
);
import
modesUtil
=
require
(
'
vs/editor/test/common/modesUtil
'
);
import
{
createLineContext
}
from
'
vs/editor/test/common/modesTestUtils
'
;
import
{
create
Mock
LineContext
}
from
'
vs/editor/test/common/modesTestUtils
'
;
suite
(
'
JS - Auto Indent
'
,
()
=>
{
...
...
@@ -63,7 +63,7 @@ suite('JS - Auto Indent', () => {
function
testElectricCharacter
(
line
:
string
,
offset
:
number
,
expected
:
Modes
.
IElectricAction
):
void
{
let
state
=
_mode
.
tokenizationSupport
.
getInitialState
();
var
lineTokens
=
_mode
.
tokenizationSupport
.
tokenize
(
line
,
state
);
let
actual
=
_mode
.
richEditSupport
.
electricCharacter
.
onElectricCharacter
(
createLineContext
(
line
,
lineTokens
),
offset
);
let
actual
=
_mode
.
richEditSupport
.
electricCharacter
.
onElectricCharacter
(
create
Mock
LineContext
(
line
,
lineTokens
),
offset
);
assert
.
deepEqual
(
actual
,
expected
,
'
LINE <<<
'
+
line
+
'
>>>, OFFSET: <<<
'
+
offset
+
'
>>>
'
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录