Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
a3f76b60
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,发现更多精彩内容 >>
提交
a3f76b60
编写于
9月 28, 2015
作者:
P
Paul Chen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Treat [,..,] as empty. Add combo test cases.
上级
6af8c3e9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
248 addition
and
40 deletion
+248
-40
src/Workspaces/CSharp/Portable/Formatting/Rules/SpacingFormattingRule.cs
...CSharp/Portable/Formatting/Rules/SpacingFormattingRule.cs
+15
-22
src/Workspaces/CSharpTest/Formatting/FormattingTests.cs
src/Workspaces/CSharpTest/Formatting/FormattingTests.cs
+233
-18
未找到文件。
src/Workspaces/CSharp/Portable/Formatting/Rules/SpacingFormattingRule.cs
浏览文件 @
a3f76b60
...
...
@@ -163,11 +163,9 @@ public override AdjustSpacesOperation GetAdjustSpacesOperation(SyntaxToken previ
return
AdjustSpacesOperationZeroOrOne
(
optionSet
,
CSharpFormattingOptions
.
SpaceBeforeOpenSquareBracket
);
}
// For spacing empty square braces
if
(
previousKind
==
SyntaxKind
.
OpenBracketToken
&&
(
currentKind
==
SyntaxKind
.
CloseBracketToken
||
(
currentKind
==
SyntaxKind
.
OmittedArraySizeExpressionToken
&&
(
previousToken
.
Parent
as
ArrayRankSpecifierSyntax
)?.
Rank
==
1
))
// For spacing empty square braces, also treat [,] as empty
if
(((
currentKind
==
SyntaxKind
.
CloseBracketToken
&&
previousKind
==
SyntaxKind
.
OpenBracketToken
)
||
currentKind
==
SyntaxKind
.
OmittedArraySizeExpressionToken
)
&&
HasFormattableBracketParent
(
previousToken
))
{
return
AdjustSpacesOperationZeroOrOne
(
optionSet
,
CSharpFormattingOptions
.
SpaceBetweenEmptySquareBrackets
);
...
...
@@ -178,23 +176,12 @@ public override AdjustSpacesOperation GetAdjustSpacesOperation(SyntaxToken previ
{
return
AdjustSpacesOperationZeroOrOne
(
optionSet
,
CSharpFormattingOptions
.
SpaceWithinSquareBrackets
);
}
if
(
currentKind
==
SyntaxKind
.
OmittedArraySizeExpressionToken
&&
previousKind
==
SyntaxKind
.
CommaToken
)
{
var
rankSpec
=
previousToken
.
Parent
as
ArrayRankSpecifierSyntax
;
if
(
rankSpec
!=
null
&&
currentToken
.
Parent
==
rankSpec
.
Sizes
.
Last
())
{
return
AdjustSpacesOperationZeroOrOne
(
optionSet
,
CSharpFormattingOptions
.
SpaceWithinSquareBrackets
);
}
}
else
if
(
currentKind
==
SyntaxKind
.
CloseBracketToken
&&
HasFormattableBracketParent
(
currentToken
))
if
(
currentKind
==
SyntaxKind
.
CloseBracketToken
&&
previousKind
!=
SyntaxKind
.
OmittedArraySizeExpressionToken
&&
HasFormattableBracketParent
(
currentToken
))
{
// int []: added spacing operation on [
// int[,]: added spacing operation on ,
// int[1]: need spacing operation
if
(
previousKind
!=
SyntaxKind
.
OmittedArraySizeExpressionToken
)
{
return
AdjustSpacesOperationZeroOrOne
(
optionSet
,
CSharpFormattingOptions
.
SpaceWithinSquareBrackets
);
}
return
AdjustSpacesOperationZeroOrOne
(
optionSet
,
CSharpFormattingOptions
.
SpaceWithinSquareBrackets
);
}
// For spacing delimiters - after colon
...
...
@@ -210,15 +197,21 @@ public override AdjustSpacesOperation GetAdjustSpacesOperation(SyntaxToken previ
}
// For spacing delimiters - after comma
if
((
previousToken
.
IsCommaInArgumentOrParameterList
()
&&
currentKind
!=
SyntaxKind
.
OmittedTypeArgumentToken
)
||
previousToken
.
IsCommaInInitializerExpression
())
if
((
previousToken
.
IsCommaInArgumentOrParameterList
()
&&
currentKind
!=
SyntaxKind
.
OmittedTypeArgumentToken
)
||
previousToken
.
IsCommaInInitializerExpression
()
||
(
previousKind
==
SyntaxKind
.
CommaToken
&&
currentKind
!=
SyntaxKind
.
OmittedArraySizeExpressionToken
&&
HasFormattableBracketParent
(
previousToken
)))
{
return
AdjustSpacesOperationZeroOrOne
(
optionSet
,
CSharpFormattingOptions
.
SpaceAfterComma
);
}
// For spacing delimiters - before comma
if
((
currentToken
.
IsCommaInArgumentOrParameterList
()
&&
previousKind
!=
SyntaxKind
.
OmittedTypeArgumentToken
)
||
currentToken
.
IsCommaInInitializerExpression
())
if
((
currentToken
.
IsCommaInArgumentOrParameterList
()
&&
previousKind
!=
SyntaxKind
.
OmittedTypeArgumentToken
)
||
currentToken
.
IsCommaInInitializerExpression
()
||
(
currentKind
==
SyntaxKind
.
CommaToken
&&
previousKind
!=
SyntaxKind
.
OmittedArraySizeExpressionToken
&&
HasFormattableBracketParent
(
currentToken
)))
{
return
AdjustSpacesOperationZeroOrOne
(
optionSet
,
CSharpFormattingOptions
.
SpaceBeforeComma
);
}
...
...
src/Workspaces/CSharpTest/Formatting/FormattingTests.cs
浏览文件 @
a3f76b60
...
...
@@ -8,6 +8,7 @@
using
Microsoft.CodeAnalysis.Test.Utilities
;
using
Roslyn.Test.Utilities
;
using
Xunit
;
using
static
Microsoft
.
CodeAnalysis
.
CSharp
.
Formatting
.
CSharpFormattingOptions
;
namespace
Microsoft.CodeAnalysis.CSharp.UnitTests.Formatting
{
...
...
@@ -5352,57 +5353,271 @@ void foo()
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Formatting
)]
public
void
S
quareBracesEmpty_True
()
public
void
S
paceWithinEmptyBracketPrecedencesSpaceBeforeOrAfterComma_00
()
{
var
code
=
@"
class Program
{
int[ ] x;
int[ , ] y;
int[ , , ] z = new int[1,2,3];
var a = new[ ] { 0 };
}"
;
var
expected00
=
@"
class Program
{
int[] x;
int[ ,] y;
var z = new[] { 0 };
int[,] y;
int[,,] z = new int[1,2,3];
var a = new[] { 0 };
}"
;
var
expected
=
@"
var
expected
01
=
@"
class Program
{
int[ ] x;
int[] x;
int[,] y;
int[,,] z = new int[1, 2, 3];
var a = new[] { 0 };
}"
;
var
expected10
=
@"
class Program
{
int[] x;
int[,] y;
var z = new[ ] { 0 };
int[,,] z = new int[1 ,2 ,3];
var a = new[] { 0 };
}"
;
var
expected11
=
@"
class Program
{
int[] x;
int[,] y;
int[,,] z = new int[1 , 2 , 3];
var a = new[] { 0 };
}"
;
var
options
=
new
Dictionary
<
OptionKey
,
object
>()
{
{
CSharpFormattingOptions
.
SpaceBetweenEmptySquareBrackets
,
true
},
{
CSharpFormattingOptions
.
SpaceWithinSquareBrackets
,
false
},
{
SpaceBeforeComma
,
false
},
{
SpaceAfterComma
,
false
},
{
SpaceBetweenEmptySquareBrackets
,
false
},
{
SpaceWithinSquareBrackets
,
false
},
};
AssertFormat
(
expected
,
code
,
changedOptionSet
:
options
);
AssertFormat
(
"// 00"
+
expected00
,
"// 00"
+
code
,
changedOptionSet
:
options
);
options
[
SpaceBeforeComma
]
=
true
;
AssertFormat
(
"// 10"
+
expected10
,
"// 10"
+
code
,
changedOptionSet
:
options
);
options
[
SpaceAfterComma
]
=
true
;
AssertFormat
(
"// 11"
+
expected11
,
"// 11"
+
code
,
changedOptionSet
:
options
);
options
[
SpaceBeforeComma
]
=
false
;
AssertFormat
(
"// 01"
+
expected01
,
"// 01"
+
code
,
changedOptionSet
:
options
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Formatting
)]
public
void
S
quareBracesEmpty_False
()
public
void
S
paceWithinEmptyBracketPrecedencesSpaceBeforeOrAfterComma_01
()
{
var
code
=
@"
class Program
{
int[ ] x;
var z = new[ ] { 0 };
int[, ] x;
int[, ] y;
int[, , ] z = new int[1,2,3];
var a = new[ ] { 0 };
}"
;
var
expected
=
@"
var
expected00
=
@"
class Program
{
int[] x;
int[,] y;
int[,,] z = new int[ 1,2,3 ];
var a = new[] { 0 };
}"
;
var
expected01
=
@"
class Program
{
int[] x;
int[,] y;
int[,,] z = new int[ 1, 2, 3 ];
var a = new[] { 0 };
}"
;
var
expected10
=
@"
class Program
{
int[] x;
var z = new[] { 0 };
int[ , ] x;
int[,] y;
int[,,] z = new int[ 1 ,2 ,3 ];
var a = new[] { 0 };
}"
;
var
expected11
=
@"
class Program
{
int[] x;
int[,] y;
int[,,] z = new int[ 1 , 2 , 3 ];
var a = new[] { 0 };
}"
;
var
options
=
new
Dictionary
<
OptionKey
,
object
>()
{
{
CSharpFormattingOptions
.
SpaceBetweenEmptySquareBrackets
,
false
},
{
CSharpFormattingOptions
.
SpaceWithinSquareBrackets
,
true
},
{
SpaceBeforeComma
,
false
},
{
SpaceAfterComma
,
false
},
{
SpaceBetweenEmptySquareBrackets
,
false
},
{
SpaceWithinSquareBrackets
,
true
},
};
AssertFormat
(
expected
,
code
,
changedOptionSet
:
options
);
AssertFormat
(
"// 00"
+
expected00
,
"// 00"
+
code
,
changedOptionSet
:
options
);
options
[
SpaceBeforeComma
]
=
true
;
AssertFormat
(
"// 10"
+
expected10
,
"// 10"
+
code
,
changedOptionSet
:
options
);
options
[
SpaceAfterComma
]
=
true
;
AssertFormat
(
"// 11"
+
expected11
,
"// 11"
+
code
,
changedOptionSet
:
options
);
options
[
SpaceBeforeComma
]
=
false
;
AssertFormat
(
"// 01"
+
expected01
,
"// 01"
+
code
,
changedOptionSet
:
options
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Formatting
)]
public
void
SpaceWithinEmptyBracketPrecedencesSpaceBeforeOrAfterComma_10
()
{
var
code
=
@"
class Program
{
int[] x;
int[ ,] y;
int[ , ,] z = new int[1,2,3];
var a = new[] { 0 };
}"
;
var
expected00
=
@"
class Program
{
int[ ] x;
int[ , ] y;
int[ , , ] z = new int[1,2,3];
var a = new[ ] { 0 };
}"
;
var
expected01
=
@"
class Program
{
int[ ] x;
int[ , ] y;
int[ , , ] z = new int[1, 2, 3];
var a = new[ ] { 0 };
}"
;
var
expected10
=
@"
class Program
{
int[ ] x;
int[ , ] y;
int[ , , ] z = new int[1 ,2 ,3];
var a = new[ ] { 0 };
}"
;
var
expected11
=
@"
class Program
{
int[ ] x;
int[ , ] y;
int[ , , ] z = new int[1 , 2 , 3];
var a = new[ ] { 0 };
}"
;
var
options
=
new
Dictionary
<
OptionKey
,
object
>()
{
{
SpaceBeforeComma
,
false
},
{
SpaceAfterComma
,
false
},
{
SpaceBetweenEmptySquareBrackets
,
true
},
{
SpaceWithinSquareBrackets
,
false
},
};
AssertFormat
(
"// 00"
+
expected00
,
"// 00"
+
code
,
changedOptionSet
:
options
);
options
[
SpaceBeforeComma
]
=
true
;
AssertFormat
(
"// 10"
+
expected10
,
"// 10"
+
code
,
changedOptionSet
:
options
);
options
[
SpaceAfterComma
]
=
true
;
AssertFormat
(
"// 11"
+
expected11
,
"// 11"
+
code
,
changedOptionSet
:
options
);
options
[
SpaceBeforeComma
]
=
false
;
AssertFormat
(
"// 01"
+
expected01
,
"// 01"
+
code
,
changedOptionSet
:
options
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Formatting
)]
public
void
SpaceWithinEmptyBracketPrecedencesSpaceBeforeOrAfterComma_11
()
{
var
code
=
@"
class Program
{
int[ ] x;
int[ , ] y;
int[ , , ] z = new int[1,2,3];
var a = new[ ] { 0 };
}"
;
var
expected00
=
@"
class Program
{
int[ ] x;
int[ , ] y;
int[ , , ] z = new int[ 1,2,3 ];
var a = new[ ] { 0 };
}"
;
var
expected01
=
@"
class Program
{
int[ ] x;
int[ , ] y;
int[ , , ] z = new int[ 1, 2, 3 ];
var a = new[ ] { 0 };
}"
;
var
expected10
=
@"
class Program
{
int[ ] x;
int[ , ] y;
int[ , , ] z = new int[ 1 ,2 ,3 ];
var a = new[ ] { 0 };
}"
;
var
expected11
=
@"
class Program
{
int[ ] x;
int[ , ] y;
int[ , , ] z = new int[ 1 , 2 , 3 ];
var a = new[ ] { 0 };
}"
;
var
options
=
new
Dictionary
<
OptionKey
,
object
>()
{
{
SpaceBeforeComma
,
false
},
{
SpaceAfterComma
,
false
},
{
SpaceBetweenEmptySquareBrackets
,
true
},
{
SpaceWithinSquareBrackets
,
true
},
};
AssertFormat
(
"// 00"
+
expected00
,
"// 00"
+
code
,
changedOptionSet
:
options
);
options
[
SpaceBeforeComma
]
=
true
;
AssertFormat
(
"// 10"
+
expected10
,
"// 10"
+
code
,
changedOptionSet
:
options
);
options
[
SpaceAfterComma
]
=
true
;
AssertFormat
(
"// 11"
+
expected11
,
"// 11"
+
code
,
changedOptionSet
:
options
);
options
[
SpaceBeforeComma
]
=
false
;
AssertFormat
(
"// 01"
+
expected01
,
"// 01"
+
code
,
changedOptionSet
:
options
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Formatting
)]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录