Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
ed79775c
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,发现更多精彩内容 >>
提交
ed79775c
编写于
8月 14, 2018
作者:
J
Jackson Kearl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix tests
上级
8bf65af9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
23 addition
and
22 deletion
+23
-22
src/vs/workbench/services/preferences/common/preferencesModels.ts
...orkbench/services/preferences/common/preferencesModels.ts
+11
-10
src/vs/workbench/services/preferences/test/common/preferencesModel.test.ts
...services/preferences/test/common/preferencesModel.test.ts
+12
-12
未找到文件。
src/vs/workbench/services/preferences/common/preferencesModels.ts
浏览文件 @
ed79775c
...
...
@@ -983,9 +983,16 @@ export function createValidator(prop: IConfigurationPropertySchema): ((value: an
patternRegex
=
new
RegExp
(
prop
.
pattern
);
}
const
type
=
Array
.
isArray
(
prop
.
type
)
?
prop
.
type
:
[
prop
.
type
];
const
canBeType
=
(
t
:
string
)
=>
type
.
indexOf
(
t
)
>
-
1
;
const
isNullable
=
canBeType
(
'
null
'
);
const
isNumeric
=
(
canBeType
(
'
number
'
)
||
canBeType
(
'
integer
'
))
&&
(
type
.
length
===
1
||
type
.
length
===
2
&&
isNullable
);
const
isIntegral
=
(
canBeType
(
'
integer
'
))
&&
(
type
.
length
===
1
||
type
.
length
===
2
&&
isNullable
);
type
Validator
<
T
>
=
{
enabled
:
boolean
,
isValid
:
(
value
:
T
)
=>
boolean
;
message
:
string
};
let
numericValidations
:
Validator
<
number
>
[]
=
[
let
numericValidations
:
Validator
<
number
>
[]
=
isNumeric
?
[
{
enabled
:
exclusiveMax
!==
undefined
&&
(
prop
.
maximum
===
undefined
||
exclusiveMax
<=
prop
.
maximum
),
isValid
:
(
value
=>
value
<
exclusiveMax
),
...
...
@@ -1013,11 +1020,11 @@ export function createValidator(prop: IConfigurationPropertySchema): ((value: an
message
:
nls
.
localize
(
'
validations.multipleOf
'
,
"
Value must be a multiple of {0}.
"
,
prop
.
multipleOf
)
},
{
enabled
:
prop
.
type
===
'
integer
'
,
isValid
:
(
value
=>
value
%
1
===
0
&&
value
.
indexOf
(
'
.
'
)
===
-
1
),
enabled
:
isIntegral
,
isValid
:
(
value
=>
value
%
1
===
0
),
message
:
nls
.
localize
(
'
validations.expectedInteger
'
,
"
Value must be an integer.
"
)
},
].
filter
(
validation
=>
validation
.
enabled
);
].
filter
(
validation
=>
validation
.
enabled
)
:
[]
;
let
stringValidations
:
Validator
<
string
>
[]
=
[
{
...
...
@@ -1037,12 +1044,6 @@ export function createValidator(prop: IConfigurationPropertySchema): ((value: an
},
].
filter
(
validation
=>
validation
.
enabled
);
const
type
=
Array
.
isArray
(
prop
.
type
)
?
prop
.
type
:
[
prop
.
type
];
const
canBeType
=
(
t
:
string
)
=>
type
.
indexOf
(
t
)
>
-
1
;
const
isNullable
=
canBeType
(
'
null
'
);
const
isNumeric
=
(
canBeType
(
'
number
'
)
||
canBeType
(
'
integer
'
))
&&
(
type
.
length
===
1
||
type
.
length
===
2
&&
isNullable
);
if
(
prop
.
type
===
'
string
'
&&
stringValidations
.
length
===
0
)
{
return
null
;
}
return
value
=>
{
...
...
src/vs/workbench/services/preferences/test/common/preferencesModel.test.ts
浏览文件 @
ed79775c
...
...
@@ -17,15 +17,15 @@ suite('Preferences Model test', () => {
}
public
accepts
(
input
)
{
assert
(
this
.
validator
(
input
)
===
''
,
`Expected
${
JSON
.
stringify
(
this
.
settings
)}
to accept
${
input
}
. Got
${
this
.
validator
(
input
)}
.`
);
assert
.
equal
(
this
.
validator
(
input
),
''
,
`Expected
${
JSON
.
stringify
(
this
.
settings
)}
to accept
\`
${
input
}
\`
. Got
${
this
.
validator
(
input
)}
.`
);
}
public
rejects
(
input
)
{
assert
(
this
.
validator
(
input
)
!==
''
,
`Expected
${
JSON
.
stringify
(
this
.
settings
)}
to reject
${
input
}
.`
);
assert
.
notEqual
(
this
.
validator
(
input
),
''
,
`Expected
${
JSON
.
stringify
(
this
.
settings
)}
to reject
\`
${
input
}
\`
.`
);
return
{
withMessage
:
(
message
)
=>
assert
(
this
.
validator
(
input
).
indexOf
(
message
)
>
-
1
,
`Expected error of
${
JSON
.
stringify
(
this
.
settings
)}
on
${
input
}
to contain
${
message
}
. Got
${
this
.
validator
(
input
)}
.`
)
`Expected error of
${
JSON
.
stringify
(
this
.
settings
)}
on
\`
${
input
}
\`
to contain
${
message
}
. Got
${
this
.
validator
(
input
)}
.`
)
};
}
...
...
@@ -165,23 +165,23 @@ suite('Preferences Model test', () => {
test
(
'
null is allowed only when expected
'
,
()
=>
{
{
const
nullableIntegers
=
new
Tester
({
multipleOf
:
1
,
type
:
[
'
integer
'
,
'
null
'
]
});
const
nullableIntegers
=
new
Tester
({
type
:
[
'
integer
'
,
'
null
'
]
});
nullableIntegers
.
accepts
(
'
2
'
);
nullableIntegers
.
rejects
(
'
.5
'
);
nullableIntegers
.
rejec
ts
(
'
2.0
'
);
nullableIntegers
.
accep
ts
(
'
2.0
'
);
nullableIntegers
.
rejects
(
'
2j
'
);
nullableIntegers
.
accepts
(
''
);
}
{
const
nonnullableIntegers
=
new
Tester
({
multipleOf
:
1
,
type
:
[
'
integer
'
]
});
const
nonnullableIntegers
=
new
Tester
({
type
:
[
'
integer
'
]
});
nonnullableIntegers
.
accepts
(
'
2
'
);
nonnullableIntegers
.
rejects
(
'
.5
'
);
nonnullableIntegers
.
rejec
ts
(
'
2.0
'
);
nonnullableIntegers
.
accep
ts
(
'
2.0
'
);
nonnullableIntegers
.
rejects
(
'
2j
'
);
nonnullableIntegers
.
rejects
(
''
);
}
{
const
nullableNumbers
=
new
Tester
({
multipleOf
:
1
,
type
:
[
'
number
'
,
'
null
'
]
});
const
nullableNumbers
=
new
Tester
({
type
:
[
'
number
'
,
'
null
'
]
});
nullableNumbers
.
accepts
(
'
2
'
);
nullableNumbers
.
accepts
(
'
.5
'
);
nullableNumbers
.
accepts
(
'
2.0
'
);
...
...
@@ -189,7 +189,7 @@ suite('Preferences Model test', () => {
nullableNumbers
.
accepts
(
''
);
}
{
const
nonnullableNumbers
=
new
Tester
({
multipleOf
:
1
,
type
:
[
'
number
'
]
});
const
nonnullableNumbers
=
new
Tester
({
type
:
[
'
number
'
]
});
nonnullableNumbers
.
accepts
(
'
2
'
);
nonnullableNumbers
.
accepts
(
'
.5
'
);
nonnullableNumbers
.
accepts
(
'
2.0
'
);
...
...
@@ -223,7 +223,7 @@ suite('Preferences Model test', () => {
test
(
'
patterns work
'
,
()
=>
{
{
const
urls
=
new
Tester
({
pattern
:
'
^(hello)*$
'
});
const
urls
=
new
Tester
({
pattern
:
'
^(hello)*$
'
,
type
:
'
string
'
});
urls
.
accepts
(
''
);
urls
.
rejects
(
'
hel
'
);
urls
.
accepts
(
'
hello
'
);
...
...
@@ -231,7 +231,7 @@ suite('Preferences Model test', () => {
urls
.
accepts
(
'
hellohello
'
);
}
{
const
urls
=
new
Tester
({
pattern
:
'
^(hello)*$
'
,
patternErrorMessage
:
'
err: must be friendly
'
});
const
urls
=
new
Tester
({
pattern
:
'
^(hello)*$
'
,
type
:
'
string
'
,
patternErrorMessage
:
'
err: must be friendly
'
});
urls
.
accepts
(
''
);
urls
.
rejects
(
'
hel
'
).
withMessage
(
'
err: must be friendly
'
);
urls
.
accepts
(
'
hello
'
);
...
...
@@ -241,7 +241,7 @@ suite('Preferences Model test', () => {
});
test
(
'
custom error messages are shown
'
,
()
=>
{
const
withMessage
=
new
Tester
({
minLength
:
1
,
maxLength
:
0
,
errorMessage
:
'
always error!
'
});
const
withMessage
=
new
Tester
({
minLength
:
1
,
maxLength
:
0
,
type
:
'
string
'
,
errorMessage
:
'
always error!
'
});
withMessage
.
rejects
(
''
).
withMessage
(
'
always error!
'
);
withMessage
.
rejects
(
'
'
).
withMessage
(
'
always error!
'
);
withMessage
.
rejects
(
'
1
'
).
withMessage
(
'
always error!
'
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录