forked from Taritsyn/JavaScriptEngineSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommonTests.cs
More file actions
90 lines (74 loc) · 1.67 KB
/
CommonTests.cs
File metadata and controls
90 lines (74 loc) · 1.67 KB
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
#if !NETCOREAPP1_0
using Xunit;
using JavaScriptEngineSwitcher.Core;
namespace JavaScriptEngineSwitcher.Tests.Jurassic
{
public class CommonTests : CommonTestsBase
{
protected override string EngineName
{
get { return "JurassicJsEngine"; }
}
#region Mapping errors
[Fact]
public override void MappingRuntimeErrorDuringEvaluationOfExpressionIsCorrect()
{
// Arrange
const string input = @"var $variable1 = 611;
var _variable2 = 711;
var @variable3 = 678;
$variable1 + _variable2 - variable3;";
JsRuntimeException exception = null;
// Act
using (var jsEngine = CreateJsEngine())
{
try
{
int result = jsEngine.Evaluate<int>(input);
}
catch (JsRuntimeException e)
{
exception = e;
}
}
// Assert
Assert.NotNull(exception);
Assert.NotEmpty(exception.Message);
Assert.Equal(3, exception.LineNumber);
Assert.Equal(0, exception.ColumnNumber);
}
public override void MappingRuntimeErrorDuringExecutionOfCodeIsCorrect()
{
// Arrange
const string input = @"function factorial(value) {
if (value <= 0) {
throw new Error(""The value must be greater than or equal to zero."");
}
return value !== 1 ? value * factorial(value - 1) : 1;
}
factorial(5);
factorial(@);
factorial(0);";
JsRuntimeException exception = null;
// Act
using (var jsEngine = CreateJsEngine())
{
try
{
jsEngine.Execute(input);
}
catch (JsRuntimeException e)
{
exception = e;
}
}
// Assert
Assert.NotNull(exception);
Assert.NotEmpty(exception.Message);
Assert.Equal(10, exception.LineNumber);
Assert.Equal(0, exception.ColumnNumber);
}
#endregion
}
}
#endif