Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
410c0e70
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,发现更多精彩内容 >>
提交
410c0e70
编写于
9月 05, 2018
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify tests
上级
e4a63849
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
73 addition
and
51 deletion
+73
-51
src/vs/editor/contrib/wordPartOperations/test/wordPartOperations.test.ts
...ontrib/wordPartOperations/test/wordPartOperations.test.ts
+67
-49
src/vs/editor/test/browser/testCodeEditor.ts
src/vs/editor/test/browser/testCodeEditor.ts
+6
-2
未找到文件。
src/vs/editor/contrib/wordPartOperations/test/wordPartOperations.test.ts
浏览文件 @
410c0e70
...
...
@@ -7,10 +7,7 @@
import
*
as
assert
from
'
assert
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
withTestCodeEditor
}
from
'
vs/editor/test/browser/testCodeEditor
'
;
import
{
DeleteWordPartLeft
,
DeleteWordPartRight
,
CursorWordPartLeft
,
CursorWordPartRight
}
from
'
vs/editor/contrib/wordPartOperations/wordPartOperations
'
;
import
{
DeleteWordPartLeft
,
DeleteWordPartRight
,
CursorWordPartLeft
,
CursorWordPartRight
}
from
'
vs/editor/contrib/wordPartOperations/wordPartOperations
'
;
import
{
EditorCommand
}
from
'
vs/editor/browser/editorExtensions
'
;
import
{
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
...
...
@@ -36,56 +33,77 @@ suite('WordPartOperations', () => {
runEditorCommand
(
editor
,
_deleteWordPartRight
);
}
function
deserializePipePositions
(
text
:
string
):
[
string
,
Position
[]]
{
let
resultText
=
''
;
let
lineNumber
=
1
;
let
charIndex
=
0
;
let
positions
:
Position
[]
=
[];
for
(
let
i
=
0
,
len
=
text
.
length
;
i
<
len
;
i
++
)
{
const
chr
=
text
.
charAt
(
i
);
if
(
chr
===
'
\n
'
)
{
resultText
+=
chr
;
lineNumber
++
;
charIndex
=
0
;
continue
;
}
if
(
chr
===
'
|
'
)
{
positions
.
push
(
new
Position
(
lineNumber
,
charIndex
+
1
));
}
else
{
resultText
+=
chr
;
charIndex
++
;
}
}
return
[
resultText
,
positions
];
}
function
serializePipePositions
(
text
:
string
,
positions
:
Position
[]):
string
{
positions
.
sort
(
Position
.
compare
);
let
resultText
=
''
;
let
lineNumber
=
1
;
let
charIndex
=
0
;
for
(
let
i
=
0
,
len
=
text
.
length
;
i
<
len
;
i
++
)
{
const
chr
=
text
.
charAt
(
i
);
if
(
positions
.
length
>
0
&&
positions
[
0
].
lineNumber
===
lineNumber
&&
positions
[
0
].
column
===
charIndex
+
1
)
{
resultText
+=
'
|
'
;
positions
.
shift
();
}
resultText
+=
chr
;
if
(
chr
===
'
\n
'
)
{
lineNumber
++
;
charIndex
=
0
;
}
else
{
charIndex
++
;
}
}
return
resultText
;
}
test
(
'
move word part left basic
'
,
()
=>
{
withTestCodeEditor
([
'
start line
'
,
'
thisIsACamelCaseVar this_is_a_snake_case_var THIS_IS_CAPS_SNAKE this_ISMixedUse
'
,
'
end line
'
],
{},
(
editor
,
_
)
=>
{
editor
.
setPosition
(
new
Position
(
3
,
8
));
const
expectedStops
=
[
[
3
,
5
],
[
3
,
4
],
[
3
,
1
],
[
2
,
81
],
[
2
,
78
],
[
2
,
73
],
[
2
,
70
],
[
2
,
66
],
[
2
,
65
],
[
2
,
59
],
[
2
,
54
],
[
2
,
51
],
[
2
,
47
],
[
2
,
46
],
[
2
,
42
],
[
2
,
37
],
[
2
,
31
],
[
2
,
29
],
[
2
,
26
],
[
2
,
22
],
[
2
,
21
],
[
2
,
20
],
[
2
,
17
],
[
2
,
13
],
[
2
,
8
],
[
2
,
7
],
[
2
,
5
],
[
2
,
1
],
[
1
,
11
],
[
1
,
7
],
[
1
,
6
],
[
1
,
1
]
];
const
EXPECTED
=
[
'
|start| |line|
'
,
'
|this|Is|A|Camel|Case|Var| | |this|_is|_a|_snake|_case|_var| |THIS|_IS|_CAPS|_SNAKE| |this|_IS|Mixed|Use|
'
,
'
|end| |line
'
].
join
(
'
\n
'
);
const
[
text
,]
=
deserializePipePositions
(
EXPECTED
);
let
actualStops
:
number
[][]
=
[];
for
(
let
i
=
0
;
i
<
expectedStops
.
length
;
i
++
)
{
withTestCodeEditor
(
text
,
{},
(
editor
,
_
)
=>
{
editor
.
setPosition
(
new
Position
(
1000
,
1000
));
let
actualStops
:
Position
[]
=
[];
let
previousStop
:
Position
=
null
;
while
(
true
)
{
moveWordPartLeft
(
editor
);
const
pos
=
editor
.
getPosition
();
actualStops
.
push
([
pos
.
lineNumber
,
pos
.
column
]);
const
currentStop
=
editor
.
getPosition
();
if
(
previousStop
&&
currentStop
.
equals
(
previousStop
))
{
break
;
}
actualStops
.
push
(
currentStop
);
previousStop
=
currentStop
;
}
assert
.
deepEqual
(
actualStops
,
expectedStops
);
const
actual
=
serializePipePositions
(
text
,
actualStops
);
assert
.
deepEqual
(
actual
,
EXPECTED
);
});
});
...
...
src/vs/editor/test/browser/testCodeEditor.ts
浏览文件 @
410c0e70
...
...
@@ -72,10 +72,14 @@ export interface TestCodeEditorCreationOptions extends editorOptions.IEditorOpti
serviceCollection
?:
ServiceCollection
;
}
export
function
withTestCodeEditor
(
text
:
string
[],
options
:
TestCodeEditorCreationOptions
,
callback
:
(
editor
:
TestCodeEditor
,
cursor
:
Cursor
)
=>
void
):
void
{
export
function
withTestCodeEditor
(
text
:
string
|
string
[],
options
:
TestCodeEditorCreationOptions
,
callback
:
(
editor
:
TestCodeEditor
,
cursor
:
Cursor
)
=>
void
):
void
{
// create a model if necessary and remember it in order to dispose it.
if
(
!
options
.
model
)
{
options
.
model
=
TextModel
.
createFromString
(
text
.
join
(
'
\n
'
));
if
(
typeof
text
===
'
string
'
)
{
options
.
model
=
TextModel
.
createFromString
(
text
);
}
else
{
options
.
model
=
TextModel
.
createFromString
(
text
.
join
(
'
\n
'
));
}
}
let
editor
=
<
TestCodeEditor
>
createTestCodeEditor
(
options
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录