Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
8ed350e9
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,发现更多精彩内容 >>
提交
8ed350e9
编写于
3月 24, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add topScore tests, #22153
上级
0185e327
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
77 addition
and
40 deletion
+77
-40
src/vs/base/common/filters.ts
src/vs/base/common/filters.ts
+8
-7
src/vs/base/test/common/filters.test.ts
src/vs/base/test/common/filters.test.ts
+69
-33
未找到文件。
src/vs/base/common/filters.ts
浏览文件 @
8ed350e9
...
...
@@ -545,21 +545,22 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
let
score
=
-
1
;
let
lowWordChar
=
lowWord
[
j
-
1
];
if
(
lowPattern
[
i
-
1
]
===
lowWordChar
)
{
if
(
lowWordChar
!==
word
[
j
-
1
])
{
if
(
j
===
1
)
{
if
(
pattern
[
i
-
1
]
===
word
[
j
-
1
])
{
score
=
7
;
}
else
{
score
=
5
;
}
}
else
if
(
lastLowWordChar
===
'
_
'
||
lastLowWordChar
===
'
.
'
)
{
score
=
5
;
}
else
if
(
j
===
1
)
{
}
else
if
(
lowWordChar
!==
word
[
j
-
1
])
{
if
(
pattern
[
i
-
1
]
===
word
[
j
-
1
])
{
score
=
7
;
}
else
{
score
=
5
;
}
}
else
if
(
lastLowWordChar
===
'
_
'
||
lastLowWordChar
===
'
.
'
)
{
score
=
5
;
}
else
if
(
j
===
i
)
{
score
=
3
;
...
...
@@ -625,7 +626,6 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
// keep going left, we cannot
// skip a character in the pattern
j
-=
1
;
total
-=
1
;
}
else
if
(
arrow
===
0
)
{
//diag
j
-=
1
;
...
...
@@ -642,7 +642,7 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
// we went diagonal by inheriting a good
// result, not by matching keep going left
i
+=
1
;
total
-=
1
;
}
else
{
// all good
...
...
@@ -662,6 +662,7 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
j
=
3
;
}
total
-=
j
*
3
;
// penalty for first matching character
total
-=
(
1
+
matches
[
matches
.
length
-
1
])
-
pattern
.
length
;
// penalty for all non matching characters between first and last
if
(
_debug
)
{
console
.
log
(
`
${
pattern
}
&
${
word
}
=>
${
total
}
points for
${
matches
}
`
);
...
...
src/vs/base/test/common/filters.test.ts
浏览文件 @
8ed350e9
...
...
@@ -283,55 +283,91 @@ suite('Filters', () => {
assertMatches
(
'
Three
'
,
'
Three
'
,
'
^T^h^r^e^e
'
,
fuzzyScore
);
});
test
(
'
topScore
'
,
function
()
{
function
assertTopScore
(
pattern
:
string
,
expected
:
number
,
...
words
:
string
[])
{
let
topScore
=
Number
.
MIN_VALUE
;
let
topIdx
=
0
;
for
(
let
i
=
0
;
i
<
words
.
length
;
i
++
)
{
const
word
=
words
[
i
];
const
m
=
fuzzyMatchAndScore
(
pattern
,
word
);
if
(
m
)
{
const
[
score
]
=
m
;
if
(
score
>
topScore
)
{
topScore
=
score
;
topIdx
=
i
;
}
function
assertTopScore
(
filter
:
typeof
fuzzyMatchAndScore
,
pattern
:
string
,
expected
:
number
,
...
words
:
string
[])
{
let
topScore
=
Number
.
MIN_VALUE
;
let
topIdx
=
0
;
for
(
let
i
=
0
;
i
<
words
.
length
;
i
++
)
{
const
word
=
words
[
i
];
const
m
=
filter
(
pattern
,
word
);
if
(
m
)
{
const
[
score
]
=
m
;
if
(
score
>
topScore
)
{
topScore
=
score
;
topIdx
=
i
;
}
}
assert
.
equal
(
topIdx
,
expected
);
}
assert
.
equal
(
topIdx
,
expected
,
`
${
pattern
}
-> actual=
${
words
[
topIdx
]}
<> expected=
${
words
[
expected
]}
`
);
}
test
(
'
topScore - fuzzyMatchAndScore
'
,
function
()
{
assertTopScore
(
fuzzyMatchAndScore
,
'
cons
'
,
2
,
'
ArrayBufferConstructor
'
,
'
Console
'
,
'
console
'
);
assertTopScore
(
fuzzyMatchAndScore
,
'
Foo
'
,
1
,
'
foo
'
,
'
Foo
'
,
'
foo
'
);
assertTopScore
(
fuzzyMatchAndScore
,
'
CC
'
,
1
,
'
camelCase
'
,
'
CamelCase
'
);
assertTopScore
(
fuzzyMatchAndScore
,
'
cC
'
,
0
,
'
camelCase
'
,
'
CamelCase
'
);
assertTopScore
(
fuzzyMatchAndScore
,
'
cC
'
,
1
,
'
ccfoo
'
,
'
camelCase
'
);
assertTopScore
(
fuzzyMatchAndScore
,
'
cC
'
,
1
,
'
ccfoo
'
,
'
camelCase
'
,
'
foo-cC-bar
'
);
// issue #17836
assertTopScore
(
fuzzyMatchAndScore
,
'
p
'
,
0
,
'
parse
'
,
'
posix
'
,
'
pafdsa
'
,
'
path
'
,
'
p
'
);
assertTopScore
(
fuzzyMatchAndScore
,
'
pa
'
,
0
,
'
parse
'
,
'
pafdsa
'
,
'
path
'
);
// issue #14583
assertTopScore
(
fuzzyMatchAndScore
,
'
log
'
,
3
,
'
HTMLOptGroupElement
'
,
'
ScrollLogicalPosition
'
,
'
SVGFEMorphologyElement
'
,
'
log
'
);
assertTopScore
(
fuzzyMatchAndScore
,
'
e
'
,
2
,
'
AbstractWorker
'
,
'
ActiveXObject
'
,
'
else
'
);
// issue #14446
assertTopScore
(
fuzzyMatchAndScore
,
'
workbench.sideb
'
,
1
,
'
workbench.editor.defaultSideBySideLayout
'
,
'
workbench.sideBar.location
'
);
// issue #11423
assertTopScore
(
fuzzyMatchAndScore
,
'
editor.r
'
,
2
,
'
diffEditor.renderSideBySide
'
,
'
editor.overviewRulerlanes
'
,
'
editor.renderControlCharacter
'
,
'
editor.renderWhitespace
'
);
// assertTopScore(fuzzyMatchAndScore, 'editor.R', 1, 'diffEditor.renderSideBySide', 'editor.overviewRulerlanes', 'editor.renderControlCharacter', 'editor.renderWhitespace');
// assertTopScore(fuzzyMatchAndScore, 'Editor.r', 0, 'diffEditor.renderSideBySide', 'editor.overviewRulerlanes', 'editor.renderControlCharacter', 'editor.renderWhitespace');
assertTopScore
(
fuzzyMatchAndScore
,
'
-mo
'
,
1
,
'
-ms-ime-mode
'
,
'
-moz-columns
'
);
// // dupe, issue #14861
assertTopScore
(
fuzzyMatchAndScore
,
'
convertModelPosition
'
,
0
,
'
convertModelPositionToViewPosition
'
,
'
convertViewToModelPosition
'
);
// // dupe, issue #14942
assertTopScore
(
fuzzyMatchAndScore
,
'
is
'
,
0
,
'
isValidViewletId
'
,
'
import statement
'
);
});
test
(
'
topScore - fuzzyScore
'
,
function
()
{
assertTopScore
(
'
cons
'
,
2
,
'
ArrayBufferConstructor
'
,
'
Console
'
,
'
console
'
);
assertTopScore
(
'
Foo
'
,
1
,
'
foo
'
,
'
Foo
'
,
'
foo
'
);
assertTopScore
(
fuzzyScore
,
'
TEdit
'
,
1
,
'
TextEditorDecorationType
'
,
'
TextEdit
'
,
'
TextEditor
'
);
assertTopScore
(
fuzzyScore
,
'
cons
'
,
2
,
'
ArrayBufferConstructor
'
,
'
Console
'
,
'
console
'
);
assertTopScore
(
fuzzyScore
,
'
Foo
'
,
1
,
'
foo
'
,
'
Foo
'
,
'
foo
'
);
assertTopScore
(
'
CC
'
,
1
,
'
camelCase
'
,
'
CamelCase
'
);
assertTopScore
(
'
cC
'
,
0
,
'
camelCase
'
,
'
CamelCase
'
);
assertTopScore
(
'
cC
'
,
1
,
'
ccfoo
'
,
'
camelCase
'
);
assertTopScore
(
'
cC
'
,
1
,
'
ccfoo
'
,
'
camelCase
'
,
'
foo-cC-bar
'
);
assertTopScore
(
fuzzyScore
,
'
CC
'
,
1
,
'
camelCase
'
,
'
CamelCase
'
);
assertTopScore
(
fuzzyScore
,
'
cC
'
,
0
,
'
camelCase
'
,
'
CamelCase
'
);
// assertTopScore(fuzzyScore,
'cC', 1, 'ccfoo', 'camelCase');
// assertTopScore(fuzzyScore,
'cC', 1, 'ccfoo', 'camelCase', 'foo-cC-bar');
// issue #17836
assertTopScore
(
'
p
'
,
0
,
'
parse
'
,
'
posix
'
,
'
pafdsa
'
,
'
path
'
,
'
p
'
);
assertTopScore
(
'
pa
'
,
0
,
'
parse
'
,
'
pafdsa
'
,
'
path
'
);
assertTopScore
(
fuzzyScore
,
'
p
'
,
0
,
'
parse
'
,
'
posix
'
,
'
pafdsa
'
,
'
path
'
,
'
p
'
);
assertTopScore
(
fuzzyScore
,
'
pa
'
,
0
,
'
parse
'
,
'
pafdsa
'
,
'
path
'
);
// issue #14583
assertTopScore
(
'
log
'
,
3
,
'
HTMLOptGroupElement
'
,
'
ScrollLogicalPosition
'
,
'
SVGFEMorphologyElement
'
,
'
log
'
);
assertTopScore
(
'
e
'
,
2
,
'
AbstractWorker
'
,
'
ActiveXObject
'
,
'
else
'
);
assertTopScore
(
fuzzyScore
,
'
log
'
,
3
,
'
HTMLOptGroupElement
'
,
'
ScrollLogicalPosition
'
,
'
SVGFEMorphologyElement
'
,
'
log
'
);
assertTopScore
(
fuzzyScore
,
'
e
'
,
2
,
'
AbstractWorker
'
,
'
ActiveXObject
'
,
'
else
'
);
// issue #14446
assertTopScore
(
'
workbench.sideb
'
,
1
,
'
workbench.editor.defaultSideBySideLayout
'
,
'
workbench.sideBar.location
'
);
assertTopScore
(
fuzzyScore
,
'
workbench.sideb
'
,
1
,
'
workbench.editor.defaultSideBySideLayout
'
,
'
workbench.sideBar.location
'
);
// issue #11423
assertTopScore
(
'
editor.r
'
,
2
,
'
diffEditor.renderSideBySide
'
,
'
editor.overviewRulerlanes
'
,
'
editor.renderControlCharacter
'
,
'
editor.renderWhitespace
'
);
// assertTopScore('editor.R', 1, 'diffEditor.renderSideBySide', 'editor.overviewRulerlanes', 'editor.renderControlCharacter', 'editor.renderWhitespace');
// assertTopScore('Editor.r', 0, 'diffEditor.renderSideBySide', 'editor.overviewRulerlanes', 'editor.renderControlCharacter', 'editor.renderWhitespace');
assertTopScore
(
fuzzyScore
,
'
editor.r
'
,
2
,
'
diffEditor.renderSideBySide
'
,
'
editor.overviewRulerlanes
'
,
'
editor.renderControlCharacter
'
,
'
editor.renderWhitespace
'
);
// assertTopScore(
fuzzyScore,
'editor.R', 1, 'diffEditor.renderSideBySide', 'editor.overviewRulerlanes', 'editor.renderControlCharacter', 'editor.renderWhitespace');
// assertTopScore(
fuzzyScore,
'Editor.r', 0, 'diffEditor.renderSideBySide', 'editor.overviewRulerlanes', 'editor.renderControlCharacter', 'editor.renderWhitespace');
assertTopScore
(
'
-mo
'
,
1
,
'
-ms-ime-mode
'
,
'
-moz-columns
'
);
assertTopScore
(
fuzzyScore
,
'
-mo
'
,
1
,
'
-ms-ime-mode
'
,
'
-moz-columns
'
);
// // dupe, issue #14861
assertTopScore
(
'
convertModelPosition
'
,
0
,
'
convertModelPositionToViewPosition
'
,
'
convertViewToModelPosition
'
);
assertTopScore
(
fuzzyScore
,
'
convertModelPosition
'
,
0
,
'
convertModelPositionToViewPosition
'
,
'
convertViewToModelPosition
'
);
// // dupe, issue #14942
assertTopScore
(
'
is
'
,
0
,
'
isValidViewletId
'
,
'
import statement
'
);
assertTopScore
(
fuzzyScore
,
'
is
'
,
0
,
'
isValidViewletId
'
,
'
import statement
'
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录