Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
c33cc40e
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,发现更多精彩内容 >>
提交
c33cc40e
编写于
10月 10, 2016
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix up codegen tests.
上级
612dd308
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
41 addition
and
12 deletion
+41
-12
src/EditorFeatures/Test/CodeGeneration/CodeGenerationTests.CSharp.cs
...eatures/Test/CodeGeneration/CodeGenerationTests.CSharp.cs
+21
-2
src/EditorFeatures/Test/CodeGeneration/CodeGenerationTests.cs
...EditorFeatures/Test/CodeGeneration/CodeGenerationTests.cs
+20
-10
未找到文件。
src/EditorFeatures/Test/CodeGeneration/CodeGenerationTests.CSharp.cs
浏览文件 @
c33cc40e
...
...
@@ -8,14 +8,17 @@
using
Microsoft.CodeAnalysis
;
using
Microsoft.CodeAnalysis.CodeGeneration
;
using
Microsoft.CodeAnalysis.CSharp
;
using
Microsoft.CodeAnalysis.CSharp.CodeStyle
;
using
Microsoft.CodeAnalysis.CSharp.Symbols
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.Editing
;
using
Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
;
using
Microsoft.CodeAnalysis.Options
;
using
Microsoft.CodeAnalysis.Text
;
using
Roslyn.Test.Utilities
;
using
Roslyn.Utilities
;
using
Xunit
;
using
Microsoft.CodeAnalysis.CodeStyle
;
using
CS
=
Microsoft
.
CodeAnalysis
.
CSharp
;
using
VB
=
Microsoft
.
CodeAnalysis
.
VisualBasic
;
...
...
@@ -639,10 +642,10 @@ public async Task AddUnsafeAutoProperty()
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeGeneration
)]
public
async
Task
AddIndexer
()
public
async
Task
AddIndexer
1
()
{
var
input
=
"class [|C|] { }"
;
var
expected
=
"class C { public string this[int i]
{ get { $$ } }
}"
;
var
expected
=
"class C { public string this[int i]
=> String.Empty;
}"
;
await
TestAddPropertyAsync
(
input
,
expected
,
type
:
typeof
(
string
),
parameters
:
Parameters
(
Parameter
(
typeof
(
int
),
"i"
)),
...
...
@@ -650,6 +653,22 @@ public async Task AddIndexer()
isIndexer
:
true
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeGeneration
)]
public
async
Task
AddIndexer2
()
{
var
input
=
"class [|C|] { }"
;
var
expected
=
"class C { public string this[int i] { get { $$ } } }"
;
await
TestAddPropertyAsync
(
input
,
expected
,
type
:
typeof
(
string
),
parameters
:
Parameters
(
Parameter
(
typeof
(
int
),
"i"
)),
getStatements
:
"return String.Empty;"
,
isIndexer
:
true
,
options
:
new
Dictionary
<
OptionKey
,
object
>
{
{
CSharpCodeStyleOptions
.
PreferExpressionBodiedAccessors
,
CodeStyleOptions
.
falseWithNoneEnforcement
},
{
CSharpCodeStyleOptions
.
PreferExpressionBodiedIndexers
,
CodeStyleOptions
.
falseWithNoneEnforcement
},
});
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeGeneration
)]
public
async
Task
AddParameterfulProperty
()
{
...
...
src/EditorFeatures/Test/CodeGeneration/CodeGenerationTests.cs
浏览文件 @
c33cc40e
...
...
@@ -13,6 +13,7 @@
using
Microsoft.CodeAnalysis.Editing
;
using
Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
;
using
Microsoft.CodeAnalysis.Formatting
;
using
Microsoft.CodeAnalysis.Options
;
using
Microsoft.CodeAnalysis.Simplification
;
using
Microsoft.CodeAnalysis.Text
;
using
Microsoft.CodeAnalysis.VisualBasic
;
...
...
@@ -373,7 +374,8 @@ public partial class CodeGenerationTests
IList
<
Func
<
SemanticModel
,
IParameterSymbol
>>
parameters
=
null
,
bool
isIndexer
=
false
,
CodeGenerationOptions
codeGenerationOptions
=
default
(
CodeGenerationOptions
),
bool
compareTokens
=
true
)
bool
compareTokens
=
true
,
IDictionary
<
OptionKey
,
object
>
options
=
null
)
{
// This assumes that tests will not use place holders for get/set statements at the same time
if
(
getStatements
!=
null
)
...
...
@@ -388,6 +390,14 @@ public partial class CodeGenerationTests
using
(
var
context
=
await
TestContext
.
CreateAsync
(
initial
,
expected
,
compareTokens
))
{
if
(
options
!=
null
)
{
foreach
(
var
kvp
in
options
)
{
context
.
Workspace
.
Options
=
context
.
Workspace
.
Options
.
WithChangedOption
(
kvp
.
Key
,
kvp
.
Value
);
}
}
var
typeSymbol
=
GetTypeSymbol
(
type
)(
context
.
SemanticModel
);
var
getParameterSymbols
=
GetParameterSymbols
(
parameters
,
context
);
var
setParameterSymbols
=
getParameterSymbols
==
null
?
null
:
new
List
<
IParameterSymbol
>(
getParameterSymbols
)
{
Parameter
(
type
,
"value"
)(
context
.
SemanticModel
)
};
...
...
@@ -788,7 +798,7 @@ internal class TestContext : IDisposable
public
Document
Result
;
p
rivate
readonly
TestWorkspace
_w
orkspace
;
p
ublic
readonly
TestWorkspace
W
orkspace
;
private
readonly
string
_language
;
private
readonly
bool
_compareTokens
;
private
readonly
bool
_ignoreResult
;
...
...
@@ -807,8 +817,8 @@ internal class TestContext : IDisposable
this
.
IsVisualBasic
=
_language
==
LanguageNames
.
VisualBasic
;
_compareTokens
=
compareTokens
;
_ignoreResult
=
ignoreResult
;
_w
orkspace
=
workspace
;
this
.
Document
=
_w
orkspace
.
CurrentSolution
.
Projects
.
Single
().
Documents
.
Single
();
W
orkspace
=
workspace
;
this
.
Document
=
W
orkspace
.
CurrentSolution
.
Projects
.
Single
().
Documents
.
Single
();
this
.
SemanticModel
=
semanticModel
;
this
.
SyntaxTree
=
SemanticModel
.
SyntaxTree
;
this
.
Service
=
Document
.
Project
.
LanguageServices
.
GetService
<
ICodeGenerationService
>();
...
...
@@ -824,23 +834,23 @@ public static async Task<TestContext> CreateAsync(string initial, string expecte
return
new
TestContext
(
initial
,
expected
,
compareTokens
,
ignoreResult
,
language
,
workspace
,
semanticModel
);
}
public
Solution
Solution
{
get
{
return
_w
orkspace
.
CurrentSolution
;
}
}
public
Solution
Solution
{
get
{
return
W
orkspace
.
CurrentSolution
;
}
}
public
SyntaxNode
GetDestinationNode
()
{
var
destSpan
=
_w
orkspace
.
Documents
.
Single
().
SelectedSpans
.
Single
();
var
destSpan
=
W
orkspace
.
Documents
.
Single
().
SelectedSpans
.
Single
();
return
SemanticModel
.
SyntaxTree
.
GetRoot
().
FindNode
(
destSpan
,
getInnermostNodeForTie
:
true
);
}
public
INamespaceOrTypeSymbol
GetDestination
()
{
var
destSpan
=
_w
orkspace
.
Documents
.
Single
().
SelectedSpans
.
Single
();
var
destSpan
=
W
orkspace
.
Documents
.
Single
().
SelectedSpans
.
Single
();
return
GetSelectedSymbol
<
INamespaceOrTypeSymbol
>(
destSpan
,
this
.
SemanticModel
);
}
public
IEnumerable
<
ISymbol
>
GetAnnotatedDeclaredSymbols
(
string
key
,
SemanticModel
semanticModel
)
{
var
annotatedSpans
=
_w
orkspace
.
Documents
.
Single
().
AnnotatedSpans
[
key
];
var
annotatedSpans
=
W
orkspace
.
Documents
.
Single
().
AnnotatedSpans
[
key
];
foreach
(
var
span
in
annotatedSpans
)
{
yield
return
GetSelectedSymbol
<
ISymbol
>(
span
,
semanticModel
);
...
...
@@ -861,7 +871,7 @@ public T GetSelectedSymbol<T>(TextSpan selection, SemanticModel semanticModel)
public
T
GetSelectedSyntax
<
T
>(
bool
fullSpanCoverage
=
false
)
where
T
:
SyntaxNode
{
var
destSpan
=
_w
orkspace
.
Documents
.
Single
().
SelectedSpans
.
Single
();
var
destSpan
=
W
orkspace
.
Documents
.
Single
().
SelectedSpans
.
Single
();
var
token
=
SemanticModel
.
SyntaxTree
.
GetRoot
().
FindToken
(
destSpan
.
Start
);
return
token
.
Parent
.
AncestorsAndSelf
().
OfType
<
T
>().
FirstOrDefault
(
t
=>
!
fullSpanCoverage
||
t
.
Span
.
End
>=
destSpan
.
End
);
}
...
...
@@ -913,7 +923,7 @@ public void Dispose()
}
finally
{
_w
orkspace
.
Dispose
();
W
orkspace
.
Dispose
();
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录