FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ClearScript/ClearScriptTest/HostVariableTest.cs at master · ClearFoundry/ClearScript · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
ClearFoundry
/
ClearScript
Public
Notifications
You must be signed in to change notification settings
Fork
167
Star
2k
Code
Issues
18
Pull requests
6
Discussions
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
ClearScript
/
ClearScriptTest
/
HostVariableTest.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
149 lines (126 loc) · 5.84 KB
Breadcrumbs
ClearScript
/
ClearScriptTest
/
HostVariableTest.cs
Copy path
File metadata and controls
149 lines (126 loc) · 5.84 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using
System
;
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
HostVariableTest
:
ClearScriptTest
{
#region setup / teardown
private
ScriptEngine
engine
;
[
TestInitialize
]
public
void
TestInitialize
(
)
{
BaseTestInitialize
(
)
;
engine
=
new
V8ScriptEngine
(
V8ScriptEngineFlags
.
EnableDebugging
)
;
engine
.
AddHostObject
(
"clr"
,
HostItemFlags
.
GlobalMembers
,
new
HostTypeCollection
(
"mscorlib"
,
"System"
,
"System.Core"
)
)
;
engine
.
AddHostObject
(
"host"
,
new
HostFunctions
(
)
)
;
}
[
TestCleanup
]
public
void
TestCleanup
(
)
{
engine
.
Dispose
(
)
;
BaseTestCleanup
(
)
;
}
#endregion
#region test methods
// ReSharper disable InconsistentNaming
[
TestMethod
,
TestCategory
(
"HostVariable"
)
]
public
void
HostVariable_out
(
)
{
var
value
=
new
Random
(
)
;
var
dict
=
new
Dictionary
<
string
,
Random
>
{
{
"key"
,
value
}
}
;
engine
.
AddHostObject
(
"dict"
,
dict
)
;
engine
.
Execute
(
"var value = host.newVar(System.Random); var found = dict.TryGetValue('key', value.out); var result = value.value;"
)
;
Assert
.
IsTrue
(
engine
.
Script
.
found
)
;
Assert
.
AreSame
(
value
,
engine
.
Script
.
result
)
;
}
[
TestMethod
,
TestCategory
(
"HostVariable"
)
]
public
void
HostVariable_out_Enum
(
)
{
const
DayOfWeek
value
=
DayOfWeek
.
Wednesday
;
var
dict
=
new
Dictionary
<
string
,
DayOfWeek
>
{
{
"key"
,
value
}
}
;
engine
.
AddHostObject
(
"dict"
,
dict
)
;
engine
.
Execute
(
"var value = host.newVar(System.DayOfWeek); var found = dict.TryGetValue('key', value.out); var result = value.value;"
)
;
Assert
.
IsTrue
(
engine
.
Script
.
found
)
;
Assert
.
AreEqual
(
value
,
engine
.
Script
.
result
)
;
}
[
TestMethod
,
TestCategory
(
"HostVariable"
)
]
public
void
HostVariable_out_Scalar
(
)
{
const
double
value
=
Math
.
E
;
var
dict
=
new
Dictionary
<
string
,
Double
>
{
{
"key"
,
value
}
}
;
engine
.
AddHostObject
(
"dict"
,
dict
)
;
engine
.
Execute
(
"var value = host.newVar(System.Double); var found = dict.TryGetValue('key', value.out); var result = value.value;"
)
;
Assert
.
IsTrue
(
engine
.
Script
.
found
)
;
Assert
.
AreEqual
(
value
,
engine
.
Script
.
result
)
;
}
[
TestMethod
,
TestCategory
(
"HostVariable"
)
]
public
void
HostVariable_out_Struct
(
)
{
var
value
=
DateTime
.
UtcNow
;
var
dict
=
new
Dictionary
<
string
,
DateTime
>
{
{
"key"
,
value
}
}
;
engine
.
AddHostObject
(
"dict"
,
dict
)
;
engine
.
Execute
(
"var value = host.newVar(System.DateTime); var found = dict.TryGetValue('key', value.out); var result = value.value;"
)
;
Assert
.
IsTrue
(
engine
.
Script
.
found
)
;
Assert
.
AreEqual
(
value
,
engine
.
Script
.
result
)
;
}
[
TestMethod
,
TestCategory
(
"HostVariable"
)
]
public
void
HostVariable_ref
(
)
{
var
inputValue
=
new
Random
(
)
;
engine
.
AddHostObject
(
"test"
,
this
)
;
engine
.
AddHostObject
(
"inValue"
,
inputValue
)
;
engine
.
Execute
(
"var value = host.newVar(inValue); var returnValue = test.TestMethod(value.ref); var result = value.value;"
)
;
Assert
.
AreEqual
(
engine
.
Script
.
result
,
default
(
Random
)
)
;
Assert
.
AreSame
(
inputValue
,
engine
.
Script
.
returnValue
)
;
}
[
TestMethod
,
TestCategory
(
"HostVariable"
)
]
public
void
HostVariable_ref_Enum
(
)
{
const
DayOfWeek
inputValue
=
DayOfWeek
.
Thursday
;
engine
.
AddHostObject
(
"test"
,
this
)
;
engine
.
AddHostObject
(
"inValue"
,
inputValue
)
;
engine
.
Execute
(
"var value = host.newVar(inValue); var returnValue = test.TestMethod(value.ref); var result = value.value;"
)
;
Assert
.
AreEqual
(
engine
.
Script
.
result
,
default
(
DayOfWeek
)
)
;
Assert
.
AreEqual
(
inputValue
,
engine
.
Script
.
returnValue
)
;
}
[
TestMethod
,
TestCategory
(
"HostVariable"
)
]
public
void
HostVariable_ref_Scalar
(
)
{
const
double
inputValue
=
Math
.
PI
;
engine
.
AddHostObject
(
"test"
,
this
)
;
engine
.
Script
.
inValue
=
inputValue
;
engine
.
Execute
(
"var value = host.newVar(inValue); var returnValue = test.TestMethod(value.ref); var result = value.value;"
)
;
Assert
.
AreEqual
(
engine
.
Script
.
result
,
default
(
Double
)
)
;
Assert
.
AreEqual
(
inputValue
,
engine
.
Script
.
returnValue
)
;
}
[
TestMethod
,
TestCategory
(
"HostVariable"
)
]
public
void
HostVariable_ref_Struct
(
)
{
var
inputValue
=
DateTime
.
UtcNow
;
engine
.
AddHostObject
(
"test"
,
this
)
;
engine
.
AddHostObject
(
"inValue"
,
inputValue
)
;
engine
.
Execute
(
"var value = host.newVar(inValue); var returnValue = test.TestMethod(value.ref); var result = value.value;"
)
;
Assert
.
AreEqual
(
engine
.
Script
.
result
,
default
(
DateTime
)
)
;
Assert
.
AreEqual
(
inputValue
,
engine
.
Script
.
returnValue
)
;
}
// ReSharper restore InconsistentNaming
#endregion
#region miscellaneous
// ReSharper disable UnusedMember.Local
public
T
TestMethod
<
T
>
(
ref
T
value
,
T
outValue
=
default
)
{
var
inValue
=
value
;
value
=
outValue
;
return
inValue
;
}
// ReSharper restore UnusedMember.Local
#endregion
}
}
Back
|
FazBrowse Home
|
New Git URL