|
@@ -594,9 +594,9 @@ namespace Jint.Tests.Runtime
|
|
[Fact]
|
|
[Fact]
|
|
public void ShouldNotExecuteDebuggerStatement()
|
|
public void ShouldNotExecuteDebuggerStatement()
|
|
{
|
|
{
|
|
- new Engine().Execute("debugger");
|
|
|
|
|
|
+ new Engine().Execute("debugger");
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
[Fact]
|
|
[Fact]
|
|
public void ShouldThrowStatementCountOverflow()
|
|
public void ShouldThrowStatementCountOverflow()
|
|
{
|
|
{
|
|
@@ -609,7 +609,7 @@ namespace Jint.Tests.Runtime
|
|
public void ShouldThrowTimeout()
|
|
public void ShouldThrowTimeout()
|
|
{
|
|
{
|
|
Assert.Throws<TimeoutException>(
|
|
Assert.Throws<TimeoutException>(
|
|
- () => new Engine(cfg => cfg.TimeoutInterval(new TimeSpan(0,0,0,0,500))).Execute("while(true);")
|
|
|
|
|
|
+ () => new Engine(cfg => cfg.TimeoutInterval(new TimeSpan(0, 0, 0, 0, 500))).Execute("while(true);")
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -658,7 +658,7 @@ namespace Jint.Tests.Runtime
|
|
assert(regex.test('a/b') === true);
|
|
assert(regex.test('a/b') === true);
|
|
assert(regex.test('a\\/b') === false);
|
|
assert(regex.test('a\\/b') === false);
|
|
");
|
|
");
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
[Fact]
|
|
[Fact]
|
|
public void ShouldComputeFractionInBase()
|
|
public void ShouldComputeFractionInBase()
|
|
@@ -708,45 +708,37 @@ namespace Jint.Tests.Runtime
|
|
[Fact]
|
|
[Fact]
|
|
public void JsonParserShouldParseNegativeNumber()
|
|
public void JsonParserShouldParseNegativeNumber()
|
|
{
|
|
{
|
|
- var engine = new Engine();
|
|
|
|
- var result = engine.Execute(@"JSON.parse('{ ""x"":-1 }').x === -1").GetCompletionValue().AsBoolean();
|
|
|
|
- Assert.Equal(true, result);
|
|
|
|
|
|
+ RunTest(@"
|
|
|
|
+ var a = JSON.parse('{ ""x"":-1 }');
|
|
|
|
+ assert(a.x === -1);
|
|
|
|
|
|
- result = engine.Execute(@"JSON.parse('{ ""x"": -1 }').x === -1").GetCompletionValue().AsBoolean();
|
|
|
|
- Assert.Equal(true, result);
|
|
|
|
|
|
+ var b = JSON.parse('{ ""x"": -1 }');
|
|
|
|
+ assert(b.x === -1);
|
|
|
|
+ ");
|
|
}
|
|
}
|
|
|
|
|
|
[Fact]
|
|
[Fact]
|
|
public void JsonParserShouldDetectInvalidNegativeNumberSyntax()
|
|
public void JsonParserShouldDetectInvalidNegativeNumberSyntax()
|
|
{
|
|
{
|
|
- var engine = new Engine();
|
|
|
|
- var code = @"
|
|
|
|
- function f() {
|
|
|
|
- try {
|
|
|
|
- JSON.parse('{ ""x"": -.1 }'); // Not allowed
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- catch(ex) {
|
|
|
|
- return ex.toString().indexOf('Unexpected token') !== -1;
|
|
|
|
- }
|
|
|
|
|
|
+ RunTest(@"
|
|
|
|
+ try {
|
|
|
|
+ JSON.parse('{ ""x"": -.1 }'); // Not allowed
|
|
|
|
+ assert(false);
|
|
|
|
+ }
|
|
|
|
+ catch(ex) {
|
|
|
|
+ assert(ex instanceof SyntaxError);
|
|
}
|
|
}
|
|
- f();
|
|
|
|
- ";
|
|
|
|
- Assert.True(engine.Execute(code).GetCompletionValue().AsBoolean());
|
|
|
|
|
|
+ ");
|
|
|
|
|
|
- code = @"
|
|
|
|
- function f() {
|
|
|
|
- try {
|
|
|
|
- JSON.parse('{ ""x"": - 1 }'); // Not allowed
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- catch(ex) {
|
|
|
|
- return ex.toString().indexOf('Unexpected token') !== -1;
|
|
|
|
- }
|
|
|
|
|
|
+ RunTest(@"
|
|
|
|
+ try {
|
|
|
|
+ JSON.parse('{ ""x"": - 1 }'); // Not allowed
|
|
|
|
+ assert(false);
|
|
|
|
+ }
|
|
|
|
+ catch(ex) {
|
|
|
|
+ assert(ex instanceof SyntaxError);
|
|
}
|
|
}
|
|
- f();
|
|
|
|
- ";
|
|
|
|
- Assert.True(engine.Execute(code).GetCompletionValue().AsBoolean());
|
|
|
|
|
|
+ ");
|
|
}
|
|
}
|
|
|
|
|
|
[Fact]
|
|
[Fact]
|
|
@@ -756,7 +748,7 @@ namespace Jint.Tests.Runtime
|
|
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("fr-FR");
|
|
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("fr-FR");
|
|
|
|
|
|
var engine = new Engine();
|
|
var engine = new Engine();
|
|
-
|
|
|
|
|
|
+
|
|
var result = engine.Execute("1.2 + 2.1").GetCompletionValue().AsNumber();
|
|
var result = engine.Execute("1.2 + 2.1").GetCompletionValue().AsNumber();
|
|
Assert.Equal(3.3d, result);
|
|
Assert.Equal(3.3d, result);
|
|
|
|
|
|
@@ -804,7 +796,7 @@ namespace Jint.Tests.Runtime
|
|
{
|
|
{
|
|
const string customName = "Custom Time";
|
|
const string customName = "Custom Time";
|
|
var customTimeZone = TimeZoneInfo.CreateCustomTimeZone(customName, new TimeSpan(7, 11, 0), customName, customName, customName, null, false);
|
|
var customTimeZone = TimeZoneInfo.CreateCustomTimeZone(customName, new TimeSpan(7, 11, 0), customName, customName, customName, null, false);
|
|
- var engine = new Engine(cfg => cfg.LocalTimeZone(customTimeZone));
|
|
|
|
|
|
+ var engine = new Engine(cfg => cfg.LocalTimeZone(customTimeZone));
|
|
|
|
|
|
var result = engine.Execute("Date.UTC(1970,0,1)").GetCompletionValue().AsNumber();
|
|
var result = engine.Execute("Date.UTC(1970,0,1)").GetCompletionValue().AsNumber();
|
|
Assert.Equal(0, result);
|
|
Assert.Equal(0, result);
|
|
@@ -905,7 +897,7 @@ namespace Jint.Tests.Runtime
|
|
{
|
|
{
|
|
var url = "http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/2.0.0/handlebars.js";
|
|
var url = "http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/2.0.0/handlebars.js";
|
|
var content = new WebClient().DownloadString(url);
|
|
var content = new WebClient().DownloadString(url);
|
|
-
|
|
|
|
|
|
+
|
|
RunTest(content);
|
|
RunTest(content);
|
|
|
|
|
|
RunTest(@"
|
|
RunTest(@"
|
|
@@ -917,5 +909,14 @@ namespace Jint.Tests.Runtime
|
|
assert('Hello Paul' == html);
|
|
assert('Hello Paul' == html);
|
|
");
|
|
");
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ [Fact]
|
|
|
|
+ public void DateParseReturnsNaN()
|
|
|
|
+ {
|
|
|
|
+ RunTest(@"
|
|
|
|
+ var d = Date.parse('not a date');
|
|
|
|
+ assert(isNaN(d));
|
|
|
|
+ ");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|