Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
8d412736
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,发现更多精彩内容 >>
提交
8d412736
编写于
4月 26, 2016
作者:
J
Jared Parsons
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tests for var
上级
2b84f77c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
116 addition
and
10 deletion
+116
-10
src/Compilers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs
...lers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs
+114
-9
src/Test/Utilities/Shared/Traits/CompilerFeature.cs
src/Test/Utilities/Shared/Traits/CompilerFeature.cs
+2
-1
未找到文件。
src/Compilers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs
浏览文件 @
8d412736
...
...
@@ -9,7 +9,7 @@
namespace
Microsoft.CodeAnalysis.CSharp.UnitTests
{
public
static
class
LocalFunctionTests
Ext
public
static
class
LocalFunctionTests
Util
{
public
static
IMethodSymbol
FindLocalFunction
(
this
CommonTestBase
.
CompilationVerifier
verifier
,
string
localFunctionName
)
{
...
...
@@ -32,21 +32,21 @@ public static IMethodSymbol FindLocalFunction(this CommonTestBase.CompilationVer
[
CompilerTrait
(
CompilerFeature
.
LocalFunctions
)]
public
class
LocalFunctionTests
:
CSharpTestBase
{
private
readonly
CSharpParseOptions
_p
arseOptions
=
TestOptions
.
Regular
.
WithLocalFunctionsFeature
();
internal
static
readonly
CSharpParseOptions
DefaultP
arseOptions
=
TestOptions
.
Regular
.
WithLocalFunctionsFeature
();
CompilationVerifier
VerifyOutput
(
string
source
,
string
output
,
CSharpCompilationOptions
options
)
private
CompilationVerifier
VerifyOutput
(
string
source
,
string
output
,
CSharpCompilationOptions
options
)
{
var
comp
=
CreateCompilationWithMscorlib45AndCSruntime
(
source
,
options
:
options
,
parseOptions
:
_p
arseOptions
);
var
comp
=
CreateCompilationWithMscorlib45AndCSruntime
(
source
,
options
:
options
,
parseOptions
:
DefaultP
arseOptions
);
return
CompileAndVerify
(
comp
,
expectedOutput
:
output
).
VerifyDiagnostics
();
// no diagnostics
}
CompilationVerifier
VerifyOutput
(
string
source
,
string
output
)
private
CompilationVerifier
VerifyOutput
(
string
source
,
string
output
)
{
var
comp
=
CreateCompilationWithMscorlib45AndCSruntime
(
source
,
options
:
TestOptions
.
ReleaseExe
,
parseOptions
:
_p
arseOptions
);
var
comp
=
CreateCompilationWithMscorlib45AndCSruntime
(
source
,
options
:
TestOptions
.
ReleaseExe
,
parseOptions
:
DefaultP
arseOptions
);
return
CompileAndVerify
(
comp
,
expectedOutput
:
output
).
VerifyDiagnostics
();
// no diagnostics
}
CompilationVerifier
VerifyOutputInMain
(
string
methodBody
,
string
output
,
params
string
[]
usings
)
private
CompilationVerifier
VerifyOutputInMain
(
string
methodBody
,
string
output
,
params
string
[]
usings
)
{
for
(
var
i
=
0
;
i
<
usings
.
Length
;
i
++)
{
...
...
@@ -66,13 +66,13 @@ static void Main()
private
void
VerifyDiagnostics
(
string
source
,
params
DiagnosticDescription
[]
expected
)
{
var
comp
=
CreateCompilationWithMscorlib45AndCSruntime
(
source
,
options
:
TestOptions
.
ReleaseExe
,
parseOptions
:
_p
arseOptions
);
var
comp
=
CreateCompilationWithMscorlib45AndCSruntime
(
source
,
options
:
TestOptions
.
ReleaseExe
,
parseOptions
:
DefaultP
arseOptions
);
comp
.
VerifyDiagnostics
(
expected
);
}
private
void
VerifyDiagnostics
(
string
source
,
CSharpCompilationOptions
options
,
params
DiagnosticDescription
[]
expected
)
{
var
comp
=
CreateCompilationWithMscorlib45AndCSruntime
(
source
,
options
:
options
,
parseOptions
:
_p
arseOptions
);
var
comp
=
CreateCompilationWithMscorlib45AndCSruntime
(
source
,
options
:
options
,
parseOptions
:
DefaultP
arseOptions
);
comp
.
VerifyDiagnostics
(
expected
);
}
...
...
@@ -3733,5 +3733,110 @@ static void Main(string[] args)
Diagnostic
(
ErrorCode
.
ERR_BadEmbeddedStmt
,
"int Add(int x, int y) => x + y;"
).
WithLocation
(
7
,
9
)
);
}
[
CompilerTrait
(
CompilerFeature
.
LocalFunctions
,
CompilerFeature
.
Var
)]
public
sealed
class
VarTests
:
CSharpTestBase
{
[
Fact
]
public
void
IllegalAsReturn
()
{
var
source
=
@"
using System;
class Program
{
static void Main()
{
var f() => 42;
Console.WriteLine(f());
}
}"
;
var
comp
=
CreateCompilationWithMscorlib45
(
source
,
parseOptions
:
DefaultParseOptions
);
comp
.
VerifyDiagnostics
(
// (7,9): error CS0825: The contextual keyword 'var' may only appear within a local variable declaration or in script code
// var f() => 42;
Diagnostic
(
ErrorCode
.
ERR_TypeVarNotFound
,
"var"
).
WithLocation
(
7
,
9
));
}
[
Fact
]
public
void
RealTypeAsReturn
()
{
var
source
=
@"
using System;
class var
{
public override string ToString() => ""dog"";
}
class Program
{
static void Main()
{
var f() => new var();
Console.WriteLine(f());
}
}"
;
CompileAndVerify
(
source
,
parseOptions
:
DefaultParseOptions
,
expectedOutput
:
"dog"
);
}
[
Fact
]
public
void
RealTypeParameterAsReturn
()
{
var
source
=
@"
using System;
class test
{
public override string ToString() => ""dog"";
}
class Program
{
static void Test<var>(var x)
{
var f() => x;
Console.WriteLine(f());
}
static void Main()
{
Test(new test());
}
}"
;
CompileAndVerify
(
source
,
parseOptions
:
DefaultParseOptions
,
expectedOutput
:
"dog"
);
}
[
Fact
]
public
void
IdentifierAndTypeNamedVar
()
{
var
source
=
@"
using System;
class var
{
public override string ToString() => ""dog"";
}
class Program
{
static void Main()
{
int var = 42;
var f() => new var();
Console.WriteLine($""{f()}-{var}"");
}
}"
;
CompileAndVerify
(
source
,
parseOptions
:
DefaultParseOptions
,
expectedOutput
:
"dog-42"
);
}
}
}
}
src/Test/Utilities/Shared/Traits/CompilerFeature.cs
浏览文件 @
8d412736
...
...
@@ -13,6 +13,7 @@ public enum CompilerFeature
ExpressionBody
,
Iterator
,
LocalFunctions
,
Params
Params
,
Var
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录