Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
4913e7f6
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,发现更多精彩内容 >>
提交
4913e7f6
编写于
12月 15, 2017
作者:
R
Ramya Achutha Rao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Split emmet abbreviation tests
上级
64fec2b4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
493 addition
and
466 deletion
+493
-466
extensions/emmet/src/test/abbreviationAction.test.ts
extensions/emmet/src/test/abbreviationAction.test.ts
+2
-466
extensions/emmet/src/test/cssAbbreviationAction.test.ts
extensions/emmet/src/test/cssAbbreviationAction.test.ts
+301
-0
extensions/emmet/src/test/wrapWithAbbreviation.test.ts
extensions/emmet/src/test/wrapWithAbbreviation.test.ts
+190
-0
未找到文件。
extensions/emmet/src/test/abbreviationAction.test.ts
浏览文件 @
4913e7f6
...
...
@@ -5,51 +5,12 @@
import
'
mocha
'
;
import
*
as
assert
from
'
assert
'
;
import
{
Selection
,
workspace
,
CompletionList
,
CancellationTokenSource
,
Position
}
from
'
vscode
'
;
import
{
Selection
,
workspace
,
CompletionList
,
CancellationTokenSource
}
from
'
vscode
'
;
import
{
withRandomFileEditor
,
closeAllEditors
}
from
'
./testUtils
'
;
import
{
expandEmmetAbbreviation
,
wrapWithAbbreviation
,
wrapIndividualLinesWithAbbreviation
}
from
'
../abbreviationActions
'
;
import
{
expandEmmetAbbreviation
}
from
'
../abbreviationActions
'
;
import
{
DefaultCompletionItemProvider
}
from
'
../defaultCompletionProvider
'
;
const
completionProvider
=
new
DefaultCompletionItemProvider
();
const
cssContents
=
`
.boo {
margin: 20px 10px;
m10
background-image: url('tryme.png');
m10
}
.boo .hoo {
margin: 10px;
ind
}
`
;
const
scssContents
=
`
.boo {
margin: 10px;
p10
.hoo {
p20
}
}
@include b(alert) {
margin: 10px;
p30
@include b(alert) {
p40
}
}
.foo {
margin: 10px;
margin: a
.hoo {
color: #000;
}
}
`
;
const
htmlContents
=
`
<body class="header">
...
...
@@ -74,53 +35,6 @@ const htmlContents = `
</body>
`
;
const
htmlContentsForWrapTests
=
`
<ul class="nav main">
<li class="item1">img</li>
<li class="item2">$hithere</li>
</ul>
`
;
const
wrapBlockElementExpected
=
`
<ul class="nav main">
<div>
<li class="item1">img</li>
</div>
<div>
<li class="item2">$hithere</li>
</div>
</ul>
`
;
const
wrapInlineElementExpected
=
`
<ul class="nav main">
<span><li class="item1">img</li></span>
<span><li class="item2">$hithere</li></span>
</ul>
`
;
const
wrapSnippetExpected
=
`
<ul class="nav main">
<a href=""><li class="item1">img</li></a>
<a href=""><li class="item2">$hithere</li></a>
</ul>
`
;
const
wrapMultiLineAbbrExpected
=
`
<ul class="nav main">
<ul>
<li>
<li class="item1">img</li>
</li>
</ul>
<ul>
<li>
<li class="item2">$hithere</li>
</li>
</ul>
</ul>
`
;
suite
(
'
Tests for Expand Abbreviations (HTML)
'
,
()
=>
{
teardown
(()
=>
{
// Reset config and close all editors
...
...
@@ -367,369 +281,6 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
});
suite
(
'
Tests for Expand Abbreviations (CSS)
'
,
()
=>
{
teardown
(
closeAllEditors
);
test
(
'
Expand abbreviation (CSS)
'
,
()
=>
{
return
withRandomFileEditor
(
cssContents
,
'
css
'
,
(
editor
,
doc
)
=>
{
editor
.
selections
=
[
new
Selection
(
3
,
1
,
3
,
4
),
new
Selection
(
5
,
1
,
5
,
4
)];
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
cssContents
.
replace
(
/m10/g
,
'
margin: 10px;
'
));
return
Promise
.
resolve
();
});
});
});
test
(
'
Skip when typing property values when there is a property in the next line (CSS)
'
,
()
=>
{
const
testContent
=
`
.foo {
margin: a
margin: 10px;
}
`
;
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
doc
)
=>
{
editor
.
selection
=
new
Selection
(
2
,
10
,
2
,
10
);
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
testContent
);
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
2
,
10
),
cancelSrc
.
token
);
if
(
completionPromise
)
{
assert
.
equal
(
1
,
2
,
`Invalid completion at property value`
);
}
return
Promise
.
resolve
();
});
});
});
test
(
'
Skip when typing property values when there is a property in the previous line (CSS)
'
,
()
=>
{
const
testContent
=
`
.foo {
margin: 10px;
margin: a
}
`
;
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
doc
)
=>
{
editor
.
selection
=
new
Selection
(
3
,
10
,
3
,
10
);
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
testContent
);
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
3
,
10
),
cancelSrc
.
token
);
if
(
completionPromise
)
{
assert
.
equal
(
1
,
2
,
`Invalid completion at property value`
);
}
return
Promise
.
resolve
();
});
});
});
test
(
'
Skip when typing property values when it is the only property in the rule (CSS)
'
,
()
=>
{
const
testContent
=
`
.foo {
margin: a
}
`
;
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
doc
)
=>
{
editor
.
selection
=
new
Selection
(
2
,
10
,
2
,
10
);
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
testContent
);
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
2
,
10
),
cancelSrc
.
token
);
if
(
completionPromise
)
{
assert
.
equal
(
1
,
2
,
`Invalid completion at property value`
);
}
return
Promise
.
resolve
();
});
});
});
test
(
'
Expand abbreviation in completion list (CSS)
'
,
()
=>
{
const
abbreviation
=
'
m10
'
;
const
expandedText
=
'
margin: 10px;
'
;
return
withRandomFileEditor
(
cssContents
,
'
css
'
,
(
editor
,
doc
)
=>
{
editor
.
selection
=
new
Selection
(
3
,
1
,
3
,
4
);
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise1
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
3
,
4
),
cancelSrc
.
token
);
const
completionPromise2
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
5
,
4
),
cancelSrc
.
token
);
if
(
!
completionPromise1
||
!
completionPromise2
)
{
assert
.
equal
(
1
,
2
,
`Problem with expanding m10`
);
return
Promise
.
resolve
();
}
const
callBack
=
(
completionList
:
CompletionList
)
=>
{
if
(
!
completionList
.
items
||
!
completionList
.
items
.
length
)
{
assert
.
equal
(
1
,
2
,
`Problem with expanding m10`
);
return
;
}
const
emmetCompletionItem
=
completionList
.
items
[
0
];
assert
.
equal
(
emmetCompletionItem
.
label
,
expandedText
,
`Label of completion item doesnt match.`
);
assert
.
equal
((
<
string
>
emmetCompletionItem
.
documentation
||
''
).
replace
(
/
\|
/g
,
''
),
expandedText
,
`Docs of completion item doesnt match.`
);
assert
.
equal
(
emmetCompletionItem
.
filterText
,
abbreviation
,
`FilterText of completion item doesnt match.`
);
};
return
Promise
.
all
<
CompletionList
>
([
completionPromise1
,
completionPromise2
]).
then
(([
result1
,
result2
])
=>
{
callBack
(
result1
);
callBack
(
result2
);
return
Promise
.
resolve
();
});
});
});
test
(
'
Expand abbreviation (SCSS)
'
,
()
=>
{
return
withRandomFileEditor
(
scssContents
,
'
scss
'
,
(
editor
,
doc
)
=>
{
editor
.
selections
=
[
new
Selection
(
3
,
4
,
3
,
4
),
new
Selection
(
5
,
5
,
5
,
5
),
new
Selection
(
11
,
4
,
11
,
4
),
new
Selection
(
14
,
5
,
14
,
5
)
];
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
scssContents
.
replace
(
/p
(\d\d)
/g
,
'
padding: $1px;
'
));
return
Promise
.
resolve
();
});
});
});
test
(
'
Expand abbreviation in completion list (SCSS)
'
,
()
=>
{
return
withRandomFileEditor
(
scssContents
,
'
scss
'
,
(
editor
,
doc
)
=>
{
editor
.
selection
=
new
Selection
(
3
,
4
,
3
,
4
);
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise1
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
3
,
4
),
cancelSrc
.
token
);
const
completionPromise2
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
5
,
5
),
cancelSrc
.
token
);
const
completionPromise3
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
11
,
4
),
cancelSrc
.
token
);
const
completionPromise4
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
14
,
5
),
cancelSrc
.
token
);
if
(
!
completionPromise1
)
{
assert
.
equal
(
1
,
2
,
`Problem with expanding padding abbreviations at line 3 col 4`
);
}
if
(
!
completionPromise2
)
{
assert
.
equal
(
1
,
2
,
`Problem with expanding padding abbreviations at line 5 col 5`
);
}
if
(
!
completionPromise3
)
{
assert
.
equal
(
1
,
2
,
`Problem with expanding padding abbreviations at line 11 col 4`
);
}
if
(
!
completionPromise4
)
{
assert
.
equal
(
1
,
2
,
`Problem with expanding padding abbreviations at line 14 col 5`
);
}
if
(
!
completionPromise1
||
!
completionPromise2
||
!
completionPromise3
||
!
completionPromise4
)
{
return
Promise
.
resolve
();
}
const
callBack
=
(
completionList
:
CompletionList
,
abbreviation
,
expandedText
)
=>
{
if
(
!
completionList
.
items
||
!
completionList
.
items
.
length
)
{
assert
.
equal
(
1
,
2
,
`Problem with expanding m10`
);
return
;
}
const
emmetCompletionItem
=
completionList
.
items
[
0
];
assert
.
equal
(
emmetCompletionItem
.
label
,
expandedText
,
`Label of completion item doesnt match.`
);
assert
.
equal
((
<
string
>
emmetCompletionItem
.
documentation
||
''
).
replace
(
/
\|
/g
,
''
),
expandedText
,
`Docs of completion item doesnt match.`
);
assert
.
equal
(
emmetCompletionItem
.
filterText
,
abbreviation
,
`FilterText of completion item doesnt match.`
);
};
return
Promise
.
all
<
CompletionList
>
([
completionPromise1
,
completionPromise2
,
completionPromise3
,
completionPromise4
]).
then
(([
result1
,
result2
,
result3
,
result4
])
=>
{
callBack
(
result1
,
'
p10
'
,
'
padding: 10px;
'
);
callBack
(
result2
,
'
p20
'
,
'
padding: 20px;
'
);
callBack
(
result3
,
'
p30
'
,
'
padding: 30px;
'
);
callBack
(
result4
,
'
p40
'
,
'
padding: 40px;
'
);
return
Promise
.
resolve
();
});
});
});
test
(
'
Invalid locations for abbreviations in scss
'
,
()
=>
{
const
scssContentsNoExpand
=
`
m10
.boo {
margin: 10px;
.hoo {
background:
}
}
`
;
return
withRandomFileEditor
(
scssContentsNoExpand
,
'
scss
'
,
(
editor
,
doc
)
=>
{
editor
.
selections
=
[
new
Selection
(
1
,
3
,
1
,
3
),
// outside rule
new
Selection
(
5
,
15
,
5
,
15
)
// in the value part of property value
];
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
scssContentsNoExpand
);
return
Promise
.
resolve
();
});
});
});
test
(
'
Invalid locations for abbreviations in scss in completion list
'
,
()
=>
{
const
scssContentsNoExpand
=
`
m10
.boo {
margin: 10px;
.hoo {
background:
}
}
`
;
return
withRandomFileEditor
(
scssContentsNoExpand
,
'
scss
'
,
(
editor
,
doc
)
=>
{
editor
.
selection
=
new
Selection
(
1
,
3
,
1
,
3
);
// outside rule
const
cancelSrc
=
new
CancellationTokenSource
();
let
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
editor
.
selection
.
active
,
cancelSrc
.
token
);
if
(
completionPromise
)
{
assert
.
equal
(
1
,
2
,
`m10 gets expanded in invalid location (outside rule)`
);
}
editor
.
selection
=
new
Selection
(
5
,
15
,
5
,
15
);
// in the value part of property value
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
editor
.
selection
.
active
,
cancelSrc
.
token
);
if
(
completionPromise
)
{
return
completionPromise
.
then
((
completionList
:
CompletionList
)
=>
{
if
(
completionList
&&
completionList
.
items
&&
completionList
.
items
.
length
>
0
)
{
assert
.
equal
(
1
,
2
,
`m10 gets expanded in invalid location (n the value part of property value)`
);
}
return
Promise
.
resolve
();
});
}
return
Promise
.
resolve
();
});
});
});
test
(
'
Skip when typing property values when there is a nested rule in the next line (SCSS)
'
,
()
=>
{
return
withRandomFileEditor
(
scssContents
,
'
scss
'
,
(
editor
,
doc
)
=>
{
editor
.
selection
=
new
Selection
(
19
,
10
,
19
,
10
);
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
scssContents
);
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
19
,
10
),
cancelSrc
.
token
);
if
(
completionPromise
)
{
assert
.
equal
(
1
,
2
,
`Invalid completion at property value`
);
}
return
Promise
.
resolve
();
});
});
});
suite
(
'
Tests for Wrap with Abbreviations
'
,
()
=>
{
teardown
(
closeAllEditors
);
const
multiCursors
=
[
new
Selection
(
2
,
6
,
2
,
6
),
new
Selection
(
3
,
6
,
3
,
6
)];
const
multiCursorsWithSelection
=
[
new
Selection
(
2
,
2
,
2
,
28
),
new
Selection
(
3
,
2
,
3
,
33
)];
const
multiCursorsWithFullLineSelection
=
[
new
Selection
(
2
,
0
,
2
,
28
),
new
Selection
(
3
,
0
,
3
,
33
)];
test
(
'
Wrap with block element using multi cursor
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursors
,
'
div
'
,
wrapBlockElementExpected
);
});
test
(
'
Wrap with inline element using multi cursor
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursors
,
'
span
'
,
wrapInlineElementExpected
);
});
test
(
'
Wrap with snippet using multi cursor
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursors
,
'
a
'
,
wrapSnippetExpected
);
});
test
(
'
Wrap with multi line abbreviation using multi cursor
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursors
,
'
ul>li
'
,
wrapMultiLineAbbrExpected
);
});
test
(
'
Wrap with block element using multi cursor selection
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursorsWithSelection
,
'
div
'
,
wrapBlockElementExpected
);
});
test
(
'
Wrap with inline element using multi cursor selection
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursorsWithSelection
,
'
span
'
,
wrapInlineElementExpected
);
});
test
(
'
Wrap with snippet using multi cursor selection
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursorsWithSelection
,
'
a
'
,
wrapSnippetExpected
);
});
test
(
'
Wrap with multi line abbreviation using multi cursor selection
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursorsWithSelection
,
'
ul>li
'
,
wrapMultiLineAbbrExpected
);
});
test
(
'
Wrap with block element using multi cursor full line selection
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursorsWithFullLineSelection
,
'
div
'
,
wrapBlockElementExpected
);
});
test
(
'
Wrap with inline element using multi cursor full line selection
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursorsWithFullLineSelection
,
'
span
'
,
wrapInlineElementExpected
);
});
test
(
'
Wrap with snippet using multi cursor full line selection
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursorsWithFullLineSelection
,
'
a
'
,
wrapSnippetExpected
);
});
test
(
'
Wrap with multi line abbreviation using multi cursor full line selection
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursorsWithFullLineSelection
,
'
ul>li
'
,
wrapMultiLineAbbrExpected
);
});
test
(
'
Wrap individual lines with abbreviation
'
,
()
=>
{
const
contents
=
`
<ul class="nav main">
<li class="item1">img</li>
<li class="item2">hi.there</li>
</ul>
`
;
const
wrapIndividualLinesExpected
=
`
<ul class="nav main">
<ul>
<li class="hello1"><li class="item1">img</li></li>
<li class="hello2"><li class="item2">hi.there</li></li>
</ul>
</ul>
`
;
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
doc
)
=>
{
editor
.
selections
=
[
new
Selection
(
2
,
2
,
3
,
33
)];
const
promise
=
wrapIndividualLinesWithAbbreviation
({
abbreviation
:
'
ul>li.hello$*
'
});
if
(
!
promise
)
{
assert
.
equal
(
1
,
2
,
'
Wrap Individual Lines with Abbreviation returned udnefined.
'
);
return
Promise
.
resolve
();
}
return
promise
.
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
wrapIndividualLinesExpected
);
return
Promise
.
resolve
();
});
});
});
test
(
'
Wrap individual lines with abbreviation and trim
'
,
()
=>
{
const
contents
=
`
<ul class="nav main">
• lorem ipsum
• lorem ipsum
</ul>
`
;
const
wrapIndividualLinesExpected
=
`
<ul class="nav main">
<ul>
<li class="hello1">lorem ipsum</li>
<li class="hello2">lorem ipsum</li>
</ul>
</ul>
`
;
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
doc
)
=>
{
editor
.
selections
=
[
new
Selection
(
2
,
3
,
3
,
16
)];
const
promise
=
wrapIndividualLinesWithAbbreviation
({
abbreviation
:
'
ul>li.hello$*|t
'
});
if
(
!
promise
)
{
assert
.
equal
(
1
,
2
,
'
Wrap Individual Lines with Abbreviation returned udnefined.
'
);
return
Promise
.
resolve
();
}
return
promise
.
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
wrapIndividualLinesExpected
);
return
Promise
.
resolve
();
});
});
});
});
suite
(
'
Tests for jsx, xml and xsl
'
,
()
=>
{
teardown
(
closeAllEditors
);
...
...
@@ -819,18 +370,3 @@ function testHtmlCompletionProvider(selection: Selection, abbreviation: string,
});
}
function
testWrapWithAbbreviation
(
selections
:
Selection
[],
abbreviation
:
string
,
expectedContents
:
string
):
Thenable
<
any
>
{
return
withRandomFileEditor
(
htmlContentsForWrapTests
,
'
html
'
,
(
editor
,
doc
)
=>
{
editor
.
selections
=
selections
;
const
promise
=
wrapWithAbbreviation
({
abbreviation
});
if
(
!
promise
)
{
assert
.
equal
(
1
,
2
,
'
Wrap with Abbreviation returned udnefined.
'
);
return
Promise
.
resolve
();
}
return
promise
.
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
expectedContents
);
return
Promise
.
resolve
();
});
});
}
extensions/emmet/src/test/cssAbbreviationAction.test.ts
0 → 100644
浏览文件 @
4913e7f6
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
'
mocha
'
;
import
*
as
assert
from
'
assert
'
;
import
{
Selection
,
CompletionList
,
CancellationTokenSource
,
Position
}
from
'
vscode
'
;
import
{
withRandomFileEditor
,
closeAllEditors
}
from
'
./testUtils
'
;
import
{
expandEmmetAbbreviation
}
from
'
../abbreviationActions
'
;
import
{
DefaultCompletionItemProvider
}
from
'
../defaultCompletionProvider
'
;
const
completionProvider
=
new
DefaultCompletionItemProvider
();
const
cssContents
=
`
.boo {
margin: 20px 10px;
m10
background-image: url('tryme.png');
m10
}
.boo .hoo {
margin: 10px;
ind
}
`
;
const
scssContents
=
`
.boo {
margin: 10px;
p10
.hoo {
p20
}
}
@include b(alert) {
margin: 10px;
p30
@include b(alert) {
p40
}
}
.foo {
margin: 10px;
margin: a
.hoo {
color: #000;
}
}
`
;
suite
(
'
Tests for Expand Abbreviations (CSS)
'
,
()
=>
{
teardown
(
closeAllEditors
);
test
(
'
Expand abbreviation (CSS)
'
,
()
=>
{
return
withRandomFileEditor
(
cssContents
,
'
css
'
,
(
editor
,
doc
)
=>
{
editor
.
selections
=
[
new
Selection
(
3
,
1
,
3
,
4
),
new
Selection
(
5
,
1
,
5
,
4
)];
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
cssContents
.
replace
(
/m10/g
,
'
margin: 10px;
'
));
return
Promise
.
resolve
();
});
});
});
test
(
'
Skip when typing property values when there is a property in the next line (CSS)
'
,
()
=>
{
const
testContent
=
`
.foo {
margin: a
margin: 10px;
}
`
;
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
doc
)
=>
{
editor
.
selection
=
new
Selection
(
2
,
10
,
2
,
10
);
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
testContent
);
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
2
,
10
),
cancelSrc
.
token
);
if
(
completionPromise
)
{
assert
.
equal
(
1
,
2
,
`Invalid completion at property value`
);
}
return
Promise
.
resolve
();
});
});
});
test
(
'
Skip when typing property values when there is a property in the previous line (CSS)
'
,
()
=>
{
const
testContent
=
`
.foo {
margin: 10px;
margin: a
}
`
;
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
doc
)
=>
{
editor
.
selection
=
new
Selection
(
3
,
10
,
3
,
10
);
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
testContent
);
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
3
,
10
),
cancelSrc
.
token
);
if
(
completionPromise
)
{
assert
.
equal
(
1
,
2
,
`Invalid completion at property value`
);
}
return
Promise
.
resolve
();
});
});
});
test
(
'
Skip when typing property values when it is the only property in the rule (CSS)
'
,
()
=>
{
const
testContent
=
`
.foo {
margin: a
}
`
;
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
doc
)
=>
{
editor
.
selection
=
new
Selection
(
2
,
10
,
2
,
10
);
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
testContent
);
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
2
,
10
),
cancelSrc
.
token
);
if
(
completionPromise
)
{
assert
.
equal
(
1
,
2
,
`Invalid completion at property value`
);
}
return
Promise
.
resolve
();
});
});
});
test
(
'
Expand abbreviation in completion list (CSS)
'
,
()
=>
{
const
abbreviation
=
'
m10
'
;
const
expandedText
=
'
margin: 10px;
'
;
return
withRandomFileEditor
(
cssContents
,
'
css
'
,
(
editor
,
doc
)
=>
{
editor
.
selection
=
new
Selection
(
3
,
1
,
3
,
4
);
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise1
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
3
,
4
),
cancelSrc
.
token
);
const
completionPromise2
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
5
,
4
),
cancelSrc
.
token
);
if
(
!
completionPromise1
||
!
completionPromise2
)
{
assert
.
equal
(
1
,
2
,
`Problem with expanding m10`
);
return
Promise
.
resolve
();
}
const
callBack
=
(
completionList
:
CompletionList
)
=>
{
if
(
!
completionList
.
items
||
!
completionList
.
items
.
length
)
{
assert
.
equal
(
1
,
2
,
`Problem with expanding m10`
);
return
;
}
const
emmetCompletionItem
=
completionList
.
items
[
0
];
assert
.
equal
(
emmetCompletionItem
.
label
,
expandedText
,
`Label of completion item doesnt match.`
);
assert
.
equal
((
<
string
>
emmetCompletionItem
.
documentation
||
''
).
replace
(
/
\|
/g
,
''
),
expandedText
,
`Docs of completion item doesnt match.`
);
assert
.
equal
(
emmetCompletionItem
.
filterText
,
abbreviation
,
`FilterText of completion item doesnt match.`
);
};
return
Promise
.
all
<
CompletionList
>
([
completionPromise1
,
completionPromise2
]).
then
(([
result1
,
result2
])
=>
{
callBack
(
result1
);
callBack
(
result2
);
return
Promise
.
resolve
();
});
});
});
test
(
'
Expand abbreviation (SCSS)
'
,
()
=>
{
return
withRandomFileEditor
(
scssContents
,
'
scss
'
,
(
editor
,
doc
)
=>
{
editor
.
selections
=
[
new
Selection
(
3
,
4
,
3
,
4
),
new
Selection
(
5
,
5
,
5
,
5
),
new
Selection
(
11
,
4
,
11
,
4
),
new
Selection
(
14
,
5
,
14
,
5
)
];
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
scssContents
.
replace
(
/p
(\d\d)
/g
,
'
padding: $1px;
'
));
return
Promise
.
resolve
();
});
});
});
test
(
'
Expand abbreviation in completion list (SCSS)
'
,
()
=>
{
return
withRandomFileEditor
(
scssContents
,
'
scss
'
,
(
editor
,
doc
)
=>
{
editor
.
selection
=
new
Selection
(
3
,
4
,
3
,
4
);
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise1
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
3
,
4
),
cancelSrc
.
token
);
const
completionPromise2
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
5
,
5
),
cancelSrc
.
token
);
const
completionPromise3
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
11
,
4
),
cancelSrc
.
token
);
const
completionPromise4
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
14
,
5
),
cancelSrc
.
token
);
if
(
!
completionPromise1
)
{
assert
.
equal
(
1
,
2
,
`Problem with expanding padding abbreviations at line 3 col 4`
);
}
if
(
!
completionPromise2
)
{
assert
.
equal
(
1
,
2
,
`Problem with expanding padding abbreviations at line 5 col 5`
);
}
if
(
!
completionPromise3
)
{
assert
.
equal
(
1
,
2
,
`Problem with expanding padding abbreviations at line 11 col 4`
);
}
if
(
!
completionPromise4
)
{
assert
.
equal
(
1
,
2
,
`Problem with expanding padding abbreviations at line 14 col 5`
);
}
if
(
!
completionPromise1
||
!
completionPromise2
||
!
completionPromise3
||
!
completionPromise4
)
{
return
Promise
.
resolve
();
}
const
callBack
=
(
completionList
:
CompletionList
,
abbreviation
,
expandedText
)
=>
{
if
(
!
completionList
.
items
||
!
completionList
.
items
.
length
)
{
assert
.
equal
(
1
,
2
,
`Problem with expanding m10`
);
return
;
}
const
emmetCompletionItem
=
completionList
.
items
[
0
];
assert
.
equal
(
emmetCompletionItem
.
label
,
expandedText
,
`Label of completion item doesnt match.`
);
assert
.
equal
((
<
string
>
emmetCompletionItem
.
documentation
||
''
).
replace
(
/
\|
/g
,
''
),
expandedText
,
`Docs of completion item doesnt match.`
);
assert
.
equal
(
emmetCompletionItem
.
filterText
,
abbreviation
,
`FilterText of completion item doesnt match.`
);
};
return
Promise
.
all
<
CompletionList
>
([
completionPromise1
,
completionPromise2
,
completionPromise3
,
completionPromise4
]).
then
(([
result1
,
result2
,
result3
,
result4
])
=>
{
callBack
(
result1
,
'
p10
'
,
'
padding: 10px;
'
);
callBack
(
result2
,
'
p20
'
,
'
padding: 20px;
'
);
callBack
(
result3
,
'
p30
'
,
'
padding: 30px;
'
);
callBack
(
result4
,
'
p40
'
,
'
padding: 40px;
'
);
return
Promise
.
resolve
();
});
});
});
test
(
'
Invalid locations for abbreviations in scss
'
,
()
=>
{
const
scssContentsNoExpand
=
`
m10
.boo {
margin: 10px;
.hoo {
background:
}
}
`
;
return
withRandomFileEditor
(
scssContentsNoExpand
,
'
scss
'
,
(
editor
,
doc
)
=>
{
editor
.
selections
=
[
new
Selection
(
1
,
3
,
1
,
3
),
// outside rule
new
Selection
(
5
,
15
,
5
,
15
)
// in the value part of property value
];
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
scssContentsNoExpand
);
return
Promise
.
resolve
();
});
});
});
test
(
'
Invalid locations for abbreviations in scss in completion list
'
,
()
=>
{
const
scssContentsNoExpand
=
`
m10
.boo {
margin: 10px;
.hoo {
background:
}
}
`
;
return
withRandomFileEditor
(
scssContentsNoExpand
,
'
scss
'
,
(
editor
,
doc
)
=>
{
editor
.
selection
=
new
Selection
(
1
,
3
,
1
,
3
);
// outside rule
const
cancelSrc
=
new
CancellationTokenSource
();
let
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
editor
.
selection
.
active
,
cancelSrc
.
token
);
if
(
completionPromise
)
{
assert
.
equal
(
1
,
2
,
`m10 gets expanded in invalid location (outside rule)`
);
}
editor
.
selection
=
new
Selection
(
5
,
15
,
5
,
15
);
// in the value part of property value
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
editor
.
selection
.
active
,
cancelSrc
.
token
);
if
(
completionPromise
)
{
return
completionPromise
.
then
((
completionList
:
CompletionList
)
=>
{
if
(
completionList
&&
completionList
.
items
&&
completionList
.
items
.
length
>
0
)
{
assert
.
equal
(
1
,
2
,
`m10 gets expanded in invalid location (n the value part of property value)`
);
}
return
Promise
.
resolve
();
});
}
return
Promise
.
resolve
();
});
});
});
test
(
'
Skip when typing property values when there is a nested rule in the next line (SCSS)
'
,
()
=>
{
return
withRandomFileEditor
(
scssContents
,
'
scss
'
,
(
editor
,
doc
)
=>
{
editor
.
selection
=
new
Selection
(
19
,
10
,
19
,
10
);
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
scssContents
);
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
19
,
10
),
cancelSrc
.
token
);
if
(
completionPromise
)
{
assert
.
equal
(
1
,
2
,
`Invalid completion at property value`
);
}
return
Promise
.
resolve
();
});
});
});
extensions/emmet/src/test/wrapWithAbbreviation.test.ts
0 → 100644
浏览文件 @
4913e7f6
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
'
mocha
'
;
import
*
as
assert
from
'
assert
'
;
import
{
Selection
}
from
'
vscode
'
;
import
{
withRandomFileEditor
,
closeAllEditors
}
from
'
./testUtils
'
;
import
{
wrapWithAbbreviation
,
wrapIndividualLinesWithAbbreviation
}
from
'
../abbreviationActions
'
;
const
htmlContentsForWrapTests
=
`
<ul class="nav main">
<li class="item1">img</li>
<li class="item2">$hithere</li>
</ul>
`
;
const
wrapBlockElementExpected
=
`
<ul class="nav main">
<div>
<li class="item1">img</li>
</div>
<div>
<li class="item2">$hithere</li>
</div>
</ul>
`
;
const
wrapInlineElementExpected
=
`
<ul class="nav main">
<span><li class="item1">img</li></span>
<span><li class="item2">$hithere</li></span>
</ul>
`
;
const
wrapSnippetExpected
=
`
<ul class="nav main">
<a href=""><li class="item1">img</li></a>
<a href=""><li class="item2">$hithere</li></a>
</ul>
`
;
const
wrapMultiLineAbbrExpected
=
`
<ul class="nav main">
<ul>
<li>
<li class="item1">img</li>
</li>
</ul>
<ul>
<li>
<li class="item2">$hithere</li>
</li>
</ul>
</ul>
`
;
suite
(
'
Tests for Wrap with Abbreviations
'
,
()
=>
{
teardown
(
closeAllEditors
);
const
multiCursors
=
[
new
Selection
(
2
,
6
,
2
,
6
),
new
Selection
(
3
,
6
,
3
,
6
)];
const
multiCursorsWithSelection
=
[
new
Selection
(
2
,
2
,
2
,
28
),
new
Selection
(
3
,
2
,
3
,
33
)];
const
multiCursorsWithFullLineSelection
=
[
new
Selection
(
2
,
0
,
2
,
28
),
new
Selection
(
3
,
0
,
3
,
33
)];
test
(
'
Wrap with block element using multi cursor
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursors
,
'
div
'
,
wrapBlockElementExpected
);
});
test
(
'
Wrap with inline element using multi cursor
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursors
,
'
span
'
,
wrapInlineElementExpected
);
});
test
(
'
Wrap with snippet using multi cursor
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursors
,
'
a
'
,
wrapSnippetExpected
);
});
test
(
'
Wrap with multi line abbreviation using multi cursor
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursors
,
'
ul>li
'
,
wrapMultiLineAbbrExpected
);
});
test
(
'
Wrap with block element using multi cursor selection
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursorsWithSelection
,
'
div
'
,
wrapBlockElementExpected
);
});
test
(
'
Wrap with inline element using multi cursor selection
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursorsWithSelection
,
'
span
'
,
wrapInlineElementExpected
);
});
test
(
'
Wrap with snippet using multi cursor selection
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursorsWithSelection
,
'
a
'
,
wrapSnippetExpected
);
});
test
(
'
Wrap with multi line abbreviation using multi cursor selection
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursorsWithSelection
,
'
ul>li
'
,
wrapMultiLineAbbrExpected
);
});
test
(
'
Wrap with block element using multi cursor full line selection
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursorsWithFullLineSelection
,
'
div
'
,
wrapBlockElementExpected
);
});
test
(
'
Wrap with inline element using multi cursor full line selection
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursorsWithFullLineSelection
,
'
span
'
,
wrapInlineElementExpected
);
});
test
(
'
Wrap with snippet using multi cursor full line selection
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursorsWithFullLineSelection
,
'
a
'
,
wrapSnippetExpected
);
});
test
(
'
Wrap with multi line abbreviation using multi cursor full line selection
'
,
()
=>
{
return
testWrapWithAbbreviation
(
multiCursorsWithFullLineSelection
,
'
ul>li
'
,
wrapMultiLineAbbrExpected
);
});
test
(
'
Wrap individual lines with abbreviation
'
,
()
=>
{
const
contents
=
`
<ul class="nav main">
<li class="item1">img</li>
<li class="item2">hi.there</li>
</ul>
`
;
const
wrapIndividualLinesExpected
=
`
<ul class="nav main">
<ul>
<li class="hello1"><li class="item1">img</li></li>
<li class="hello2"><li class="item2">hi.there</li></li>
</ul>
</ul>
`
;
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
doc
)
=>
{
editor
.
selections
=
[
new
Selection
(
2
,
2
,
3
,
33
)];
const
promise
=
wrapIndividualLinesWithAbbreviation
({
abbreviation
:
'
ul>li.hello$*
'
});
if
(
!
promise
)
{
assert
.
equal
(
1
,
2
,
'
Wrap Individual Lines with Abbreviation returned udnefined.
'
);
return
Promise
.
resolve
();
}
return
promise
.
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
wrapIndividualLinesExpected
);
return
Promise
.
resolve
();
});
});
});
test
(
'
Wrap individual lines with abbreviation and trim
'
,
()
=>
{
const
contents
=
`
<ul class="nav main">
• lorem ipsum
• lorem ipsum
</ul>
`
;
const
wrapIndividualLinesExpected
=
`
<ul class="nav main">
<ul>
<li class="hello1">lorem ipsum</li>
<li class="hello2">lorem ipsum</li>
</ul>
</ul>
`
;
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
doc
)
=>
{
editor
.
selections
=
[
new
Selection
(
2
,
3
,
3
,
16
)];
const
promise
=
wrapIndividualLinesWithAbbreviation
({
abbreviation
:
'
ul>li.hello$*|t
'
});
if
(
!
promise
)
{
assert
.
equal
(
1
,
2
,
'
Wrap Individual Lines with Abbreviation returned udnefined.
'
);
return
Promise
.
resolve
();
}
return
promise
.
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
wrapIndividualLinesExpected
);
return
Promise
.
resolve
();
});
});
});
});
function
testWrapWithAbbreviation
(
selections
:
Selection
[],
abbreviation
:
string
,
expectedContents
:
string
):
Thenable
<
any
>
{
return
withRandomFileEditor
(
htmlContentsForWrapTests
,
'
html
'
,
(
editor
,
doc
)
=>
{
editor
.
selections
=
selections
;
const
promise
=
wrapWithAbbreviation
({
abbreviation
});
if
(
!
promise
)
{
assert
.
equal
(
1
,
2
,
'
Wrap with Abbreviation returned udnefined.
'
);
return
Promise
.
resolve
();
}
return
promise
.
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
expectedContents
);
return
Promise
.
resolve
();
});
});
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录