ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / src / vs / editor / contrib / find / test / browser / replacePattern.test.ts 255 строк · изменён 14 нояб., 04:52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import assert from 'assert' ;
import { buildReplaceStringWithCasePreserved } from '../../../../../base/common/search.js' ;
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js' ;
import { parseReplaceString, ReplacePattern, ReplacePiece } from '../../browser/replacePattern.js' ;
suite ( 'Replace Pattern test' , ( ) => {
ensureNoDisposablesAreLeakedInTestSuite ( ) ;
test ( 'parse replace string' , ( ) => {
const testParse input expectedPieces ReplacePiece
actual input
expected expectedPieces
assert actual expected input
ReplacePiece
ReplacePiece
ReplacePiece
ReplacePiece
ReplacePiece
ReplacePiece
ReplacePiece
ReplacePiece
ReplacePiece
ReplacePiece
ReplacePiece
ReplacePiece
ReplacePiece
ReplacePiece ReplacePiece
ReplacePiece ReplacePiece
ReplacePiece ReplacePiece ReplacePiece
ReplacePiece ReplacePiece
ReplacePiece ReplacePiece
ReplacePiece ReplacePiece
ReplacePiece ReplacePiece
ReplacePiece ReplacePiece
ReplacePiece ReplacePiece
ReplacePiece ReplacePiece ReplacePiece
ReplacePiece ReplacePiece ReplacePiece
ReplacePiece ReplacePiece ReplacePiece
ReplacePiece ReplacePiece ReplacePiece
ReplacePiece ReplacePiece ReplacePiece
ReplacePiece
ReplacePiece
ReplacePiece
ReplacePiece
input expectedPieces ReplacePiece
actual input
expected expectedPieces
assert actual expected input
target search RegExp replaceString expected
replacePattern replaceString
m search target
actual replacePattern m
assert actual expected
ReplacePiece ReplacePiece
ReplacePiece ReplacePiece
ReplacePiece ReplacePiece
ReplacePiece ReplacePiece
ReplacePiece ReplacePiece ReplacePiece ReplacePiece
target search RegExp replaceString expected
replacePattern replaceString
m search target
actual replacePattern m
assert actual expected
target search RegExp replaceString expected
replacePattern replaceString
m search target
actual replacePattern m
assert actual expected
searchRegex
searchRegex
searchRegex
searchRegex
searchRegex
searchRegex
searchRegex
target search RegExp replaceString expected
replacePattern replaceString
m search target
actual replacePattern m
assert actual expected
replacePattern
matches
actual replacePattern matches
assert actual
target replaceString expected
actual
actual target replaceString
assert actual expected
target replaceString expected
replacePattern replaceString
actual replacePattern target
assert actual expected
=
(
:
string
,
:
[
]
)
=>
{
const
=
parseReplaceString
(
)
;
const
=
new
ReplacePattern
(
)
;
.
deepStrictEqual
(
,
,
'Parsing '
+
)
;
}
;
testParse
(
'hello'
,
[
.
staticValue
(
'hello'
)
]
)
;
testParse
(
'\\thello'
,
[
.
staticValue
(
'\thello'
)
]
)
;
testParse
(
'h\\tello'
,
[
.
staticValue
(
'h\tello'
)
]
)
;
testParse
(
'hello\\t'
,
[
.
staticValue
(
'hello\t'
)
]
)
;
testParse
(
'\\nhello'
,
[
.
staticValue
(
'\nhello'
)
]
)
;
testParse
(
'\\\\thello'
,
[
.
staticValue
(
'\\thello'
)
]
)
;
testParse
(
'h\\\\tello'
,
[
.
staticValue
(
'h\\tello'
)
]
)
;
testParse
(
'hello\\\\t'
,
[
.
staticValue
(
'hello\\t'
)
]
)
;
testParse
(
'\\\\\\thello'
,
[
.
staticValue
(
'\\\thello'
)
]
)
;
testParse
(
'\\\\\\\\thello'
,
[
.
staticValue
(
'\\\\thello'
)
]
)
;
testParse
(
'hello\\'
,
[
.
staticValue
(
'hello\\'
)
]
)
;
testParse
(
'hello\\x'
,
[
.
staticValue
(
'hello\\x'
)
]
)
;
testParse
(
'hello\\0'
,
[
.
staticValue
(
'hello\\0'
)
]
)
;
testParse
(
'hello$&'
,
[
.
staticValue
(
'hello'
)
,
.
matchIndex
(
0
)
]
)
;
testParse
(
'hello$0'
,
[
.
staticValue
(
'hello'
)
,
.
matchIndex
(
0
)
]
)
;
testParse
(
'hello$02'
,
[
.
staticValue
(
'hello'
)
,
.
matchIndex
(
0
)
,
.
staticValue
(
'2'
)
]
)
;
testParse
(
'hello$1'
,
[
.
staticValue
(
'hello'
)
,
.
matchIndex
(
1
)
]
)
;
testParse
(
'hello$2'
,
[
.
staticValue
(
'hello'
)
,
.
matchIndex
(
2
)
]
)
;
testParse
(
'hello$9'
,
[
.
staticValue
(
'hello'
)
,
.
matchIndex
(
9
)
]
)
;
testParse
(
'$9hello'
,
[
.
matchIndex
(
9
)
,
.
staticValue
(
'hello'
)
]
)
;
testParse
(
'hello$12'
,
[
.
staticValue
(
'hello'
)
,
.
matchIndex
(
12
)
]
)
;
testParse
(
'hello$99'
,
[
.
staticValue
(
'hello'
)
,
.
matchIndex
(
99
)
]
)
;
testParse
(
'hello$99a'
,
[
.
staticValue
(
'hello'
)
,
.
matchIndex
(
99
)
,
.
staticValue
(
'a'
)
]
)
;
testParse
(
'hello$1a'
,
[
.
staticValue
(
'hello'
)
,
.
matchIndex
(
1
)
,
.
staticValue
(
'a'
)
]
)
;
testParse
(
'hello$100'
,
[
.
staticValue
(
'hello'
)
,
.
matchIndex
(
10
)
,
.
staticValue
(
'0'
)
]
)
;
testParse
(
'hello$100a'
,
[
.
staticValue
(
'hello'
)
,
.
matchIndex
(
10
)
,
.
staticValue
(
'0a'
)
]
)
;
testParse
(
'hello$10a0'
,
[
.
staticValue
(
'hello'
)
,
.
matchIndex
(
10
)
,
.
staticValue
(
'a0'
)
]
)
;
testParse
(
'hello$$'
,
[
.
staticValue
(
'hello$'
)
]
)
;
testParse
(
'hello$$0'
,
[
.
staticValue
(
'hello$0'
)
]
)
;
testParse
(
'hello$`'
,
[
.
staticValue
(
'hello$`'
)
]
)
;
testParse
(
'hello$\''
,
[
.
staticValue
(
'hello$\''
)
]
)
;
}
)
;
test
(
'parse replace string with case modifiers'
,
(
)
=>
{
const
testParse
=
(
:
string
,
:
[
]
)
=>
{
const
=
parseReplaceString
(
)
;
const
=
new
ReplacePattern
(
)
;
.
deepStrictEqual
(
,
,
'Parsing '
+
)
;
}
;
function
assertReplace
(
:
string
,
:
,
:
string
,
:
string
)
:
void
{
const
=
parseReplaceString
(
)
;
const
=
.
exec
(
)
;
const
=
.
buildReplaceString
(
)
;
.
strictEqual
(
,
,
` ${ target} .replace( ${ search} , ${ replaceString} ) === ${ expected} `
)
;
}
testParse
(
'hello\\U$1'
,
[
.
staticValue
(
'hello'
)
,
.
caseOps
(
1
,
[
'U'
]
)
]
)
;
assertReplace
(
'func privateFunc('
,
/ func ( \w + ) \( /
,
'func \\U$1('
,
'func PRIVATEFUNC('
)
;
testParse
(
'hello\\u$1'
,
[
.
staticValue
(
'hello'
)
,
.
caseOps
(
1
,
[
'u'
]
)
]
)
;
assertReplace
(
'func privateFunc('
,
/ func ( \w + ) \( /
,
'func \\u$1('
,
'func PrivateFunc('
)
;
testParse
(
'hello\\L$1'
,
[
.
staticValue
(
'hello'
)
,
.
caseOps
(
1
,
[
'L'
]
)
]
)
;
assertReplace
(
'func privateFunc('
,
/ func ( \w + ) \( /
,
'func \\L$1('
,
'func privatefunc('
)
;
testParse
(
'hello\\l$1'
,
[
.
staticValue
(
'hello'
)
,
.
caseOps
(
1
,
[
'l'
]
)
]
)
;
assertReplace
(
'func PrivateFunc('
,
/ func ( \w + ) \( /
,
'func \\l$1('
,
'func privateFunc('
)
;
testParse
(
'hello$1\\u\\u\\U$4goodbye'
,
[
.
staticValue
(
'hello'
)
,
.
matchIndex
(
1
)
,
.
caseOps
(
4
,
[
'u'
,
'u'
,
'U'
]
)
,
.
staticValue
(
'goodbye'
)
]
)
;
assertReplace
(
'hellogooDbye'
,
/ hello( \w + ) /
,
'hello\\u\\u\\l\\l\\U$1'
,
'helloGOodBYE'
)
;
}
)
;
test
(
'replace has JavaScript semantics'
,
(
)
=>
{
const
testJSReplaceSemantics
=
(
:
string
,
:
,
:
string
,
:
string
)
=>
{
const
=
parseReplaceString
(
)
;
const
=
.
exec
(
)
;
const
=
.
buildReplaceString
(
)
;
.
deepStrictEqual
(
,
,
` ${ target} .replace( ${ search} , ${ replaceString} ) `
)
;
}
;
testJSReplaceSemantics
(
'hi'
,
/ hi /
,
'hello'
,
'hi'
.
replace
(
/ hi /
,
'hello'
)
)
;
testJSReplaceSemantics
(
'hi'
,
/ hi /
,
'\\t'
,
'hi'
.
replace
(
/ hi /
,
'\t'
)
)
;
testJSReplaceSemantics
(
'hi'
,
/ hi /
,
'\\n'
,
'hi'
.
replace
(
/ hi /
,
'\n'
)
)
;
testJSReplaceSemantics
(
'hi'
,
/ hi /
,
'\\\\t'
,
'hi'
.
replace
(
/ hi /
,
'\\t'
)
)
;
testJSReplaceSemantics
(
'hi'
,
/ hi /
,
'\\\\n'
,
'hi'
.
replace
(
/ hi /
,
'\\n'
)
)
;
testJSReplaceSemantics
(
'hi'
,
/ hi /
,
'hello$&'
,
'hi'
.
replace
(
/ hi /
,
'hello$&'
)
)
;
testJSReplaceSemantics
(
'hi'
,
/ hi /
,
'hello$0'
,
'hi'
.
replace
(
/ hi /
,
'hello$&'
)
)
;
testJSReplaceSemantics
(
'hi'
,
/ hi /
,
'hello$&1'
,
'hi'
.
replace
(
/ hi /
,
'hello$&1'
)
)
;
testJSReplaceSemantics
(
'hi'
,
/ hi /
,
'hello$01'
,
'hi'
.
replace
(
/ hi /
,
'hello$&1'
)
)
;
testJSReplaceSemantics
(
'hi'
,
/ ( hi) /
,
'hello$10'
,
'hi'
.
replace
(
/ ( hi) /
,
'hello$10'
)
)
;
testJSReplaceSemantics
(
'hi'
,
/ ( hi) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) /
,
'hello$10'
,
'hi'
.
replace
(
/ ( hi) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) /
,
'hello$10'
)
)
;
testJSReplaceSemantics
(
'hi'
,
/ ( hi) /
,
'hello$100'
,
'hi'
.
replace
(
/ ( hi) /
,
'hello$100'
)
)
;
testJSReplaceSemantics
(
'hi'
,
/ ( hi) /
,
'hello$20'
,
'hi'
.
replace
(
/ ( hi) /
,
'hello$20'
)
)
;
}
)
;
test
(
'get replace string if given text is a complete match'
,
(
)
=>
{
function
assertReplace
(
:
string
,
:
,
:
string
,
:
string
)
:
void
{
const
=
parseReplaceString
(
)
;
const
=
.
exec
(
)
;
const
=
.
buildReplaceString
(
)
;
.
strictEqual
(
,
,
` ${ target} .replace( ${ search} , ${ replaceString} ) === ${ expected} `
)
;
}
assertReplace
(
'bla'
,
/ bla /
,
'hello'
,
'hello'
)
;
assertReplace
(
'bla'
,
/ ( bla) /
,
'hello'
,
'hello'
)
;
assertReplace
(
'bla'
,
/ ( bla) /
,
'hello$0'
,
'hellobla'
)
;
const
=
/ let\s + ( \w + ) \s * =\s * require\s * \( \s * [ '"] ( [ \w \. \- /] + ) \s * [ '"] \s * \) \s * /
;
assertReplace
(
'let fs = require(\'fs\')'
,
,
'import * as $1 from \'$2\';'
,
'import * as fs from \'fs\';'
)
;
assertReplace
(
'let something = require(\'fs\')'
,
,
'import * as $1 from \'$2\';'
,
'import * as something from \'fs\';'
)
;
assertReplace
(
'let something = require(\'fs\')'
,
,
'import * as $1 from \'$1\';'
,
'import * as something from \'something\';'
)
;
assertReplace
(
'let something = require(\'fs\')'
,
,
'import * as $2 from \'$1\';'
,
'import * as fs from \'something\';'
)
;
assertReplace
(
'let something = require(\'fs\')'
,
,
'import * as $0 from \'$0\';'
,
'import * as let something = require(\'fs\') from \'let something = require(\'fs\')\';'
)
;
assertReplace
(
'let fs = require(\'fs\')'
,
,
'import * as $1 from \'$2\';'
,
'import * as fs from \'fs\';'
)
;
assertReplace
(
'for ()'
,
/ for( . * ) /
,
'cat$1'
,
'cat ()'
)
;
assertReplace
(
'HRESULT OnAmbientPropertyChange(DISPID dispid);'
,
/ \b \s {3} \b /
,
' '
,
' '
)
;
}
)
;
test
(
'get replace string if match is sub-string of the text'
,
(
)
=>
{
function
assertReplace
(
:
string
,
:
,
:
string
,
:
string
)
:
void
{
const
=
parseReplaceString
(
)
;
const
=
.
exec
(
)
;
const
=
.
buildReplaceString
(
)
;
.
strictEqual
(
,
,
` ${ target} .replace( ${ search} , ${ replaceString} ) === ${ expected} `
)
;
}
assertReplace
(
'this is a bla text'
,
/ bla /
,
'hello'
,
'hello'
)
;
assertReplace
(
'this is a bla text'
,
/ this(?= . * bla) /
,
'that'
,
'that'
)
;
assertReplace
(
'this is a bla text'
,
/ ( th) is(?= . * bla) /
,
'$1at'
,
'that'
)
;
assertReplace
(
'this is a bla text'
,
/ ( th) is(?= . * bla) /
,
'$1e'
,
'the'
)
;
assertReplace
(
'this is a bla text'
,
/ ( th) is(?= . * bla) /
,
'$1ere'
,
'there'
)
;
assertReplace
(
'this is a bla text'
,
/ ( th) is(?= . * bla) /
,
'$1'
,
'th'
)
;
assertReplace
(
'this is a bla text'
,
/ ( th) is(?= . * bla) /
,
'ma$1'
,
'math'
)
;
assertReplace
(
'this is a bla text'
,
/ ( th) is(?= . * bla) /
,
'ma$1s'
,
'maths'
)
;
assertReplace
(
'this is a bla text'
,
/ ( th) is(?= . * bla) /
,
'$0'
,
'this'
)
;
assertReplace
(
'this is a bla text'
,
/ ( th) is(?= . * bla) /
,
'$0$1'
,
'thisth'
)
;
assertReplace
(
'this is a bla text'
,
/ bla(?= \s text$ ) /
,
'foo'
,
'foo'
)
;
assertReplace
(
'this is a bla text'
,
/ b( la) (?= \s text$ ) /
,
'f$1'
,
'fla'
)
;
assertReplace
(
'this is a bla text'
,
/ b( la) (?= \s text$ ) /
,
'f$0'
,
'fbla'
)
;
assertReplace
(
'this is a bla text'
,
/ b( la) (?= \s text$ ) /
,
'$0ah'
,
'blaah'
)
;
}
)
;
test
(
'issue #19740 Find and replace capture group/backreference inserts `undefined` instead of empty string'
,
(
)
=>
{
const
=
parseReplaceString
(
'a{$1}'
)
;
const
=
/ a( z) ? /
.
exec
(
'abcd'
)
;
const
=
.
buildReplaceString
(
)
;
.
strictEqual
(
,
'a{}'
)
;
}
)
;
test
(
'buildReplaceStringWithCasePreserved test'
,
(
)
=>
{
function
assertReplace
(
:
string
[
]
,
:
string
,
:
string
)
:
void
{
let
:
string
=
''
;
=
buildReplaceStringWithCasePreserved
(
,
)
;
.
strictEqual
(
,
)
;
}
assertReplace
(
[
'abc'
]
,
'Def'
,
'def'
)
;
assertReplace
(
[
'Abc'
]
,
'Def'
,
'Def'
)
;
assertReplace
(
[
'ABC'
]
,
'Def'
,
'DEF'
)
;
assertReplace
(
[
'abc'
,
'Abc'
]
,
'Def'
,
'def'
)
;
assertReplace
(
[
'Abc'
,
'abc'
]
,
'Def'
,
'Def'
)
;
assertReplace
(
[
'ABC'
,
'abc'
]
,
'Def'
,
'DEF'
)
;
assertReplace
(
[
'aBc'
,
'abc'
]
,
'Def'
,
'def'
)
;
assertReplace
(
[
'AbC'
]
,
'Def'
,
'Def'
)
;
assertReplace
(
[
'aBC'
]
,
'Def'
,
'def'
)
;
assertReplace
(
[
'aBc'
]
,
'DeF'
,
'deF'
)
;
assertReplace
(
[
'Foo-Bar'
]
,
'newfoo-newbar'
,
'Newfoo-Newbar'
)
;
assertReplace
(
[
'Foo-Bar-Abc'
]
,
'newfoo-newbar-newabc'
,
'Newfoo-Newbar-Newabc'
)
;
assertReplace
(
[
'Foo-Bar-abc'
]
,
'newfoo-newbar'
,
'Newfoo-newbar'
)
;
assertReplace
(
[
'foo-Bar'
]
,
'newfoo-newbar'
,
'newfoo-Newbar'
)
;
assertReplace
(
[
'foo-BAR'
]
,
'newfoo-newbar'
,
'newfoo-NEWBAR'
)
;
assertReplace
(
[
'foO-BAR'
]
,
'NewFoo-NewBar'
,
'newFoo-NEWBAR'
)
;
assertReplace
(
[
'Foo_Bar'
]
,
'newfoo_newbar'
,
'Newfoo_Newbar'
)
;
assertReplace
(
[
'Foo_Bar_Abc'
]
,
'newfoo_newbar_newabc'
,
'Newfoo_Newbar_Newabc'
)
;
assertReplace
(
[
'Foo_Bar_abc'
]
,
'newfoo_newbar'
,
'Newfoo_newbar'
)
;
assertReplace
(
[
'Foo_Bar-abc'
]
,
'newfoo_newbar-abc'
,
'Newfoo_newbar-abc'
)
;
assertReplace
(
[
'foo_Bar'
]
,
'newfoo_newbar'
,
'newfoo_Newbar'
)
;
assertReplace
(
[
'Foo_BAR'
]
,
'newfoo_newbar'
,
'Newfoo_NEWBAR'
)
;
}
)
;
test
(
'preserve case'
,
(
)
=>
{
function
assertReplace
(
:
string
[
]
,
:
string
,
:
string
)
:
void
{
const
=
parseReplaceString
(
)
;
const
=
.
buildReplaceString
(
,
true
)
;
.
strictEqual
(
,
)
;
}
assertReplace
(
[
'abc'
]
,
'Def'
,
'def'
)
;
assertReplace
(
[
'Abc'
]
,
'Def'
,
'Def'
)
;
assertReplace
(
[
'ABC'
]
,
'Def'
,
'DEF'
)
;
assertReplace
(
[
'abc'
,
'Abc'
]
,
'Def'
,
'def'
)
;
assertReplace
(
[
'Abc'
,
'abc'
]
,
'Def'
,
'Def'
)
;
assertReplace
(
[
'ABC'
,
'abc'
]
,
'Def'
,
'DEF'
)
;
assertReplace
(
[
'aBc'
,
'abc'
]
,
'Def'
,
'def'
)
;
assertReplace
(
[
'AbC'
]
,
'Def'
,
'Def'
)
;
assertReplace
(
[
'aBC'
]
,
'Def'
,
'def'
)
;
assertReplace
(
[
'aBc'
]
,
'DeF'
,
'deF'
)
;
assertReplace
(
[
'Foo-Bar'
]
,
'newfoo-newbar'
,
'Newfoo-Newbar'
)
;
assertReplace
(
[
'Foo-Bar-Abc'
]
,
'newfoo-newbar-newabc'
,
'Newfoo-Newbar-Newabc'
)
;
assertReplace
(
[
'Foo-Bar-abc'
]
,
'newfoo-newbar'
,
'Newfoo-newbar'
)
;
assertReplace
(
[
'foo-Bar'
]
,
'newfoo-newbar'
,
'newfoo-Newbar'
)
;
assertReplace
(
[
'foo-BAR'
]
,
'newfoo-newbar'
,
'newfoo-NEWBAR'
)
;
assertReplace
(
[
'foO-BAR'
]
,
'NewFoo-NewBar'
,
'newFoo-NEWBAR'
)
;
assertReplace
(
[
'Foo_Bar'
]
,
'newfoo_newbar'
,
'Newfoo_Newbar'
)
;
assertReplace
(
[
'Foo_Bar_Abc'
]
,
'newfoo_newbar_newabc'
,
'Newfoo_Newbar_Newabc'
)
;
assertReplace
(
[
'Foo_Bar_abc'
]
,
'newfoo_newbar'
,
'Newfoo_newbar'
)
;
assertReplace
(
[
'Foo_Bar-abc'
]
,
'newfoo_newbar-abc'
,
'Newfoo_newbar-abc'
)
;
assertReplace
(
[
'foo_Bar'
]
,
'newfoo_newbar'
,
'newfoo_Newbar'
)
;
assertReplace
(
[
'foo_BAR'
]
,
'newfoo_newbar'
,
'newfoo_NEWBAR'
)
;
}
)
;
}
)
;