Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
537c8966
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,发现更多精彩内容 >>
提交
537c8966
编写于
8月 19, 2015
作者:
C
Charles Stoner
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4650 from cston/cp-tests
Add tests for cut and copy
上级
aef3fe30
9ba52ab5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
155 addition
and
5 deletion
+155
-5
src/InteractiveWindow/EditorTest/InteractiveWindowTests.cs
src/InteractiveWindow/EditorTest/InteractiveWindowTests.cs
+155
-5
未找到文件。
src/InteractiveWindow/EditorTest/InteractiveWindowTests.cs
浏览文件 @
537c8966
...
...
@@ -5,6 +5,7 @@
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
System.Windows
;
using
Microsoft.VisualStudio.InteractiveWindow.Commands
;
using
Microsoft.VisualStudio.Text
;
using
Moq
;
...
...
@@ -26,15 +27,15 @@ public InteractiveWindowTests()
_testHost
=
new
InteractiveWindowTestHost
(
_states
.
Add
);
}
public
void
Dispose
()
void
IDisposable
.
Dispose
()
{
_testHost
.
Dispose
();
}
p
ublic
IInteractiveWindow
Window
=>
_testHost
.
Window
;
p
rivate
IInteractiveWindow
Window
=>
_testHost
.
Window
;
internal
List
<
ReplSpan
>
ProjectionSpans
=>
((
InteractiveWindow
)
Window
).
ProjectionSpans
;
p
ublic
static
IEnumerable
<
IInteractiveWindowCommand
>
MockCommands
(
params
string
[]
commandNames
)
p
rivate
static
IEnumerable
<
IInteractiveWindowCommand
>
MockCommands
(
params
string
[]
commandNames
)
{
foreach
(
var
name
in
commandNames
)
{
...
...
@@ -44,7 +45,7 @@ public static IEnumerable<IInteractiveWindowCommand> MockCommands(params string[
}
}
p
ublic
static
ITextSnapshot
MockSnapshot
(
string
content
)
p
rivate
static
ITextSnapshot
MockSnapshot
(
string
content
)
{
var
snapshotMock
=
new
Mock
<
ITextSnapshot
>();
snapshotMock
.
Setup
(
m
=>
m
[
It
.
IsAny
<
int
>()]).
Returns
<
int
>(
index
=>
content
[
index
]);
...
...
@@ -55,7 +56,7 @@ public static ITextSnapshot MockSnapshot(string content)
return
snapshotMock
.
Object
;
}
p
ublic
string
GetTextFromCurrentLanguageBuffer
()
p
rivate
string
GetTextFromCurrentLanguageBuffer
()
{
return
Window
.
CurrentLanguageBuffer
.
CurrentSnapshot
.
GetText
();
}
...
...
@@ -696,5 +697,154 @@ public void ResetCommandNoConfigClassification()
Assert
.
Equal
(
new
[]
{
0
,
9
},
ResetCommand
.
GetNoConfigPositions
(
"noconfig noconfig"
));
Assert
.
Equal
(
new
[]
{
0
,
15
},
ResetCommand
.
GetNoConfigPositions
(
"noconfig error noconfig"
));
}
[
Fact
]
public
void
CopyWithinInput
()
{
Clipboard
.
Clear
();
Window
.
InsertCode
(
"1 + 2"
);
Window
.
Operations
.
SelectAll
();
Window
.
Operations
.
Copy
();
VerifyClipboardData
(
"1 + 2"
);
// Shrink the selection.
var
selection
=
Window
.
TextView
.
Selection
;
var
span
=
selection
.
SelectedSpans
[
0
];
selection
.
Select
(
new
SnapshotSpan
(
span
.
Snapshot
,
span
.
Start
+
1
,
span
.
Length
-
2
),
isReversed
:
false
);
Window
.
Operations
.
Copy
();
VerifyClipboardData
(
" + "
);
}
[
Fact
]
public
void
CopyInputAndOutput
()
{
Clipboard
.
Clear
();
Submit
(
@"foreach (var o in new[] { 1, 2, 3 })
System.Console.WriteLine();"
,
@"1
2
3
"
);
var
caret
=
Window
.
TextView
.
Caret
;
caret
.
MoveToPreviousCaretPosition
();
caret
.
MoveToPreviousCaretPosition
();
Window
.
Operations
.
SelectAll
();
Window
.
Operations
.
Copy
();
VerifyClipboardData
(
@"foreach (var o in new[] { 1, 2, 3 })
System.Console.WriteLine();
1
2
3
"
,
@"> foreach (var o in new[] \{ 1, 2, 3 \})\par > System.Console.WriteLine();\par 1\par 2\par 3\par > "
);
// Shrink the selection.
var
selection
=
Window
.
TextView
.
Selection
;
var
span
=
selection
.
SelectedSpans
[
0
];
selection
.
Select
(
new
SnapshotSpan
(
span
.
Snapshot
,
span
.
Start
+
3
,
span
.
Length
-
6
),
isReversed
:
false
);
Window
.
Operations
.
Copy
();
VerifyClipboardData
(
@"oreach (var o in new[] { 1, 2, 3 })
System.Console.WriteLine();
1
2
3"
,
@"oreach (var o in new[] \{ 1, 2, 3 \})\par > System.Console.WriteLine();\par 1\par 2\par 3"
);
}
[
Fact
]
public
void
CutWithinInput
()
{
Clipboard
.
Clear
();
Window
.
InsertCode
(
"foreach (var o in new[] { 1, 2, 3 })"
);
Window
.
Operations
.
BreakLine
();
Window
.
InsertCode
(
"System.Console.WriteLine();"
);
Window
.
Operations
.
BreakLine
();
var
caret
=
Window
.
TextView
.
Caret
;
caret
.
MoveToPreviousCaretPosition
();
caret
.
MoveToPreviousCaretPosition
();
Window
.
Operations
.
SelectAll
();
// Shrink the selection.
var
selection
=
Window
.
TextView
.
Selection
;
var
span
=
selection
.
SelectedSpans
[
0
];
selection
.
Select
(
new
SnapshotSpan
(
span
.
Snapshot
,
span
.
Start
+
3
,
span
.
Length
-
6
),
isReversed
:
false
);
Window
.
Operations
.
Cut
();
VerifyClipboardData
(
@"each (var o in new[] { 1, 2, 3 })
System.Console.WriteLine()"
,
expectedRtf
:
null
);
}
[
Fact
]
public
void
CutInputAndOutput
()
{
Clipboard
.
Clear
();
Submit
(
@"foreach (var o in new[] { 1, 2, 3 })
System.Console.WriteLine();"
,
@"1
2
3
"
);
var
caret
=
Window
.
TextView
.
Caret
;
caret
.
MoveToPreviousCaretPosition
();
caret
.
MoveToPreviousCaretPosition
();
Window
.
Operations
.
SelectAll
();
Window
.
Operations
.
Cut
();
VerifyClipboardData
(
null
);
}
private
void
Submit
(
string
submission
,
string
output
)
{
Task
.
Run
(()
=>
Window
.
SubmitAsync
(
new
[]
{
submission
})).
PumpingWait
();
// TestInteractiveEngine.ExecuteCodeAsync() simply returns
// success rather than executing the submission, so add the
// expected output to the output buffer.
var
buffer
=
Window
.
OutputBuffer
;
using
(
var
edit
=
buffer
.
CreateEdit
())
{
edit
.
Replace
(
buffer
.
CurrentSnapshot
.
Length
,
0
,
output
);
edit
.
Apply
();
}
}
private
static
void
VerifyClipboardData
(
string
expectedText
)
{
VerifyClipboardData
(
expectedText
,
expectedText
);
}
private
static
void
VerifyClipboardData
(
string
expectedText
,
string
expectedRtf
)
{
var
data
=
Clipboard
.
GetDataObject
();
Assert
.
Equal
(
expectedText
,
data
.
GetData
(
DataFormats
.
StringFormat
));
Assert
.
Equal
(
expectedText
,
data
.
GetData
(
DataFormats
.
Text
));
Assert
.
Equal
(
expectedText
,
data
.
GetData
(
DataFormats
.
UnicodeText
));
var
actualRtf
=
(
string
)
data
.
GetData
(
DataFormats
.
Rtf
);
if
(
expectedRtf
==
null
)
{
Assert
.
Null
(
actualRtf
);
}
else
{
Assert
.
True
(
actualRtf
.
StartsWith
(
@"{\rtf"
));
Assert
.
True
(
actualRtf
.
EndsWith
(
expectedRtf
+
"}"
));
}
}
}
internal
static
class
OperationsExtensions
{
internal
static
void
Copy
(
this
IInteractiveWindowOperations
operations
)
{
((
IInteractiveWindowOperations2
)
operations
).
Copy
();
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录