Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
e8bc943d
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e8bc943d
编写于
2月 07, 2018
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adding more tests for toc provider
上级
b93fa7bf
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
62 addition
and
7 deletion
+62
-7
extensions/markdown/src/test/tableOfContentsProvider.test.ts
extensions/markdown/src/test/tableOfContentsProvider.test.ts
+62
-7
未找到文件。
extensions/markdown/src/test/tableOfContentsProvider.test.ts
浏览文件 @
e8bc943d
...
...
@@ -9,13 +9,68 @@ import * as vscode from 'vscode';
import
{
TableOfContentsProvider
}
from
'
../tableOfContentsProvider
'
;
import
{
MarkdownEngine
}
from
'
../markdownEngine
'
;
const
testFileName
=
vscode
.
Uri
.
parse
(
'
test.md
'
);
suite
(
'
markdown.TableOfContentsProvider
'
,
()
=>
{
test
(
'
Should not return anything for empty document
'
,
async
()
=>
{
const
doc
=
new
InMemoryDocument
(
vscode
.
Uri
.
parse
(
'
test.md
'
),
''
);
test
(
'
Lookup should not return anything for empty document
'
,
async
()
=>
{
const
doc
=
new
InMemoryDocument
(
testFileName
,
''
);
const
provider
=
new
TableOfContentsProvider
(
new
MarkdownEngine
(),
doc
);
assert
.
strictEqual
(
await
provider
.
lookup
(
''
),
undefined
);
assert
.
strictEqual
(
await
provider
.
lookup
(
'
foo
'
),
undefined
);
});
test
(
'
Lookup should not return anything for document with no headers
'
,
async
()
=>
{
const
doc
=
new
InMemoryDocument
(
testFileName
,
'
a *b*
\n
c
'
);
const
provider
=
new
TableOfContentsProvider
(
new
MarkdownEngine
(),
doc
);
assert
.
strictEqual
(
await
provider
.
lookup
(
''
),
undefined
);
assert
.
strictEqual
(
await
provider
.
lookup
(
'
foo
'
),
undefined
);
assert
.
strictEqual
(
await
provider
.
lookup
(
'
a
'
),
undefined
);
assert
.
strictEqual
(
await
provider
.
lookup
(
'
b
'
),
undefined
);
});
test
(
'
Lookup should return basic #header
'
,
async
()
=>
{
const
doc
=
new
InMemoryDocument
(
testFileName
,
`# a\nx\n# c`
);
const
provider
=
new
TableOfContentsProvider
(
new
MarkdownEngine
(),
doc
);
{
const
entry
=
await
provider
.
lookup
(
'
a
'
);
assert
.
ok
(
entry
);
assert
.
strictEqual
(
entry
!
.
line
,
0
);
}
{
assert
.
strictEqual
(
await
provider
.
lookup
(
'
x
'
),
undefined
);
}
{
const
entry
=
await
provider
.
lookup
(
'
c
'
);
assert
.
ok
(
entry
);
assert
.
strictEqual
(
entry
!
.
line
,
2
);
}
});
test
(
'
Lookups should be case in-sensitive
'
,
async
()
=>
{
const
doc
=
new
InMemoryDocument
(
testFileName
,
`# fOo\n`
);
const
provider
=
new
TableOfContentsProvider
(
new
MarkdownEngine
(),
doc
);
assert
.
strictEqual
((
await
provider
.
lookup
(
'
fOo
'
))
!
.
line
,
0
);
assert
.
strictEqual
((
await
provider
.
lookup
(
'
foo
'
))
!
.
line
,
0
);
assert
.
strictEqual
((
await
provider
.
lookup
(
'
FOO
'
))
!
.
line
,
0
);
});
test
(
'
Lookups should ignore leading and trailing white-space, and collapse internal whitespace
'
,
async
()
=>
{
const
doc
=
new
InMemoryDocument
(
testFileName
,
`# f o o \n`
);
const
provider
=
new
TableOfContentsProvider
(
new
MarkdownEngine
(),
doc
);
assert
.
strictEqual
((
await
provider
.
lookup
(
'
f o o
'
))
!
.
line
,
0
);
assert
.
strictEqual
((
await
provider
.
lookup
(
'
f o o
'
))
!
.
line
,
0
);
assert
.
strictEqual
((
await
provider
.
lookup
(
'
f o o
'
))
!
.
line
,
0
);
assert
.
strictEqual
((
await
provider
.
lookup
(
'
f o o
'
))
!
.
line
,
0
);
assert
.
strictEqual
((
await
provider
.
lookup
(
'
f o o
'
))
!
.
line
,
0
);
assert
.
strictEqual
(
await
provider
.
lookup
(
'
f
'
),
undefined
);
assert
.
strictEqual
(
await
provider
.
lookup
(
'
foo
'
),
undefined
);
assert
.
strictEqual
(
await
provider
.
lookup
(
'
fo o
'
),
undefined
);
});
});
...
...
@@ -24,9 +79,9 @@ class InMemoryDocument implements vscode.TextDocument {
constructor
(
public
readonly
uri
:
vscode
.
Uri
,
contents
:
string
private
readonly
_
contents
:
string
)
{
this
.
_lines
=
contents
.
split
(
/
\n
/g
);
this
.
_lines
=
this
.
_
contents
.
split
(
/
\n
/g
);
}
fileName
:
string
=
''
;
...
...
@@ -54,11 +109,11 @@ class InMemoryDocument implements vscode.TextDocument {
offsetAt
(
_position
:
vscode
.
Position
):
never
{
throw
new
Error
(
'
Method not implemented.
'
);
}
positionAt
(
_offset
:
number
):
never
{
positionAt
(
_offset
:
number
):
never
{
throw
new
Error
(
'
Method not implemented.
'
);
}
getText
(
_range
?:
vscode
.
Range
|
undefined
):
never
{
throw
new
Error
(
'
Method not implemented.
'
)
;
getText
(
_range
?:
vscode
.
Range
|
undefined
):
string
{
return
this
.
_contents
;
}
getWordRangeAtPosition
(
_position
:
vscode
.
Position
,
_regex
?:
RegExp
|
undefined
):
never
{
throw
new
Error
(
'
Method not implemented.
'
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录