FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ClearScript/ClearScriptTest/HostListTest.cs at master · PascalMing/ClearScript · GitHub
PascalMing
/
ClearScript
Public
forked from
ClearFoundry/ClearScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
ClearScript
/
ClearScriptTest
/
HostListTest.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
355 lines (289 loc) · 11.9 KB
Breadcrumbs
ClearScript
/
ClearScriptTest
/
HostListTest.cs
Copy path
File metadata and controls
355 lines (289 loc) · 11.9 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using
System
;
using
System
.
Collections
;
using
System
.
Collections
.
Generic
;
using
System
.
Diagnostics
.
CodeAnalysis
;
using
Microsoft
.
ClearScript
.
V8
;
using
Microsoft
.
VisualStudio
.
TestTools
.
UnitTesting
;
namespace
Microsoft
.
ClearScript
.
Test
{
[
TestClass
]
[
SuppressMessage
(
"Microsoft.Design"
,
"CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable"
,
Justification
=
"Test classes use TestCleanupAttribute for deterministic teardown."
)
]
public
class
HostListTest
:
ClearScriptTest
{
#region setup / teardown
private
ScriptEngine
engine
;
[
TestInitialize
]
public
void
TestInitialize
(
)
{
engine
=
new
V8ScriptEngine
(
V8ScriptEngineFlags
.
EnableDebugging
)
;
}
[
TestCleanup
]
public
void
TestCleanup
(
)
{
engine
.
Dispose
(
)
;
BaseTestCleanup
(
)
;
}
#endregion
#region test methods
// ReSharper disable InconsistentNaming
[
TestMethod
,
TestCategory
(
"HostList"
)
]
public
void
HostList_ArrayList
(
)
{
var
list
=
new
ArrayList
{
DayOfWeek
.
Monday
,
DayOfWeek
.
Tuesday
,
DayOfWeek
.
Wednesday
}
;
engine
.
Script
.
list
=
list
;
Assert
.
AreEqual
(
3
,
engine
.
Evaluate
(
"list.Count"
)
)
;
Assert
.
AreEqual
(
DayOfWeek
.
Tuesday
,
engine
.
Evaluate
(
"list[1]"
)
)
;
Assert
.
AreEqual
(
"[HostObject:DayOfWeek]"
,
engine
.
ExecuteCommand
(
"list[2]"
)
)
;
engine
.
Execute
(
"list[1] = list[2]"
)
;
Assert
.
AreEqual
(
DayOfWeek
.
Wednesday
,
engine
.
Evaluate
(
"list[1]"
)
)
;
}
[
TestMethod
,
TestCategory
(
"HostList"
)
]
public
void
HostList_List
(
)
{
var
list
=
new
List
<
IConvertible
>
{
DayOfWeek
.
Monday
,
DayOfWeek
.
Tuesday
,
DayOfWeek
.
Wednesday
}
;
engine
.
Script
.
list
=
list
;
Assert
.
AreEqual
(
3
,
engine
.
Evaluate
(
"list.Count"
)
)
;
Assert
.
AreEqual
(
DayOfWeek
.
Tuesday
,
engine
.
Evaluate
(
"list[1]"
)
)
;
Assert
.
AreEqual
(
"[HostObject:IConvertible]"
,
engine
.
ExecuteCommand
(
"list[2]"
)
)
;
engine
.
Execute
(
"list[1] = list[2]"
)
;
Assert
.
AreEqual
(
DayOfWeek
.
Wednesday
,
engine
.
Evaluate
(
"list[1]"
)
)
;
}
[
TestMethod
,
TestCategory
(
"HostList"
)
]
public
void
HostList_Custom
(
)
{
var
list
=
new
BogusCustomList
{
DayOfWeek
.
Monday
,
DayOfWeek
.
Tuesday
,
DayOfWeek
.
Wednesday
}
;
engine
.
Script
.
list
=
list
;
Assert
.
AreEqual
(
3
,
engine
.
Evaluate
(
"list.Count"
)
)
;
Assert
.
AreEqual
(
DayOfWeek
.
Tuesday
,
engine
.
Evaluate
(
"list[1]"
)
)
;
Assert
.
AreEqual
(
"[HostObject:DayOfWeek]"
,
engine
.
ExecuteCommand
(
"list[2]"
)
)
;
engine
.
Execute
(
"list[1] = list[2]"
)
;
Assert
.
AreEqual
(
DayOfWeek
.
Wednesday
,
engine
.
Evaluate
(
"list[1]"
)
)
;
}
[
TestMethod
,
TestCategory
(
"HostList"
)
]
public
void
HostList_CustomGeneric
(
)
{
var
list
=
new
BogusCustomList
<
IConvertible
>
{
DayOfWeek
.
Monday
,
DayOfWeek
.
Tuesday
,
DayOfWeek
.
Wednesday
}
;
engine
.
Script
.
list
=
list
;
Assert
.
AreEqual
(
3
,
engine
.
Evaluate
(
"list.Count"
)
)
;
Assert
.
AreEqual
(
DayOfWeek
.
Tuesday
,
engine
.
Evaluate
(
"list[1]"
)
)
;
Assert
.
AreEqual
(
"[HostObject:IConvertible]"
,
engine
.
ExecuteCommand
(
"list[2]"
)
)
;
engine
.
Execute
(
"list[1] = list[2]"
)
;
Assert
.
AreEqual
(
DayOfWeek
.
Wednesday
,
engine
.
Evaluate
(
"list[1]"
)
)
;
}
[
TestMethod
,
TestCategory
(
"HostList"
)
]
public
void
HostList_TypeRestriction
(
)
{
var
list
=
new
List
<
IConvertible
>
{
DayOfWeek
.
Monday
,
DayOfWeek
.
Tuesday
,
DayOfWeek
.
Wednesday
}
;
engine
.
Script
.
list
=
list
;
Assert
.
AreEqual
(
3
,
engine
.
Evaluate
(
"list.Count"
)
)
;
Assert
.
AreEqual
(
"[HostObject:IConvertible]"
,
engine
.
ExecuteCommand
(
"list[2]"
)
)
;
Assert
.
AreEqual
(
"[HostObject:IConvertible]"
,
engine
.
ExecuteCommand
(
"list.Item(2)"
)
)
;
engine
.
DisableListIndexTypeRestriction
=
true
;
Assert
.
AreEqual
(
"[HostObject:DayOfWeek]"
,
engine
.
ExecuteCommand
(
"list[2]"
)
)
;
Assert
.
AreEqual
(
"[HostObject:IConvertible]"
,
engine
.
ExecuteCommand
(
"list.Item(2)"
)
)
;
engine
.
DisableListIndexTypeRestriction
=
false
;
Assert
.
AreEqual
(
"[HostObject:IConvertible]"
,
engine
.
ExecuteCommand
(
"list[2]"
)
)
;
Assert
.
AreEqual
(
"[HostObject:IConvertible]"
,
engine
.
ExecuteCommand
(
"list.Item(2)"
)
)
;
engine
.
DisableTypeRestriction
=
true
;
Assert
.
AreEqual
(
"[HostObject:DayOfWeek]"
,
engine
.
ExecuteCommand
(
"list[2]"
)
)
;
Assert
.
AreEqual
(
"[HostObject:DayOfWeek]"
,
engine
.
ExecuteCommand
(
"list.Item(2)"
)
)
;
}
[
TestMethod
,
TestCategory
(
"ReadOnlyHostList"
)
]
public
void
ReadOnlyHostList_List
(
)
{
IReadOnlyList
<
IConvertible
>
list
=
new
List
<
IConvertible
>
{
DayOfWeek
.
Monday
,
DayOfWeek
.
Tuesday
,
DayOfWeek
.
Wednesday
}
;
engine
.
AddRestrictedHostObject
(
"list"
,
list
)
;
Assert
.
AreEqual
(
3
,
engine
.
Evaluate
(
"list.Count"
)
)
;
Assert
.
AreEqual
(
DayOfWeek
.
Tuesday
,
engine
.
Evaluate
(
"list[1]"
)
)
;
Assert
.
AreEqual
(
"[HostObject:IConvertible]"
,
engine
.
ExecuteCommand
(
"list[2]"
)
)
;
TestUtil
.
AssertException
<
UnauthorizedAccessException
>
(
(
)
=>
engine
.
Execute
(
"list[1] = list[2]"
)
)
;
}
[
TestMethod
,
TestCategory
(
"ReadOnlyHostList"
)
]
public
void
ReadOnlyHostList_Custom
(
)
{
var
list
=
new
BogusReadOnlyCustomList
<
IConvertible
>
(
DayOfWeek
.
Monday
,
DayOfWeek
.
Tuesday
,
DayOfWeek
.
Wednesday
)
;
engine
.
Script
.
list
=
list
;
Assert
.
AreEqual
(
3
,
engine
.
Evaluate
(
"list.Count"
)
)
;
Assert
.
AreEqual
(
DayOfWeek
.
Tuesday
,
engine
.
Evaluate
(
"list[1]"
)
)
;
Assert
.
AreEqual
(
"[HostObject:IConvertible]"
,
engine
.
ExecuteCommand
(
"list[2]"
)
)
;
TestUtil
.
AssertException
<
UnauthorizedAccessException
>
(
(
)
=>
engine
.
Execute
(
"list[1] = list[2]"
)
)
;
}
[
TestMethod
,
TestCategory
(
"ReadOnlyHostList"
)
]
public
void
ReadOnlyHostList_TypeRestriction
(
)
{
var
list
=
new
BogusReadOnlyCustomList
<
IConvertible
>
(
DayOfWeek
.
Monday
,
DayOfWeek
.
Tuesday
,
DayOfWeek
.
Wednesday
)
;
engine
.
Script
.
list
=
list
;
Assert
.
AreEqual
(
3
,
engine
.
Evaluate
(
"list.Count"
)
)
;
Assert
.
AreEqual
(
"[HostObject:IConvertible]"
,
engine
.
ExecuteCommand
(
"list[2]"
)
)
;
Assert
.
AreEqual
(
"[HostObject:IConvertible]"
,
engine
.
ExecuteCommand
(
"list.Item(2)"
)
)
;
engine
.
DisableListIndexTypeRestriction
=
true
;
Assert
.
AreEqual
(
"[HostObject:DayOfWeek]"
,
engine
.
ExecuteCommand
(
"list[2]"
)
)
;
Assert
.
AreEqual
(
"[HostObject:IConvertible]"
,
engine
.
ExecuteCommand
(
"list.Item(2)"
)
)
;
engine
.
DisableListIndexTypeRestriction
=
false
;
Assert
.
AreEqual
(
"[HostObject:IConvertible]"
,
engine
.
ExecuteCommand
(
"list[2]"
)
)
;
Assert
.
AreEqual
(
"[HostObject:IConvertible]"
,
engine
.
ExecuteCommand
(
"list.Item(2)"
)
)
;
engine
.
DisableTypeRestriction
=
true
;
Assert
.
AreEqual
(
"[HostObject:DayOfWeek]"
,
engine
.
ExecuteCommand
(
"list[2]"
)
)
;
Assert
.
AreEqual
(
"[HostObject:DayOfWeek]"
,
engine
.
ExecuteCommand
(
"list.Item(2)"
)
)
;
}
// ReSharper restore InconsistentNaming
#endregion
#region miscellaneous
public
interface
IBogus
{
}
public
interface
ICustomList
:
IList
{
}
public
interface
ICustomList
<
T
>
:
IList
<
T
>
{
}
public
interface
IReadOnlyCustomList
<
out
T
>
:
IReadOnlyList
<
T
>
{
}
public
interface
IBogusCustomList
:
IBogus
,
ICustomList
{
}
public
interface
IBogusCustomList
<
T
>
:
IBogus
,
ICustomList
<
T
>
{
}
public
interface
IBogusReadOnlyCustomList
<
out
T
>
:
IBogus
,
IReadOnlyCustomList
<
T
>
{
}
public
class
BogusCustomListBase
:
IBogusCustomList
{
private
readonly
IList
list
=
new
ArrayList
(
)
;
public
IEnumerator
GetEnumerator
(
)
{
return
list
.
GetEnumerator
(
)
;
}
public
void
CopyTo
(
Array
array
,
int
index
)
{
list
.
CopyTo
(
array
,
index
)
;
}
public
int
Count
=>
list
.
Count
;
public
object
SyncRoot
=>
list
.
SyncRoot
;
public
bool
IsSynchronized
=>
list
.
IsSynchronized
;
public
int
Add
(
object
value
)
{
return
list
.
Add
(
value
)
;
}
public
bool
Contains
(
object
value
)
{
return
list
.
Contains
(
value
)
;
}
public
void
Clear
(
)
{
list
.
Clear
(
)
;
}
public
int
IndexOf
(
object
value
)
{
return
list
.
IndexOf
(
value
)
;
}
public
void
Insert
(
int
index
,
object
value
)
{
list
.
Insert
(
index
,
value
)
;
}
public
void
Remove
(
object
value
)
{
list
.
Remove
(
value
)
;
}
public
void
RemoveAt
(
int
index
)
{
list
.
RemoveAt
(
index
)
;
}
public
object
this
[
int
index
]
{
get
=>
list
[
index
]
;
set
=>
list
[
index
]
=
value
;
}
public
bool
IsReadOnly
=>
list
.
IsReadOnly
;
public
bool
IsFixedSize
=>
list
.
IsFixedSize
;
}
public
class
BogusCustomListBase
<
T
>
:
IBogusCustomList
<
T
>
{
private
readonly
IList
<
T
>
list
=
new
List
<
T
>
(
)
;
public
IEnumerator
<
T
>
GetEnumerator
(
)
{
return
list
.
GetEnumerator
(
)
;
}
IEnumerator
IEnumerable
.
GetEnumerator
(
)
{
return
GetEnumerator
(
)
;
}
public
void
Add
(
T
item
)
{
list
.
Add
(
item
)
;
}
public
void
Clear
(
)
{
list
.
Clear
(
)
;
}
public
bool
Contains
(
T
item
)
{
return
list
.
Contains
(
item
)
;
}
public
void
CopyTo
(
T
[
]
array
,
int
arrayIndex
)
{
list
.
CopyTo
(
array
,
arrayIndex
)
;
}
public
bool
Remove
(
T
item
)
{
return
list
.
Remove
(
item
)
;
}
public
int
Count
=>
list
.
Count
;
public
bool
IsReadOnly
=>
list
.
IsReadOnly
;
public
int
IndexOf
(
T
item
)
{
return
list
.
IndexOf
(
item
)
;
}
public
void
Insert
(
int
index
,
T
item
)
{
list
.
Insert
(
index
,
item
)
;
}
public
void
RemoveAt
(
int
index
)
{
list
.
RemoveAt
(
index
)
;
}
public
T
this
[
int
index
]
{
get
=>
list
[
index
]
;
set
=>
list
[
index
]
=
value
;
}
}
public
class
BogusReadOnlyCustomListBase
<
T
>
:
IBogusReadOnlyCustomList
<
T
>
{
private
readonly
IReadOnlyList
<
T
>
list
;
public
BogusReadOnlyCustomListBase
(
params
T
[
]
items
)
{
list
=
new
List
<
T
>
(
items
)
;
}
public
IEnumerator
<
T
>
GetEnumerator
(
)
{
return
list
.
GetEnumerator
(
)
;
}
IEnumerator
IEnumerable
.
GetEnumerator
(
)
{
return
GetEnumerator
(
)
;
}
public
int
Count
=>
list
.
Count
;
public
T
this
[
int
index
]
=>
list
[
index
]
;
}
public
class
BogusCustomList
:
BogusCustomListBase
{
}
public
class
BogusCustomList
<
T
>
:
BogusCustomListBase
<
T
>
{
}
public
class
BogusReadOnlyCustomList
<
T
>
:
BogusReadOnlyCustomListBase
<
T
>
{
public
BogusReadOnlyCustomList
(
params
T
[
]
items
)
:
base
(
items
)
{
}
}
#endregion
}
}
Back
|
FazBrowse Home
|
New Git URL