Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
c8526d8d
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,发现更多精彩内容 >>
提交
c8526d8d
编写于
10月 14, 2016
作者:
H
Heejae Chang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added unit tests
上级
0f02de0d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
85 addition
and
2 deletion
+85
-2
src/Compilers/Core/CodeAnalysisTest/EmbeddedTextTests.cs
src/Compilers/Core/CodeAnalysisTest/EmbeddedTextTests.cs
+30
-2
src/Compilers/Core/CodeAnalysisTest/Text/LargeTextTests.cs
src/Compilers/Core/CodeAnalysisTest/Text/LargeTextTests.cs
+18
-0
src/Compilers/Core/CodeAnalysisTest/Text/SourceTextTests.cs
src/Compilers/Core/CodeAnalysisTest/Text/SourceTextTests.cs
+37
-0
未找到文件。
src/Compilers/Core/CodeAnalysisTest/EmbeddedTextTests.cs
浏览文件 @
c8526d8d
...
...
@@ -10,8 +10,6 @@
using
System.IO.Compression
;
using
Roslyn.Test.Utilities
;
using
System.Linq
;
using
System.Collections.Immutable
;
using
System.Reflection
;
namespace
Microsoft.CodeAnalysis.UnitTests
{
...
...
@@ -194,6 +192,36 @@ public void FromSource_Large()
AssertEx
.
Equal
(
Encoding
.
Unicode
.
GetPreamble
().
Concat
(
Encoding
.
Unicode
.
GetBytes
(
LargeSource
)),
Decompress
(
text
.
Blob
.
Skip
(
4
)));
}
[
Fact
]
public
void
FromTextReader_Small
()
{
var
expected
=
SourceText
.
From
(
SmallSource
,
Encoding
.
UTF8
,
SourceHashAlgorithm
.
Sha1
);
var
expectedEmbeded
=
EmbeddedText
.
FromSource
(
"pathToSmall"
,
expected
);
var
actual
=
SourceText
.
From
(
new
StringReader
(
SmallSource
),
SmallSource
.
Length
,
Encoding
.
UTF8
,
SourceHashAlgorithm
.
Sha1
);
var
actualEmbeded
=
EmbeddedText
.
FromSource
(
expectedEmbeded
.
FilePath
,
actual
);
Assert
.
Equal
(
expectedEmbeded
.
FilePath
,
actualEmbeded
.
FilePath
);
Assert
.
Equal
(
expectedEmbeded
.
ChecksumAlgorithm
,
actualEmbeded
.
ChecksumAlgorithm
);
AssertEx
.
Equal
(
expectedEmbeded
.
Checksum
,
actualEmbeded
.
Checksum
);
AssertEx
.
Equal
(
expectedEmbeded
.
Blob
,
actualEmbeded
.
Blob
);
}
[
Fact
]
public
void
FromTextReader_Large
()
{
var
expected
=
SourceText
.
From
(
LargeSource
,
Encoding
.
UTF8
,
SourceHashAlgorithm
.
Sha1
);
var
expectedEmbeded
=
EmbeddedText
.
FromSource
(
"pathToSmall"
,
expected
);
var
actual
=
SourceText
.
From
(
new
StringReader
(
LargeSource
),
LargeSource
.
Length
,
Encoding
.
UTF8
,
SourceHashAlgorithm
.
Sha1
);
var
actualEmbeded
=
EmbeddedText
.
FromSource
(
expectedEmbeded
.
FilePath
,
actual
);
Assert
.
Equal
(
expectedEmbeded
.
FilePath
,
actualEmbeded
.
FilePath
);
Assert
.
Equal
(
expectedEmbeded
.
ChecksumAlgorithm
,
actualEmbeded
.
ChecksumAlgorithm
);
AssertEx
.
Equal
(
expectedEmbeded
.
Checksum
,
actualEmbeded
.
Checksum
);
AssertEx
.
Equal
(
expectedEmbeded
.
Blob
,
actualEmbeded
.
Blob
);
}
[
Fact
]
public
void
FromSource_Precomputed
()
{
...
...
src/Compilers/Core/CodeAnalysisTest/Text/LargeTextTests.cs
浏览文件 @
c8526d8d
...
...
@@ -29,6 +29,11 @@ private static SourceText CreateSourceText(Stream stream, Encoding encoding = nu
return
LargeText
.
Decode
(
stream
,
encoding
??
Encoding
.
UTF8
,
SourceHashAlgorithm
.
Sha1
,
throwIfBinaryDetected
:
true
,
canBeEmbedded
:
false
);
}
private
static
SourceText
CreateSourceText
(
TextReader
reader
,
int
length
,
Encoding
encoding
=
null
)
{
return
LargeText
.
Decode
(
reader
,
length
,
encoding
??
Encoding
.
UTF8
,
SourceHashAlgorithm
.
Sha1
);
}
private
const
string
HelloWorld
=
"Hello, world!"
;
[
Fact
]
...
...
@@ -313,5 +318,18 @@ public void LinesGetText2()
var
data
=
CreateSourceText
(
text
);
Assert
.
Equal
(
"foo"
,
data
.
Lines
[
0
].
ToString
());
}
[
Fact
]
public
void
FromTextReader
()
{
var
expected
=
"foo"
;
var
expectedSourceText
=
CreateSourceText
(
expected
);
var
actual
=
new
StringReader
(
expected
);
var
actualSourceText
=
CreateSourceText
(
actual
,
expected
.
Length
);
Assert
.
Equal
(
"foo"
,
actualSourceText
.
Lines
[
0
].
ToString
());
Assert
.
Equal
<
byte
>(
expectedSourceText
.
GetChecksum
(),
actualSourceText
.
GetChecksum
());
}
}
}
\ No newline at end of file
src/Compilers/Core/CodeAnalysisTest/Text/SourceTextTests.cs
浏览文件 @
c8526d8d
...
...
@@ -229,6 +229,43 @@ public void FromThrowsIfBinary()
Assert
.
Throws
<
InvalidDataException
>(()
=>
SourceText
.
From
(
stream
,
throwIfBinaryDetected
:
true
));
}
[
Fact
]
public
void
FromTextReader
()
{
var
expected
=
"Text reader source text test"
;
var
expectedSourceText
=
SourceText
.
From
(
expected
);
var
actual
=
new
StringReader
(
expected
);
var
actualSourceText
=
SourceText
.
From
(
actual
,
expected
.
Length
);
Assert
.
Equal
<
byte
>(
expectedSourceText
.
GetChecksum
(),
actualSourceText
.
GetChecksum
());
var
utf8NoBOM
=
new
UTF8Encoding
(
encoderShouldEmitUTF8Identifier
:
false
);
Assert
.
Same
(
s_utf8
,
SourceText
.
From
(
actual
,
expected
.
Length
,
s_utf8
).
Encoding
);
Assert
.
Same
(
s_unicode
,
SourceText
.
From
(
actual
,
expected
.
Length
,
s_unicode
).
Encoding
);
Assert
.
Equal
(
utf8NoBOM
,
SourceText
.
From
(
actual
,
expected
.
Length
,
null
).
Encoding
);
}
[
Fact
]
public
void
FromTextReader_Large
()
{
var
expected
=
new
string
(
'l'
,
SourceText
.
LargeObjectHeapLimitInChars
);
var
expectedSourceText
=
SourceText
.
From
(
expected
);
var
actual
=
new
StringReader
(
expected
);
var
actualSourceText
=
SourceText
.
From
(
actual
,
expected
.
Length
);
Assert
.
IsType
<
LargeText
>(
actualSourceText
);
Assert
.
Equal
<
byte
>(
expectedSourceText
.
GetChecksum
(),
actualSourceText
.
GetChecksum
());
var
utf8NoBOM
=
new
UTF8Encoding
(
encoderShouldEmitUTF8Identifier
:
false
);
Assert
.
Same
(
s_utf8
,
SourceText
.
From
(
actual
,
expected
.
Length
,
s_utf8
).
Encoding
);
Assert
.
Same
(
s_unicode
,
SourceText
.
From
(
actual
,
expected
.
Length
,
s_unicode
).
Encoding
);
Assert
.
Equal
(
utf8NoBOM
,
SourceText
.
From
(
actual
,
expected
.
Length
,
null
).
Encoding
);
}
private
static
void
TestTryReadByteOrderMark
(
Encoding
expectedEncoding
,
int
expectedPreambleLength
,
byte
[]
data
)
{
TestTryReadByteOrderMark
(
expectedEncoding
,
expectedPreambleLength
,
data
,
data
==
null
?
0
:
data
.
Length
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录