Menu

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

Download this file

37 lines (30 with data), 872 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
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
namespace JavaScript.UnitTest
{
[TestFixture]
public class RegExprTest
{
[Test]
public void StringMatchTest()
{
JsEngine eng = new JsEngine();
string src =
"var s = 'bob';\r\n" +
@"m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);";
JsObject obj = eng.Eval(src + "m.length;");
Assert.AreEqual("3", obj.ToString(), "match should be 'bob,bob,'");
obj = eng.Eval(src + "m;");
Assert.AreEqual("bob,bob,", obj.ToString(), "match should be 'bob,bob,'");
}
[Test]
public void Flags()
{
JsEngine eng = new JsEngine();
string src = "'>Mom&'.replace(/>/g,String.fromCharCode(62)).replace(/&/g,String.fromCharCode(38));";
Assert.AreEqual(">Mom&", eng.Eval(src).ToString(), "<Mom&");
}
}
}
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.