Menu

[r4]: / trunk / JavaScript / UnitTest / ArrayTest.cs  Maximize  Restore  History

Download this file

39 lines (33 with data), 865 Bytes

 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
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
namespace JavaScript.UnitTest
{
[TestFixture]
public class ArrayTest
{
[Test]
public void DimConstructor()
{
Assert.AreEqual("5", Exec("var x = new Array(5);x.length;"), "length should be 5");
Assert.AreEqual("undefined", Exec("var x = new Array(5);x[0];"), "elements are undefined");
}
[Test]
public void VarDecTest()
{
Assert.AreEqual("5", Exec("var x = [1,2,3,4,5]; x.length;"), "length should be 5");
Assert.AreEqual("5", Exec("var x = [1,2,3,4,5]; x[4];"), "5th Element");
}
private string Exec(string src)
{
JsEngine eng = new JsEngine();
return Exec(src, eng);
}
private string Exec(string src, JsEngine eng)
{
JsObject o = eng.Eval(src, 1);
return o.ToString();
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.