1
- using Xunit ;
2
-
3
- namespace JavaScriptEngineSwitcher . Tests . Yantra
1
+ namespace JavaScriptEngineSwitcher . Tests . Yantra
4
2
{
5
3
public class Es5Tests : Es5TestsBase
6
4
{
7
5
protected override string EngineName
8
6
{
9
7
get { return "YantraJsEngine" ; }
10
8
}
11
-
12
-
13
- #region Array methods
14
-
15
- [ Fact ]
16
- public override void SupportsArrayIndexOfMethod ( )
17
- {
18
- // Arrange
19
- const string initCode = "var arr = [2, 5, 9, 2]" ;
20
-
21
- const string input1 = "arr.indexOf(2);" ;
22
- const int targetOutput1 = 0 ;
23
-
24
- const string input2 = "arr.indexOf(7);" ;
25
- const int targetOutput2 = - 1 ;
26
-
27
- const string input3 = "arr.indexOf(2, 3)" ;
28
- const int targetOutput3 = 3 ;
29
-
30
- const string input4 = "arr.indexOf(2, 2);" ;
31
- const int targetOutput4 = 3 ;
32
-
33
- const string input5 = "arr.indexOf(2, -2);" ;
34
- #if NET9_0_OR_GREATER
35
- const int targetOutput5 = 0 ;
36
- #else
37
- const int targetOutput5 = 3 ;
38
- #endif
39
-
40
- const string input6 = "arr.indexOf(2, -1);" ;
41
- #if NET9_0_OR_GREATER
42
- const int targetOutput6 = 0 ;
43
- #else
44
- const int targetOutput6 = 3 ;
45
- #endif
46
-
47
- const string input7 = "[].lastIndexOf(2, 0);" ;
48
- const int targetOutput7 = - 1 ;
49
-
50
- // Act
51
- int output1 ;
52
- int output2 ;
53
- int output3 ;
54
- int output4 ;
55
- int output5 ;
56
- int output6 ;
57
- int output7 ;
58
-
59
- using ( var jsEngine = CreateJsEngine ( ) )
60
- {
61
- jsEngine . Execute ( initCode ) ;
62
-
63
- output1 = jsEngine . Evaluate < int > ( input1 ) ;
64
- output2 = jsEngine . Evaluate < int > ( input2 ) ;
65
- output3 = jsEngine . Evaluate < int > ( input3 ) ;
66
- output4 = jsEngine . Evaluate < int > ( input4 ) ;
67
- output5 = jsEngine . Evaluate < int > ( input5 ) ;
68
- output6 = jsEngine . Evaluate < int > ( input6 ) ;
69
- output7 = jsEngine . Evaluate < int > ( input7 ) ;
70
- }
71
-
72
- // Assert
73
- Assert . Equal ( targetOutput1 , output1 ) ;
74
- Assert . Equal ( targetOutput2 , output2 ) ;
75
- Assert . Equal ( targetOutput3 , output3 ) ;
76
- Assert . Equal ( targetOutput4 , output4 ) ;
77
- Assert . Equal ( targetOutput5 , output5 ) ;
78
- Assert . Equal ( targetOutput6 , output6 ) ;
79
- Assert . Equal ( targetOutput7 , output7 ) ;
80
- }
81
-
82
- [ Fact ]
83
- public override void SupportsArrayLastIndexOfMethod ( )
84
- {
85
- // Arrange
86
- const string initCode = "var arr = [2, 5, 9, 2]" ;
87
-
88
- const string input1 = "arr.lastIndexOf(2);" ;
89
- const int targetOutput1 = 3 ;
90
-
91
- const string input2 = "arr.lastIndexOf(7);" ;
92
- const int targetOutput2 = - 1 ;
93
-
94
- const string input3 = "arr.lastIndexOf(2, 3)" ;
95
- const int targetOutput3 = 3 ;
96
-
97
- const string input4 = "arr.lastIndexOf(2, 2);" ;
98
- const int targetOutput4 = 0 ;
99
-
100
- const string input5 = "arr.lastIndexOf(2, -2);" ;
101
- const int targetOutput5 = 0 ;
102
-
103
- const string input6 = "arr.lastIndexOf(2, -1);" ;
104
- #if NET9_0_OR_GREATER
105
- const int targetOutput6 = 0 ;
106
- #else
107
- const int targetOutput6 = 3 ;
108
- #endif
109
-
110
- const string input7 = "[].lastIndexOf(2, 0);" ;
111
- const int targetOutput7 = - 1 ;
112
-
113
- // Act
114
- int output1 ;
115
- int output2 ;
116
- int output3 ;
117
- int output4 ;
118
- int output5 ;
119
- int output6 ;
120
- int output7 ;
121
-
122
- using ( var jsEngine = CreateJsEngine ( ) )
123
- {
124
- jsEngine . Execute ( initCode ) ;
125
-
126
- output1 = jsEngine . Evaluate < int > ( input1 ) ;
127
- output2 = jsEngine . Evaluate < int > ( input2 ) ;
128
- output3 = jsEngine . Evaluate < int > ( input3 ) ;
129
- output4 = jsEngine . Evaluate < int > ( input4 ) ;
130
- output5 = jsEngine . Evaluate < int > ( input5 ) ;
131
- output6 = jsEngine . Evaluate < int > ( input6 ) ;
132
- output7 = jsEngine . Evaluate < int > ( input7 ) ;
133
- }
134
-
135
- // Assert
136
- Assert . Equal ( targetOutput1 , output1 ) ;
137
- Assert . Equal ( targetOutput2 , output2 ) ;
138
- Assert . Equal ( targetOutput3 , output3 ) ;
139
- Assert . Equal ( targetOutput4 , output4 ) ;
140
- Assert . Equal ( targetOutput5 , output5 ) ;
141
- Assert . Equal ( targetOutput6 , output6 ) ;
142
- Assert . Equal ( targetOutput7 , output7 ) ;
143
- }
144
-
145
- #endregion
146
-
147
9
}
148
10
}
0 commit comments