Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
c9bb66f3
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c9bb66f3
编写于
11月 09, 2015
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make formatting tests async.
上级
ddb81303
变更
10
展开全部
隐藏空白更改
内联
并排
Showing
10 changed file
with
1445 addition
and
1420 deletion
+1445
-1420
src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs
...ortable/ChangeSignature/AbstractChangeSignatureService.cs
+2
-2
src/VisualStudio/Core/Def/Implementation/Venus/ContainedLanguageCodeSupport.cs
.../Def/Implementation/Venus/ContainedLanguageCodeSupport.cs
+1
-1
src/Workspaces/CSharpTest/Formatting/CSharpFormattingTestBase.cs
...kspaces/CSharpTest/Formatting/CSharpFormattingTestBase.cs
+6
-5
src/Workspaces/CSharpTest/Formatting/FormattingMultipleSpanTests.cs
...aces/CSharpTest/Formatting/FormattingMultipleSpanTests.cs
+19
-18
src/Workspaces/CSharpTest/Formatting/FormattingTests.cs
src/Workspaces/CSharpTest/Formatting/FormattingTests.cs
+588
-587
src/Workspaces/CSharpTest/Formatting/FormattingTriviaTests.cs
...Workspaces/CSharpTest/Formatting/FormattingTriviaTests.cs
+135
-134
src/Workspaces/Core/Portable/Formatting/Formatter.cs
src/Workspaces/Core/Portable/Formatting/Formatter.cs
+27
-7
src/Workspaces/CoreTest/Formatting/FormattingTestBase.cs
src/Workspaces/CoreTest/Formatting/FormattingTestBase.cs
+7
-6
src/Workspaces/VisualBasicTest/Formatting/FormattingTests.vb
src/Workspaces/VisualBasicTest/Formatting/FormattingTests.vb
+641
-641
src/Workspaces/VisualBasicTest/Formatting/VisualBasicFormattingTestBase.vb
...sualBasicTest/Formatting/VisualBasicFormattingTestBase.vb
+19
-19
未找到文件。
src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs
浏览文件 @
c9bb66f3
...
...
@@ -334,13 +334,13 @@ private bool TryCreateUpdatedSolution(ChangeSignatureAnalyzedContext context, Ch
var
annotatedNodes
=
newRoot
.
GetAnnotatedNodes
<
SyntaxNode
>(
syntaxAnnotation
:
changeSignatureFormattingAnnotation
);
var
formattedRoot
=
Formatter
.
Format
(
var
formattedRoot
=
Formatter
.
Format
Async
(
newRoot
,
changeSignatureFormattingAnnotation
,
doc
.
Project
.
Solution
.
Workspace
,
options
:
null
,
rules
:
GetFormattingRules
(
doc
),
cancellationToken
:
CancellationToken
.
None
);
cancellationToken
:
CancellationToken
.
None
)
.
WaitAndGetResult
(
CancellationToken
.
None
)
;
updatedRoots
[
docId
]
=
formattedRoot
;
}
...
...
src/VisualStudio/Core/Def/Implementation/Venus/ContainedLanguageCodeSupport.cs
浏览文件 @
c9bb66f3
...
...
@@ -218,7 +218,7 @@ public static string GetEventHandlerMemberId(Document document, string className
var
formattingRules
=
additionalFormattingRule
.
Concat
(
Formatter
.
GetDefaultFormattingRules
(
targetDocument
));
var
workspace
=
targetDocument
.
Project
.
Solution
.
Workspace
;
newRoot
=
Formatter
.
Format
(
newRoot
,
Formatter
.
Annotation
,
workspace
,
workspace
.
Options
,
formattingRules
,
cancellationToken
);
newRoot
=
Formatter
.
Format
Async
(
newRoot
,
Formatter
.
Annotation
,
workspace
,
workspace
.
Options
,
formattingRules
,
cancellationToken
).
WaitAndGetResult
(
cancellationToken
);
var
newMember
=
newRoot
.
GetAnnotatedNodesAndTokens
(
annotation
).
Single
();
var
newMemberText
=
newMember
.
ToFullString
();
...
...
src/Workspaces/CSharpTest/Formatting/CSharpFormattingTestBase.cs
浏览文件 @
c9bb66f3
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using
System.Collections.Generic
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.Options
;
using
Microsoft.CodeAnalysis.Text
;
using
Microsoft.CodeAnalysis.UnitTests.Formatting
;
...
...
@@ -17,7 +18,7 @@ protected override SyntaxNode ParseCompilation(string text, ParseOptions parseOp
return
SyntaxFactory
.
ParseCompilationUnit
(
text
,
options
:
(
CSharpParseOptions
)
parseOptions
);
}
protected
void
AssertFormat
(
protected
Task
AssertFormatAsync
(
string
expected
,
string
code
,
bool
debugMode
=
false
,
...
...
@@ -25,10 +26,10 @@ protected override SyntaxNode ParseCompilation(string text, ParseOptions parseOp
bool
testWithTransformation
=
true
,
ParseOptions
parseOptions
=
null
)
{
AssertFormat
(
expected
,
code
,
SpecializedCollections
.
SingletonEnumerable
(
new
TextSpan
(
0
,
code
.
Length
)),
debugMode
,
changedOptionSet
,
testWithTransformation
,
parseOptions
);
return
AssertFormatAsync
(
expected
,
code
,
SpecializedCollections
.
SingletonEnumerable
(
new
TextSpan
(
0
,
code
.
Length
)),
debugMode
,
changedOptionSet
,
testWithTransformation
,
parseOptions
);
}
protected
void
AssertFormat
(
protected
Task
AssertFormatAsync
(
string
expected
,
string
code
,
IEnumerable
<
TextSpan
>
spans
,
...
...
@@ -37,7 +38,7 @@ protected override SyntaxNode ParseCompilation(string text, ParseOptions parseOp
bool
testWithTransformation
=
true
,
ParseOptions
parseOptions
=
null
)
{
AssertFormat
(
expected
,
code
,
spans
,
LanguageNames
.
CSharp
,
debugMode
,
changedOptionSet
,
testWithTransformation
,
parseOptions
);
return
AssertFormatAsync
(
expected
,
code
,
spans
,
LanguageNames
.
CSharp
,
debugMode
,
changedOptionSet
,
testWithTransformation
,
parseOptions
);
}
}
}
}
\ No newline at end of file
src/Workspaces/CSharpTest/Formatting/FormattingMultipleSpanTests.cs
浏览文件 @
c9bb66f3
...
...
@@ -4,6 +4,7 @@
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.CSharp
;
using
Microsoft.CodeAnalysis.CSharp.Formatting
;
using
Microsoft.CodeAnalysis.Formatting
;
...
...
@@ -18,22 +19,22 @@ namespace Microsoft.CodeAnalysis.CSharp.UnitTests.Formatting
public
class
FormattingEngineMultiSpanTests
:
CSharpFormattingTestBase
{
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Formatting
)]
public
void
EndOfLine
()
public
async
Task
EndOfLine
()
{
var
content
=
@"namespace A{/*1*/}/*2*/"
;
var
expected
=
@"namespace A{}"
;
AssertFormat
(
content
,
expected
);
await
AssertFormatAsync
(
content
,
expected
).
ConfigureAwait
(
true
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Formatting
)]
public
void
Simple1
()
public
async
Task
Simple1
()
{
AssertFormat
(
"namespace A/*1*/{}/*2*/ class A {}"
,
"namespace A{ } class A {}"
);
await
AssertFormatAsync
(
"namespace A/*1*/{}/*2*/ class A {}"
,
"namespace A{ } class A {}"
).
ConfigureAwait
(
true
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Formatting
)]
public
void
DontFormatTriviaOutsideOfSpan_IncludingTrailingTriviaOnNewLine
()
public
async
Task
DontFormatTriviaOutsideOfSpan_IncludingTrailingTriviaOnNewLine
()
{
var
content
=
@"namespace A
/*1*/{
...
...
@@ -47,11 +48,11 @@ class A /*1*/{}/*2*/";
class A { }"
;
AssertFormat
(
content
,
expected
);
await
AssertFormatAsync
(
content
,
expected
).
ConfigureAwait
(
true
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Formatting
)]
public
void
FormatIncludingTrivia
()
public
async
Task
FormatIncludingTrivia
()
{
var
content
=
@"namespace A
/*1*/{
...
...
@@ -65,11 +66,11 @@ class A /*1*/{}/*2*/";
class A { }"
;
AssertFormat
(
content
,
expected
);
await
AssertFormatAsync
(
content
,
expected
).
ConfigureAwait
(
true
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Formatting
)]
public
void
MergeSpanAndFormat
()
public
async
Task
MergeSpanAndFormat
()
{
var
content
=
@"namespace A
/*1*/{
...
...
@@ -83,11 +84,11 @@ class A{}/*2*/";
class A { }"
;
AssertFormat
(
content
,
expected
);
await
AssertFormatAsync
(
content
,
expected
).
ConfigureAwait
(
true
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Formatting
)]
public
void
OverlappedSpan
()
public
async
Task
OverlappedSpan
()
{
var
content
=
@"namespace A
/*1*/{
...
...
@@ -101,13 +102,13 @@ class A{}/*2*/";
class A { }"
;
AssertFormat
(
content
,
expected
);
await
AssertFormatAsync
(
content
,
expected
).
ConfigureAwait
(
true
);
}
[
Fact
]
[
WorkItem
(
554160
,
"DevDiv"
)]
[
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Formatting
)]
public
void
FormatSpanNullReference01
()
public
async
Task
FormatSpanNullReference01
()
{
var
code
=
@"/*1*/class C
{
...
...
@@ -126,13 +127,13 @@ void F()
}"
;
var
changingOptions
=
new
Dictionary
<
OptionKey
,
object
>();
changingOptions
.
Add
(
CSharpFormattingOptions
.
IndentBlock
,
false
);
AssertFormat
(
code
,
expected
,
changedOptionSet
:
changingOptions
);
await
AssertFormatAsync
(
code
,
expected
,
changedOptionSet
:
changingOptions
).
ConfigureAwait
(
true
);
}
[
Fact
]
[
WorkItem
(
554160
,
"DevDiv"
)]
[
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Formatting
)]
public
void
FormatSpanNullReference02
()
public
async
Task
FormatSpanNullReference02
()
{
var
code
=
@"class C/*1*/
{
...
...
@@ -151,7 +152,7 @@ void F()
}"
;
var
changingOptions
=
new
Dictionary
<
OptionKey
,
object
>();
changingOptions
.
Add
(
CSharpFormattingOptions
.
WrappingPreserveSingleLine
,
false
);
AssertFormat
(
code
,
expected
,
changedOptionSet
:
changingOptions
);
await
AssertFormatAsync
(
code
,
expected
,
changedOptionSet
:
changingOptions
).
ConfigureAwait
(
true
);
}
[
WorkItem
(
539231
,
"DevDiv"
)]
...
...
@@ -168,11 +169,11 @@ public void EmptySpan()
}
}
private
void
AssertFormat
(
string
content
,
string
expected
,
Dictionary
<
OptionKey
,
object
>
changedOptionSet
=
null
)
private
Task
AssertFormatAsync
(
string
content
,
string
expected
,
Dictionary
<
OptionKey
,
object
>
changedOptionSet
=
null
)
{
var
tuple
=
PreprocessMarkers
(
content
);
AssertFormat
(
expected
,
tuple
.
Item1
,
tuple
.
Item2
,
changedOptionSet
:
changedOptionSet
);
return
AssertFormatAsync
(
expected
,
tuple
.
Item1
,
tuple
.
Item2
,
changedOptionSet
:
changedOptionSet
);
}
private
Tuple
<
string
,
List
<
TextSpan
>>
PreprocessMarkers
(
string
codeWithMarker
)
...
...
src/Workspaces/CSharpTest/Formatting/FormattingTests.cs
浏览文件 @
c9bb66f3
此差异已折叠。
点击以展开。
src/Workspaces/CSharpTest/Formatting/FormattingTriviaTests.cs
浏览文件 @
c9bb66f3
此差异已折叠。
点击以展开。
src/Workspaces/Core/Portable/Formatting/Formatter.cs
浏览文件 @
c9bb66f3
...
...
@@ -162,7 +162,7 @@ internal static async Task<Document> FormatAsync(Document document, SyntaxAnnota
}
var
root
=
await
document
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
return
document
.
WithSyntaxRoot
(
Format
(
root
,
annotation
,
document
.
Project
.
Solution
.
Workspace
,
options
,
rules
,
cancellationToken
));
return
document
.
WithSyntaxRoot
(
await
FormatAsync
(
root
,
annotation
,
document
.
Project
.
Solution
.
Workspace
,
options
,
rules
,
cancellationToken
).
ConfigureAwait
(
false
));
}
/// <summary>
...
...
@@ -176,10 +176,15 @@ internal static async Task<Document> FormatAsync(Document document, SyntaxAnnota
/// <returns>The formatted tree's root node.</returns>
public
static
SyntaxNode
Format
(
SyntaxNode
node
,
SyntaxAnnotation
annotation
,
Workspace
workspace
,
OptionSet
options
=
null
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
return
Format
(
node
,
annotation
,
workspace
,
options
,
rules
:
null
,
cancellationToken
:
cancellationToken
);
return
Format
Async
(
node
,
annotation
,
workspace
,
options
,
cancellationToken
).
WaitAndGetResult
(
cancellationToken
);
}
internal
static
SyntaxNode
Format
(
SyntaxNode
node
,
SyntaxAnnotation
annotation
,
Workspace
workspace
,
OptionSet
options
,
IEnumerable
<
IFormattingRule
>
rules
,
CancellationToken
cancellationToken
)
internal
static
Task
<
SyntaxNode
>
FormatAsync
(
SyntaxNode
node
,
SyntaxAnnotation
annotation
,
Workspace
workspace
,
OptionSet
options
=
null
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
return
FormatAsync
(
node
,
annotation
,
workspace
,
options
,
rules
:
null
,
cancellationToken
:
cancellationToken
);
}
internal
static
Task
<
SyntaxNode
>
FormatAsync
(
SyntaxNode
node
,
SyntaxAnnotation
annotation
,
Workspace
workspace
,
OptionSet
options
,
IEnumerable
<
IFormattingRule
>
rules
,
CancellationToken
cancellationToken
)
{
if
(
workspace
==
null
)
{
...
...
@@ -200,7 +205,7 @@ internal static SyntaxNode Format(SyntaxNode node, SyntaxAnnotation annotation,
?
GetElasticSpans
(
node
)
:
GetAnnotatedSpans
(
node
,
annotation
);
return
Format
(
node
,
spans
,
workspace
,
options
,
rules
,
cancellationToken
);
return
Format
Async
(
node
,
spans
,
workspace
,
options
,
rules
,
cancellationToken
);
}
/// <summary>
...
...
@@ -294,7 +299,12 @@ internal static async Task<SyntaxNode> FormatAsync(SyntaxNode node, IEnumerable<
/// <returns>The changes necessary to format the tree.</returns>
public
static
IList
<
TextChange
>
GetFormattedTextChanges
(
SyntaxNode
node
,
Workspace
workspace
,
OptionSet
options
=
null
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
return
GetFormattedTextChanges
(
node
,
SpecializedCollections
.
SingletonEnumerable
(
node
.
FullSpan
),
workspace
,
options
,
rules
:
null
,
cancellationToken
:
cancellationToken
);
return
GetFormattedTextChangesAsync
(
node
,
workspace
,
options
,
cancellationToken
).
WaitAndGetResult
(
cancellationToken
);
}
internal
static
Task
<
IList
<
TextChange
>>
GetFormattedTextChangesAsync
(
SyntaxNode
node
,
Workspace
workspace
,
OptionSet
options
=
null
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
return
GetFormattedTextChangesAsync
(
node
,
SpecializedCollections
.
SingletonEnumerable
(
node
.
FullSpan
),
workspace
,
options
,
rules
:
null
,
cancellationToken
:
cancellationToken
);
}
/// <summary>
...
...
@@ -308,7 +318,12 @@ public static IList<TextChange> GetFormattedTextChanges(SyntaxNode node, Workspa
/// <returns>The changes necessary to format the tree.</returns>
public
static
IList
<
TextChange
>
GetFormattedTextChanges
(
SyntaxNode
node
,
TextSpan
span
,
Workspace
workspace
,
OptionSet
options
=
null
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
return
GetFormattedTextChanges
(
node
,
SpecializedCollections
.
SingletonEnumerable
(
span
),
workspace
,
options
,
rules
:
null
,
cancellationToken
:
cancellationToken
);
return
GetFormattedTextChangesAsync
(
node
,
span
,
workspace
,
options
,
cancellationToken
).
WaitAndGetResult
(
cancellationToken
);
}
internal
static
Task
<
IList
<
TextChange
>>
GetFormattedTextChangesAsync
(
SyntaxNode
node
,
TextSpan
span
,
Workspace
workspace
,
OptionSet
options
=
null
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
return
GetFormattedTextChangesAsync
(
node
,
SpecializedCollections
.
SingletonEnumerable
(
span
),
workspace
,
options
,
rules
:
null
,
cancellationToken
:
cancellationToken
);
}
/// <summary>
...
...
@@ -322,7 +337,12 @@ public static IList<TextChange> GetFormattedTextChanges(SyntaxNode node, TextSpa
/// <returns>The changes necessary to format the tree.</returns>
public
static
IList
<
TextChange
>
GetFormattedTextChanges
(
SyntaxNode
node
,
IEnumerable
<
TextSpan
>
spans
,
Workspace
workspace
,
OptionSet
options
=
null
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
return
GetFormattedTextChanges
(
node
,
spans
,
workspace
,
options
,
rules
:
null
,
cancellationToken
:
cancellationToken
);
return
GetFormattedTextChangesAsync
(
node
,
spans
,
workspace
,
options
,
cancellationToken
).
WaitAndGetResult
(
cancellationToken
);
}
internal
static
Task
<
IList
<
TextChange
>>
GetFormattedTextChangesAsync
(
SyntaxNode
node
,
IEnumerable
<
TextSpan
>
spans
,
Workspace
workspace
,
OptionSet
options
=
null
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
return
GetFormattedTextChangesAsync
(
node
,
spans
,
workspace
,
options
,
rules
:
null
,
cancellationToken
:
cancellationToken
);
}
internal
static
IList
<
TextChange
>
GetFormattedTextChanges
(
SyntaxNode
node
,
IEnumerable
<
TextSpan
>
spans
,
Workspace
workspace
,
OptionSet
options
,
IEnumerable
<
IFormattingRule
>
rules
,
CancellationToken
cancellationToken
)
...
...
src/Workspaces/CoreTest/Formatting/FormattingTestBase.cs
浏览文件 @
c9bb66f3
...
...
@@ -2,6 +2,7 @@
using
System.Collections.Generic
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.Formatting
;
using
Microsoft.CodeAnalysis.Options
;
using
Microsoft.CodeAnalysis.Text
;
...
...
@@ -12,7 +13,7 @@ namespace Microsoft.CodeAnalysis.UnitTests.Formatting
{
public
abstract
class
FormattingTestBase
{
protected
void
AssertFormat
(
protected
Task
AssertFormatAsync
(
string
expected
,
string
code
,
string
language
,
...
...
@@ -20,10 +21,10 @@ public abstract class FormattingTestBase
Dictionary
<
OptionKey
,
object
>
changedOptionSet
=
null
,
bool
testWithTransformation
=
true
)
{
AssertFormat
(
expected
,
code
,
SpecializedCollections
.
SingletonEnumerable
(
new
TextSpan
(
0
,
code
.
Length
)),
language
,
debugMode
,
changedOptionSet
,
testWithTransformation
);
return
AssertFormatAsync
(
expected
,
code
,
SpecializedCollections
.
SingletonEnumerable
(
new
TextSpan
(
0
,
code
.
Length
)),
language
,
debugMode
,
changedOptionSet
,
testWithTransformation
);
}
protected
void
AssertFormat
(
protected
async
Task
AssertFormatAsync
(
string
expected
,
string
code
,
IEnumerable
<
TextSpan
>
spans
,
...
...
@@ -55,7 +56,7 @@ public abstract class FormattingTestBase
}
var
root
=
syntaxTree
.
GetRoot
();
AssertFormat
(
workspace
,
expected
,
root
,
spans
,
options
,
document
.
GetTextAsync
().
Result
);
await
AssertFormatAsync
(
workspace
,
expected
,
root
,
spans
,
options
,
await
document
.
GetTextAsync
().
ConfigureAwait
(
true
)).
ConfigureAwait
(
true
);
// format with node and transform
AssertFormatWithTransformation
(
workspace
,
expected
,
root
,
spans
,
options
,
treeCompare
,
parseOptions
);
...
...
@@ -81,9 +82,9 @@ public abstract class FormattingTestBase
}
}
protected
static
void
AssertFormat
(
Workspace
workspace
,
string
expected
,
SyntaxNode
root
,
IEnumerable
<
TextSpan
>
spans
,
OptionSet
optionSet
,
SourceText
sourceText
)
protected
static
async
Task
AssertFormatAsync
(
Workspace
workspace
,
string
expected
,
SyntaxNode
root
,
IEnumerable
<
TextSpan
>
spans
,
OptionSet
optionSet
,
SourceText
sourceText
)
{
var
result
=
Formatter
.
GetFormattedTextChanges
(
root
,
spans
,
workspace
,
optionSet
);
var
result
=
await
Formatter
.
GetFormattedTextChangesAsync
(
root
,
spans
,
workspace
,
optionSet
).
ConfigureAwait
(
true
);
AssertResult
(
expected
,
sourceText
,
result
);
}
...
...
src/Workspaces/VisualBasicTest/Formatting/FormattingTests.vb
浏览文件 @
c9bb66f3
此差异已折叠。
点击以展开。
src/Workspaces/VisualBasicTest/Formatting/VisualBasicFormattingTestBase.vb
浏览文件 @
c9bb66f3
...
...
@@ -30,14 +30,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Formatting
Return
StringFromLines
(
adjustedLines
.
ToArray
())
End
Function
Protected
Sub
AssertFormatLf2CrLf
(
code
As
String
,
expected
As
String
,
Optional
optionSet
As
Dictionary
(
Of
OptionKey
,
Object
)
=
Nothing
)
Protected
Function
AssertFormatLf2CrLfAsync
(
code
As
String
,
expected
As
String
,
Optional
optionSet
As
Dictionary
(
Of
OptionKey
,
Object
)
=
Nothing
)
As
Task
code
=
code
.
Replace
(
vbLf
,
vbCrLf
)
expected
=
expected
.
Replace
(
vbLf
,
vbCrLf
)
AssertFormat
(
code
,
expected
,
changedOptionSet
:
=
optionSet
)
End
Sub
Return
AssertFormatAsync
(
code
,
expected
,
changedOptionSet
:
=
optionSet
)
End
Function
Protected
Sub
AssertFormatUsingAllEntryPoints
(
code
As
String
,
expected
As
String
)
Protected
Async
Function
AssertFormatUsingAllEntryPointsAsync
(
code
As
String
,
expected
As
String
)
As
Task
Using
workspace
=
New
AdhocWorkspace
()
Dim
project
=
workspace
.
CurrentSolution
.
AddProject
(
"Project"
,
"Project.dll"
,
LanguageNames
.
VisualBasic
)
...
...
@@ -49,50 +49,50 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Formatting
Dim
spans
=
New
List
(
Of
TextSpan
)()
spans
.
Add
(
syntaxTree
.
GetRoot
().
FullSpan
)
Dim
changes
=
Formatter
.
GetFormattedTextChanges
(
syntaxTree
.
GetRoot
(
CancellationToken
.
None
),
workspace
,
cancellationToken
:
=
CancellationToken
.
Non
e
)
Dim
changes
=
Await
Formatter
.
GetFormattedTextChangesAsync
(
syntaxTree
.
GetRoot
(
CancellationToken
.
None
),
workspace
,
cancellationToken
:
=
CancellationToken
.
None
).
ConfigureAwait
(
Tru
e
)
AssertResult
(
expected
,
document
.
GetTextAsync
().
Result
,
changes
)
changes
=
Formatter
.
GetFormattedTextChanges
(
syntaxTree
.
GetRoot
(),
syntaxTree
.
GetRoot
(
CancellationToken
.
None
).
FullSpan
,
workspace
,
cancellationToken
:
=
CancellationToken
.
Non
e
)
changes
=
Await
Formatter
.
GetFormattedTextChangesAsync
(
syntaxTree
.
GetRoot
(),
syntaxTree
.
GetRoot
(
CancellationToken
.
None
).
FullSpan
,
workspace
,
cancellationToken
:
=
CancellationToken
.
None
).
ConfigureAwait
(
Tru
e
)
AssertResult
(
expected
,
document
.
GetTextAsync
().
Result
,
changes
)
spans
=
New
List
(
Of
TextSpan
)()
spans
.
Add
(
syntaxTree
.
GetRoot
().
FullSpan
)
changes
=
Formatter
.
GetFormattedTextChanges
(
syntaxTree
.
GetRoot
(
CancellationToken
.
None
),
spans
,
workspace
,
cancellationToken
:
=
CancellationToken
.
Non
e
)
changes
=
Await
Formatter
.
GetFormattedTextChangesAsync
(
syntaxTree
.
GetRoot
(
CancellationToken
.
None
),
spans
,
workspace
,
cancellationToken
:
=
CancellationToken
.
None
).
ConfigureAwait
(
Tru
e
)
AssertResult
(
expected
,
document
.
GetTextAsync
().
Result
,
changes
)
' format with node and transform
AssertFormatWithTransformation
(
workspace
,
expected
,
syntaxTree
.
GetRoot
(),
spans
,
Nothing
,
False
)
End
Using
End
Sub
End
Function
Protected
Sub
AssertFormatSpan
(
markupCode
As
String
,
expected
As
String
)
Protected
Function
AssertFormatSpanAsync
(
markupCode
As
String
,
expected
As
String
)
As
Task
Dim
code
As
String
=
Nothing
Dim
cursorPosition
As
Integer
?
=
Nothing
Dim
spans
As
IList
(
Of
TextSpan
)
=
Nothing
MarkupTestFile
.
GetSpans
(
markupCode
,
code
,
spans
)
AssertFormat
(
expected
,
code
,
spans
)
End
Sub
Return
AssertFormatAsync
(
expected
,
code
,
spans
)
End
Function
Protected
Overloads
Sub
AssertFormat
(
Protected
Overloads
Function
AssertFormatAsync
(
code
As
String
,
expected
As
String
,
Optional
debugMode
As
Boolean
=
False
,
Optional
changedOptionSet
As
Dictionary
(
Of
OptionKey
,
Object
)
=
Nothing
,
Optional
testWithTransformation
As
Boolean
=
False
,
Optional
experimental
As
Boolean
=
False
)
AssertFormat
(
expected
,
code
,
SpecializedCollections
.
SingletonEnumerable
(
New
TextSpan
(
0
,
code
.
Length
)),
debugMode
,
changedOptionSet
,
testWithTransformation
,
experimental
:
=
experimental
)
End
Sub
Optional
experimental
As
Boolean
=
False
)
As
Task
Return
AssertFormatAsync
(
expected
,
code
,
SpecializedCollections
.
SingletonEnumerable
(
New
TextSpan
(
0
,
code
.
Length
)),
debugMode
,
changedOptionSet
,
testWithTransformation
,
experimental
:
=
experimental
)
End
Function
Protected
Overloads
Sub
AssertFormat
(
Protected
Overloads
Function
AssertFormatAsync
(
expected
As
String
,
code
As
String
,
spans
As
IEnumerable
(
Of
TextSpan
),
Optional
debugMode
As
Boolean
=
False
,
Optional
changedOptionSet
As
Dictionary
(
Of
OptionKey
,
Object
)
=
Nothing
,
Optional
testWithTransformation
As
Boolean
=
False
,
Optional
experimental
As
Boolean
=
False
)
Optional
experimental
As
Boolean
=
False
)
As
Task
Dim
parseOptions
=
New
VisualBasicParseOptions
()
If
(
experimental
)
Then
...
...
@@ -100,8 +100,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Formatting
' parseOptions = parseOptions.WithExperimentalFeatures
End
If
AssertFormat
(
expected
,
code
,
spans
,
LanguageNames
.
VisualBasic
,
debugMode
,
changedOptionSet
,
testWithTransformation
,
parseOptions
)
End
Sub
Return
AssertFormatAsync
(
expected
,
code
,
spans
,
LanguageNames
.
VisualBasic
,
debugMode
,
changedOptionSet
,
testWithTransformation
,
parseOptions
)
End
Function
Private
Function
StringFromLines
(
ParamArray
lines
As
String
())
As
String
Return
String
.
Join
(
Environment
.
NewLine
,
lines
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录