Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
1a5cabbf
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,发现更多精彩内容 >>
提交
1a5cabbf
编写于
2月 14, 2017
作者:
N
Neal Gafter
提交者:
GitHub
2月 14, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add further tests for pattern-matching in global code (#17092)
Fixes #14146
上级
4f8c86bc
变更
3
展开全部
隐藏空白更改
内联
并排
Showing
3 changed file
with
1937 addition
and
0 deletion
+1937
-0
src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTestBase.cs
...CSharp/Test/Semantic/Semantics/PatternMatchingTestBase.cs
+15
-0
src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs
...rs/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs
+66
-0
src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_Global.cs
...rp/Test/Semantic/Semantics/PatternMatchingTests_Global.cs
+1856
-0
未找到文件。
src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTestBase.cs
浏览文件 @
1a5cabbf
...
...
@@ -121,6 +121,16 @@ protected static void VerifyModelForDeclarationPatternDuplicateInSameScope(Seman
}
}
protected
static
void
VerifyNotAPatternField
(
SemanticModel
model
,
IdentifierNameSyntax
reference
)
{
var
symbol
=
model
.
GetSymbolInfo
(
reference
).
Symbol
;
Assert
.
NotEqual
(
SymbolKind
.
Field
,
symbol
.
Kind
);
Assert
.
Same
(
symbol
,
model
.
LookupSymbols
(
reference
.
SpanStart
,
name
:
reference
.
Identifier
.
ValueText
).
Single
());
Assert
.
True
(
model
.
LookupNames
(
reference
.
SpanStart
).
Contains
(
reference
.
Identifier
.
ValueText
));
}
protected
static
void
VerifyNotAPatternLocal
(
SemanticModel
model
,
IdentifierNameSyntax
reference
)
{
var
symbol
=
model
.
GetSymbolInfo
(
reference
).
Symbol
;
...
...
@@ -301,6 +311,11 @@ protected static void VerifyModelNotSupported(SemanticModel model, params Identi
}
}
protected
static
void
AssertNoGlobalStatements
(
SyntaxTree
tree
)
{
Assert
.
Empty
(
tree
.
GetRoot
().
DescendantNodes
().
OfType
<
GlobalStatementSyntax
>());
}
#
endregion
helpers
}
}
src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs
浏览文件 @
1a5cabbf
...
...
@@ -795,6 +795,13 @@ static bool Dummy(int x)
var
compilation
=
CreateCompilationWithMscorlib45
(
source
,
options
:
TestOptions
.
DebugExe
);
CompileAndVerify
(
compilation
,
expectedOutput
:
@"1
True"
);
var
tree
=
compilation
.
SyntaxTrees
.
Single
();
var
model
=
compilation
.
GetSemanticModel
(
tree
);
var
x1Decl
=
GetPatternDeclaration
(
tree
,
"x1"
);
var
x1Ref
=
GetReferences
(
tree
,
"x1"
).
Single
();
VerifyModelForDeclarationPattern
(
model
,
x1Decl
,
x1Ref
);
}
[
Fact
]
...
...
@@ -902,6 +909,49 @@ static bool Print(object x)
}
}
[
Fact
]
public
void
Query_02
()
{
var
source
=
@"
using System.Linq;
public class X
{
public static void Main()
{
Test1();
}
static void Test1()
{
var res = from x1 in new[] { 1 is var y1 && Print(y1) ? 2 : 0}
select Print(x1);
res.ToArray();
}
static bool Print(object x)
{
System.Console.WriteLine(x);
return true;
}
}
"
;
var
compilation
=
CreateCompilationWithMscorlib45
(
source
,
new
[]
{
SystemCoreRef
},
options
:
TestOptions
.
DebugExe
,
parseOptions
:
TestOptions
.
Regular
);
CompileAndVerify
(
compilation
,
expectedOutput
:
@"1
2"
);
var
tree
=
compilation
.
SyntaxTrees
.
Single
();
var
model
=
compilation
.
GetSemanticModel
(
tree
);
var
yDecl
=
GetPatternDeclaration
(
tree
,
"y1"
);
var
yRef
=
GetReferences
(
tree
,
"y1"
).
Single
();
VerifyModelForDeclarationPattern
(
model
,
yDecl
,
yRef
);
}
[
Fact
]
public
void
ExpressionBodiedFunctions_01
()
{
...
...
@@ -2359,6 +2409,14 @@ static System.Collections.IEnumerable Dummy(object y, object z)
CompileAndVerify
(
compilation
,
expectedOutput
:
@"3
3"
);
var
tree
=
compilation
.
SyntaxTrees
.
Single
();
var
model
=
compilation
.
GetSemanticModel
(
tree
);
var
x1Decl
=
GetPatternDeclaration
(
tree
,
"x1"
);
var
x1Ref
=
GetReferences
(
tree
,
"x1"
).
ToArray
();
Assert
.
Equal
(
2
,
x1Ref
.
Length
);
VerifyModelForDeclarationPattern
(
model
,
x1Decl
,
x1Ref
);
}
[
Fact
]
...
...
@@ -2775,6 +2833,14 @@ static bool Dummy(object y, object z)
CompileAndVerify
(
compilation
,
expectedOutput
:
@"System.InvalidOperationException
System.InvalidOperationException"
);
var
tree
=
compilation
.
SyntaxTrees
.
Single
();
var
model
=
compilation
.
GetSemanticModel
(
tree
);
var
x1Decl
=
GetPatternDeclaration
(
tree
,
"x1"
);
var
x1Ref
=
GetReferences
(
tree
,
"x1"
).
ToArray
();
Assert
.
Equal
(
2
,
x1Ref
.
Length
);
VerifyModelForDeclarationPattern
(
model
,
x1Decl
,
x1Ref
);
}
[
Fact
]
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_Global.cs
浏览文件 @
1a5cabbf
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录