Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
668ff04c
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,发现更多精彩内容 >>
提交
668ff04c
编写于
8月 31, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merge model.brackets.test.ts into textModelWithTokens.test.ts
上级
06241839
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
123 addition
and
130 deletion
+123
-130
src/vs/editor/test/common/model/model.brackets.test.ts
src/vs/editor/test/common/model/model.brackets.test.ts
+0
-130
src/vs/editor/test/common/model/textModelWithTokens.test.ts
src/vs/editor/test/common/model/textModelWithTokens.test.ts
+123
-0
未找到文件。
src/vs/editor/test/common/model/model.brackets.test.ts
已删除
100644 → 0
浏览文件 @
06241839
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
IFoundBracket
}
from
'
vs/editor/common/editorCommon
'
;
import
{
TextModel
}
from
'
vs/editor/common/model/textModel
'
;
import
{
TextModelWithTokens
}
from
'
vs/editor/common/model/textModelWithTokens
'
;
suite
(
'
TextModelWithTokens
'
,
()
=>
{
function
toRelaxedFoundBracket
(
a
:
IFoundBracket
)
{
if
(
!
a
)
{
return
null
;
}
return
{
range
:
a
.
range
.
toString
(),
open
:
a
.
open
,
close
:
a
.
close
,
isOpen
:
a
.
isOpen
};
}
function
testBrackets
(
contents
:
string
[],
brackets
:
string
[][]):
void
{
let
charIsBracket
:
{[
char
:
string
]:
boolean
}
=
{};
let
charIsOpenBracket
:
{[
char
:
string
]:
boolean
}
=
{};
let
openForChar
:
{[
char
:
string
]:
string
}
=
{};
let
closeForChar
:
{[
char
:
string
]:
string
}
=
{};
brackets
.
forEach
((
b
)
=>
{
charIsBracket
[
b
[
0
]]
=
true
;
charIsBracket
[
b
[
1
]]
=
true
;
charIsOpenBracket
[
b
[
0
]]
=
true
;
charIsOpenBracket
[
b
[
1
]]
=
false
;
openForChar
[
b
[
0
]]
=
b
[
0
];
closeForChar
[
b
[
0
]]
=
b
[
1
];
openForChar
[
b
[
1
]]
=
b
[
0
];
closeForChar
[
b
[
1
]]
=
b
[
1
];
});
let
expectedBrackets
:
IFoundBracket
[]
=
[];
for
(
let
lineIndex
=
0
;
lineIndex
<
contents
.
length
;
lineIndex
++
)
{
let
lineText
=
contents
[
lineIndex
];
for
(
let
charIndex
=
0
;
charIndex
<
lineText
.
length
;
charIndex
++
)
{
let
ch
=
lineText
.
charAt
(
charIndex
);
if
(
charIsBracket
[
ch
])
{
expectedBrackets
.
push
({
open
:
openForChar
[
ch
],
close
:
closeForChar
[
ch
],
isOpen
:
charIsOpenBracket
[
ch
],
range
:
new
Range
(
lineIndex
+
1
,
charIndex
+
1
,
lineIndex
+
1
,
charIndex
+
2
)
});
}
}
}
let
model
=
new
TextModelWithTokens
([],
TextModel
.
toRawText
(
contents
.
join
(
'
\n
'
),
TextModel
.
DEFAULT_CREATION_OPTIONS
),
null
);
// findPrevBracket
{
let
expectedBracketIndex
=
expectedBrackets
.
length
-
1
;
let
currentExpectedBracket
=
expectedBracketIndex
>=
0
?
expectedBrackets
[
expectedBracketIndex
]
:
null
;
for
(
let
lineNumber
=
contents
.
length
;
lineNumber
>=
1
;
lineNumber
--
)
{
let
lineText
=
contents
[
lineNumber
-
1
];
for
(
let
column
=
lineText
.
length
+
1
;
column
>=
1
;
column
--
)
{
if
(
currentExpectedBracket
)
{
if
(
lineNumber
===
currentExpectedBracket
.
range
.
startLineNumber
&&
column
<
currentExpectedBracket
.
range
.
endColumn
)
{
expectedBracketIndex
--
;
currentExpectedBracket
=
expectedBracketIndex
>=
0
?
expectedBrackets
[
expectedBracketIndex
]
:
null
;
}
}
let
actual
=
model
.
findPrevBracket
({
lineNumber
:
lineNumber
,
column
:
column
});
assert
.
deepEqual
(
toRelaxedFoundBracket
(
actual
),
toRelaxedFoundBracket
(
currentExpectedBracket
),
'
findPrevBracket of
'
+
lineNumber
+
'
,
'
+
column
);
}
}
}
// findNextBracket
{
let
expectedBracketIndex
=
0
;
let
currentExpectedBracket
=
expectedBracketIndex
<
expectedBrackets
.
length
?
expectedBrackets
[
expectedBracketIndex
]
:
null
;
for
(
let
lineNumber
=
1
;
lineNumber
<=
contents
.
length
;
lineNumber
++
)
{
let
lineText
=
contents
[
lineNumber
-
1
];
for
(
let
column
=
1
;
column
<=
lineText
.
length
+
1
;
column
++
)
{
if
(
currentExpectedBracket
)
{
if
(
lineNumber
===
currentExpectedBracket
.
range
.
startLineNumber
&&
column
>
currentExpectedBracket
.
range
.
startColumn
)
{
expectedBracketIndex
++
;
currentExpectedBracket
=
expectedBracketIndex
<
expectedBrackets
.
length
?
expectedBrackets
[
expectedBracketIndex
]
:
null
;
}
}
let
actual
=
model
.
findNextBracket
({
lineNumber
:
lineNumber
,
column
:
column
});
assert
.
deepEqual
(
toRelaxedFoundBracket
(
actual
),
toRelaxedFoundBracket
(
currentExpectedBracket
),
'
findNextBracket of
'
+
lineNumber
+
'
,
'
+
column
);
}
}
}
model
.
dispose
();
}
test
(
'
brackets
'
,
()
=>
{
testBrackets
([
'
if (a == 3) { return (7 * (a + 5)); }
'
],
[
[
'
{
'
,
'
}
'
],
[
'
[
'
,
'
]
'
],
[
'
(
'
,
'
)
'
]
]);
});
});
src/vs/editor/test/common/model/textModelWithTokens.test.ts
浏览文件 @
668ff04c
...
@@ -10,6 +10,10 @@ import {ViewLineToken} from 'vs/editor/common/core/viewLineToken';
...
@@ -10,6 +10,10 @@ import {ViewLineToken} from 'vs/editor/common/core/viewLineToken';
import
{
ITokenizationSupport
}
from
'
vs/editor/common/modes
'
;
import
{
ITokenizationSupport
}
from
'
vs/editor/common/modes
'
;
import
{
MockMode
}
from
'
vs/editor/test/common/mocks/mockMode
'
;
import
{
MockMode
}
from
'
vs/editor/test/common/mocks/mockMode
'
;
import
{
Token
}
from
'
vs/editor/common/core/token
'
;
import
{
Token
}
from
'
vs/editor/common/core/token
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
IFoundBracket
}
from
'
vs/editor/common/editorCommon
'
;
import
{
TextModel
}
from
'
vs/editor/common/model/textModel
'
;
import
{
TextModelWithTokens
}
from
'
vs/editor/common/model/textModelWithTokens
'
;
suite
(
'
TextModelWithTokens
'
,
()
=>
{
suite
(
'
TextModelWithTokens
'
,
()
=>
{
...
@@ -61,3 +65,122 @@ suite('TextModelWithTokens', () => {
...
@@ -61,3 +65,122 @@ suite('TextModelWithTokens', () => {
});
});
});
});
suite
(
'
TextModelWithTokens
'
,
()
=>
{
function
toRelaxedFoundBracket
(
a
:
IFoundBracket
)
{
if
(
!
a
)
{
return
null
;
}
return
{
range
:
a
.
range
.
toString
(),
open
:
a
.
open
,
close
:
a
.
close
,
isOpen
:
a
.
isOpen
};
}
function
testBrackets
(
contents
:
string
[],
brackets
:
string
[][]):
void
{
let
charIsBracket
:
{[
char
:
string
]:
boolean
}
=
{};
let
charIsOpenBracket
:
{[
char
:
string
]:
boolean
}
=
{};
let
openForChar
:
{[
char
:
string
]:
string
}
=
{};
let
closeForChar
:
{[
char
:
string
]:
string
}
=
{};
brackets
.
forEach
((
b
)
=>
{
charIsBracket
[
b
[
0
]]
=
true
;
charIsBracket
[
b
[
1
]]
=
true
;
charIsOpenBracket
[
b
[
0
]]
=
true
;
charIsOpenBracket
[
b
[
1
]]
=
false
;
openForChar
[
b
[
0
]]
=
b
[
0
];
closeForChar
[
b
[
0
]]
=
b
[
1
];
openForChar
[
b
[
1
]]
=
b
[
0
];
closeForChar
[
b
[
1
]]
=
b
[
1
];
});
let
expectedBrackets
:
IFoundBracket
[]
=
[];
for
(
let
lineIndex
=
0
;
lineIndex
<
contents
.
length
;
lineIndex
++
)
{
let
lineText
=
contents
[
lineIndex
];
for
(
let
charIndex
=
0
;
charIndex
<
lineText
.
length
;
charIndex
++
)
{
let
ch
=
lineText
.
charAt
(
charIndex
);
if
(
charIsBracket
[
ch
])
{
expectedBrackets
.
push
({
open
:
openForChar
[
ch
],
close
:
closeForChar
[
ch
],
isOpen
:
charIsOpenBracket
[
ch
],
range
:
new
Range
(
lineIndex
+
1
,
charIndex
+
1
,
lineIndex
+
1
,
charIndex
+
2
)
});
}
}
}
let
model
=
new
TextModelWithTokens
([],
TextModel
.
toRawText
(
contents
.
join
(
'
\n
'
),
TextModel
.
DEFAULT_CREATION_OPTIONS
),
null
);
// findPrevBracket
{
let
expectedBracketIndex
=
expectedBrackets
.
length
-
1
;
let
currentExpectedBracket
=
expectedBracketIndex
>=
0
?
expectedBrackets
[
expectedBracketIndex
]
:
null
;
for
(
let
lineNumber
=
contents
.
length
;
lineNumber
>=
1
;
lineNumber
--
)
{
let
lineText
=
contents
[
lineNumber
-
1
];
for
(
let
column
=
lineText
.
length
+
1
;
column
>=
1
;
column
--
)
{
if
(
currentExpectedBracket
)
{
if
(
lineNumber
===
currentExpectedBracket
.
range
.
startLineNumber
&&
column
<
currentExpectedBracket
.
range
.
endColumn
)
{
expectedBracketIndex
--
;
currentExpectedBracket
=
expectedBracketIndex
>=
0
?
expectedBrackets
[
expectedBracketIndex
]
:
null
;
}
}
let
actual
=
model
.
findPrevBracket
({
lineNumber
:
lineNumber
,
column
:
column
});
assert
.
deepEqual
(
toRelaxedFoundBracket
(
actual
),
toRelaxedFoundBracket
(
currentExpectedBracket
),
'
findPrevBracket of
'
+
lineNumber
+
'
,
'
+
column
);
}
}
}
// findNextBracket
{
let
expectedBracketIndex
=
0
;
let
currentExpectedBracket
=
expectedBracketIndex
<
expectedBrackets
.
length
?
expectedBrackets
[
expectedBracketIndex
]
:
null
;
for
(
let
lineNumber
=
1
;
lineNumber
<=
contents
.
length
;
lineNumber
++
)
{
let
lineText
=
contents
[
lineNumber
-
1
];
for
(
let
column
=
1
;
column
<=
lineText
.
length
+
1
;
column
++
)
{
if
(
currentExpectedBracket
)
{
if
(
lineNumber
===
currentExpectedBracket
.
range
.
startLineNumber
&&
column
>
currentExpectedBracket
.
range
.
startColumn
)
{
expectedBracketIndex
++
;
currentExpectedBracket
=
expectedBracketIndex
<
expectedBrackets
.
length
?
expectedBrackets
[
expectedBracketIndex
]
:
null
;
}
}
let
actual
=
model
.
findNextBracket
({
lineNumber
:
lineNumber
,
column
:
column
});
assert
.
deepEqual
(
toRelaxedFoundBracket
(
actual
),
toRelaxedFoundBracket
(
currentExpectedBracket
),
'
findNextBracket of
'
+
lineNumber
+
'
,
'
+
column
);
}
}
}
model
.
dispose
();
}
test
(
'
brackets
'
,
()
=>
{
testBrackets
([
'
if (a == 3) { return (7 * (a + 5)); }
'
],
[
[
'
{
'
,
'
}
'
],
[
'
[
'
,
'
]
'
],
[
'
(
'
,
'
)
'
]
]);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录