Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
f808c228
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f808c228
编写于
5月 25, 2018
作者:
R
Rob Lourens
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
EH search - add tests for non-file: schemes
上级
c64d97d9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
81 addition
and
29 deletion
+81
-29
src/vs/workbench/test/electron-browser/api/extHostSearch.test.ts
...workbench/test/electron-browser/api/extHostSearch.test.ts
+81
-29
未找到文件。
src/vs/workbench/test/electron-browser/api/extHostSearch.test.ts
浏览文件 @
f808c228
...
...
@@ -17,6 +17,7 @@ import * as vscode from 'vscode';
import
{
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
isPromiseCanceledError
}
from
'
vs/base/common/errors
'
;
import
{
Range
}
from
'
vs/workbench/api/node/extHostTypes
'
;
import
{
joinPath
}
from
'
vs/base/common/resources
'
;
let
rpcProtocol
:
TestRPCProtocol
;
let
extHostSearch
:
ExtHostSearch
;
...
...
@@ -53,8 +54,8 @@ class MockMainThreadSearch implements MainThreadSearchShape {
let
mockExtfs
:
Partial
<
typeof
extfs
>
;
suite
(
'
ExtHostSearch
'
,
()
=>
{
async
function
registerTestSearchProvider
(
provider
:
vscode
.
SearchProvider
):
TPromise
<
void
>
{
disposables
.
push
(
extHostSearch
.
registerSearchProvider
(
'
file
'
,
provider
));
async
function
registerTestSearchProvider
(
provider
:
vscode
.
SearchProvider
,
scheme
=
'
file
'
):
TPromise
<
void
>
{
disposables
.
push
(
extHostSearch
.
registerSearchProvider
(
scheme
,
provider
));
await
rpcProtocol
.
sync
();
}
...
...
@@ -121,12 +122,8 @@ suite('ExtHostSearch', () => {
const
rootFolderA
=
URI
.
file
(
'
/foo/bar1
'
);
const
rootFolderB
=
URI
.
file
(
'
/foo/bar2
'
);
// const rootFolderC = URI.file('/foo/bar3');
function
makeAbsoluteURI
(
root
:
URI
,
relativePath
:
string
):
URI
{
return
URI
.
file
(
path
.
join
(
root
.
fsPath
,
relativePath
));
}
const
fancyScheme
=
'
fancy
'
;
const
fancySchemeFolderA
=
URI
.
from
({
scheme
:
fancyScheme
,
path
:
'
/project/folder1
'
});
suite
(
'
File:
'
,
()
=>
{
...
...
@@ -162,9 +159,9 @@ suite('ExtHostSearch', () => {
test
(
'
simple results
'
,
async
()
=>
{
const
reportedResults
=
[
makeAbsoluteURI
(
rootFolderA
,
'
file1.ts
'
),
makeAbsoluteURI
(
rootFolderA
,
'
file2.ts
'
),
makeAbsoluteURI
(
rootFolderA
,
'
file3.ts
'
)
joinPath
(
rootFolderA
,
'
file1.ts
'
),
joinPath
(
rootFolderA
,
'
file2.ts
'
),
joinPath
(
rootFolderA
,
'
file3.ts
'
)
];
await
registerTestSearchProvider
({
...
...
@@ -383,7 +380,7 @@ suite('ExtHostSearch', () => {
compareURIs
(
results
,
[
makeAbsoluteURI
(
rootFolderA
,
'
file1.ts
'
)
joinPath
(
rootFolderA
,
'
file1.ts
'
)
]);
});
...
...
@@ -443,20 +440,20 @@ suite('ExtHostSearch', () => {
compareURIs
(
results
,
[
makeAbsoluteURI
(
rootFolderA
,
'
folder/fileA.scss
'
),
makeAbsoluteURI
(
rootFolderA
,
'
folder/file2.css
'
),
joinPath
(
rootFolderA
,
'
folder/fileA.scss
'
),
joinPath
(
rootFolderA
,
'
folder/file2.css
'
),
makeAbsoluteURI
(
rootFolderB
,
'
fileB.ts
'
),
makeAbsoluteURI
(
rootFolderB
,
'
fileB.js
'
),
makeAbsoluteURI
(
rootFolderB
,
'
file3.js
'
),
joinPath
(
rootFolderB
,
'
fileB.ts
'
),
joinPath
(
rootFolderB
,
'
fileB.js
'
),
joinPath
(
rootFolderB
,
'
file3.js
'
),
]);
});
test
(
'
max results = 1
'
,
async
()
=>
{
const
reportedResults
=
[
makeAbsoluteURI
(
rootFolderA
,
'
file1.ts
'
),
makeAbsoluteURI
(
rootFolderA
,
'
file2.ts
'
),
makeAbsoluteURI
(
rootFolderA
,
'
file3.ts
'
),
joinPath
(
rootFolderA
,
'
file1.ts
'
),
joinPath
(
rootFolderA
,
'
file2.ts
'
),
joinPath
(
rootFolderA
,
'
file3.ts
'
),
];
let
wasCanceled
=
false
;
...
...
@@ -490,9 +487,9 @@ suite('ExtHostSearch', () => {
test
(
'
max results = 2
'
,
async
()
=>
{
const
reportedResults
=
[
makeAbsoluteURI
(
rootFolderA
,
'
file1.ts
'
),
makeAbsoluteURI
(
rootFolderA
,
'
file2.ts
'
),
makeAbsoluteURI
(
rootFolderA
,
'
file3.ts
'
),
joinPath
(
rootFolderA
,
'
file1.ts
'
),
joinPath
(
rootFolderA
,
'
file2.ts
'
),
joinPath
(
rootFolderA
,
'
file3.ts
'
),
];
let
wasCanceled
=
false
;
...
...
@@ -567,9 +564,9 @@ suite('ExtHostSearch', () => {
test
(
'
respects filePattern
'
,
async
()
=>
{
const
reportedResults
=
[
makeAbsoluteURI
(
rootFolderA
,
'
file1.ts
'
),
makeAbsoluteURI
(
rootFolderA
,
'
file2.ts
'
),
makeAbsoluteURI
(
rootFolderA
,
'
file3.ts
'
),
joinPath
(
rootFolderA
,
'
file1.ts
'
),
joinPath
(
rootFolderA
,
'
file2.ts
'
),
joinPath
(
rootFolderA
,
'
file3.ts
'
),
];
await
registerTestSearchProvider
({
...
...
@@ -596,6 +593,35 @@ suite('ExtHostSearch', () => {
compareURIs
(
results
,
reportedResults
.
slice
(
2
));
});
test
(
'
works with non-file schemes
'
,
async
()
=>
{
const
reportedResults
=
[
joinPath
(
fancySchemeFolderA
,
'
file1.ts
'
),
joinPath
(
fancySchemeFolderA
,
'
file2.ts
'
),
joinPath
(
fancySchemeFolderA
,
'
file3.ts
'
),
];
await
registerTestSearchProvider
({
provideFileSearchResults
(
options
:
vscode
.
FileSearchOptions
,
progress
:
vscode
.
Progress
<
string
>
,
token
:
vscode
.
CancellationToken
):
Thenable
<
void
>
{
reportedResults
.
forEach
(
r
=>
progress
.
report
(
path
.
basename
(
r
.
fsPath
)));
return
TPromise
.
wrap
(
null
);
}
},
fancyScheme
);
const
query
:
ISearchQuery
=
{
type
:
QueryType
.
File
,
filePattern
:
''
,
folderQueries
:
[
{
folder
:
fancySchemeFolderA
}
]
};
const
results
=
await
runFileSearch
(
query
);
compareURIs
(
results
,
reportedResults
);
});
// Mock fs?
// test('Returns result for absolute path', async () => {
// const queriedFile = makeFileResult(rootFolderA, 'file2.ts');
...
...
@@ -653,11 +679,11 @@ suite('ExtHostSearch', () => {
};
}
function
assertResults
(
actual
:
IFileMatch
[],
expected
:
vscode
.
TextSearchResult
[])
{
function
assertResults
(
actual
:
IFileMatch
[],
expected
:
vscode
.
TextSearchResult
[]
,
folder
=
rootFolderA
)
{
const
actualTextSearchResults
:
vscode
.
TextSearchResult
[]
=
[];
for
(
let
fileMatch
of
actual
)
{
// Make relative
const
relativePath
=
fileMatch
.
resource
.
fsPath
.
substr
(
rootFolderA
.
fsPath
.
length
+
1
);
const
relativePath
=
fileMatch
.
resource
.
toString
().
substr
(
folder
.
toString
()
.
length
+
1
);
for
(
let
lineMatch
of
fileMatch
.
lineMatches
)
{
for
(
let
[
offset
,
length
]
of
lineMatch
.
offsetAndLengths
)
{
actualTextSearchResults
.
push
({
...
...
@@ -884,7 +910,7 @@ suite('ExtHostSearch', () => {
test
(
'
multiroot sibling clause
'
,
async
()
=>
{
mockExtfs
.
readdir
=
(
_path
:
string
,
callback
:
(
error
:
Error
,
files
:
string
[])
=>
void
)
=>
{
if
(
_path
===
makeAbsoluteURI
(
rootFolderA
,
'
folder
'
).
fsPath
)
{
if
(
_path
===
joinPath
(
rootFolderA
,
'
folder
'
).
fsPath
)
{
callback
(
null
,
[
'
fileA.scss
'
,
'
fileA.css
'
,
...
...
@@ -1080,5 +1106,31 @@ suite('ExtHostSearch', () => {
assert
.
equal
(
results
.
length
,
2
);
assert
.
equal
(
cancels
,
2
);
});
test
(
'
works with non-file schemes
'
,
async
()
=>
{
const
providedResults
:
vscode
.
TextSearchResult
[]
=
[
makeTextResult
(
'
file1.ts
'
),
makeTextResult
(
'
file2.ts
'
),
makeTextResult
(
'
file3.ts
'
)
];
await
registerTestSearchProvider
({
provideTextSearchResults
(
query
:
vscode
.
TextSearchQuery
,
options
:
vscode
.
TextSearchOptions
,
progress
:
vscode
.
Progress
<
vscode
.
TextSearchResult
>
,
token
:
vscode
.
CancellationToken
):
Thenable
<
void
>
{
providedResults
.
forEach
(
r
=>
progress
.
report
(
r
));
return
TPromise
.
wrap
(
null
);
}
},
fancyScheme
);
const
query
:
ISearchQuery
=
{
type
:
QueryType
.
Text
,
folderQueries
:
[
{
folder
:
fancySchemeFolderA
}
]
};
const
results
=
await
runTextSearch
(
getPattern
(
'
foo
'
),
query
);
assertResults
(
results
,
providedResults
,
fancySchemeFolderA
);
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录