Skip to content

Commit b414859

Browse files
Converted Startup.js and Startup.vbs into unit tests.
1 parent a17b795 commit b414859

File tree

9 files changed

+256
-134
lines changed

9 files changed

+256
-134
lines changed

ClearScript/V8/V8/V8Patch.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Index: tools/gyp/v8.gyp
22
===================================================================
3-
--- tools/gyp/v8.gyp (revision 13364)
3+
--- tools/gyp/v8.gyp (revision 13474)
44
+++ tools/gyp/v8.gyp (working copy)
55
@@ -32,6 +32,7 @@
66
'targets': [

ClearScriptConsole/ClearScriptConsole.csproj

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
<ItemGroup>
5656
<Compile Include="ClearScriptConsole.cs" />
5757
<Compile Include="Properties\AssemblyInfo.cs" />
58-
<Compile Include="ConsoleTestObject.cs" />
5958
</ItemGroup>
6059
<ItemGroup>
6160
<ProjectReference Include="..\ClearScript\ClearScript.csproj">
@@ -64,14 +63,6 @@
6463
<Private>False</Private>
6564
</ProjectReference>
6665
</ItemGroup>
67-
<ItemGroup>
68-
<Content Include="Startup.js">
69-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
70-
</Content>
71-
<Content Include="Startup.vbs">
72-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
73-
</Content>
74-
</ItemGroup>
7566
<ItemGroup>
7667
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
7768
</ItemGroup>

ClearScriptConsole/Startup.js

Lines changed: 0 additions & 57 deletions
This file was deleted.

ClearScriptConsole/Startup.vbs

Lines changed: 0 additions & 65 deletions
This file was deleted.

ClearScriptTest/ClearScriptTest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<Compile Include="BaseInterfaceMemberAccessTest.cs" />
6060
<Compile Include="BaseMemberAccessTest.cs" />
6161
<Compile Include="ExplicitInterfaceMemberAccessTest.cs" />
62+
<Compile Include="GeneralTestObject.cs" />
6263
<Compile Include="HostVariableTest.cs" />
6364
<Compile Include="IExplicitBaseTestInterface.cs" />
6465
<Compile Include="IBaseTestInterface.cs" />
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464

6565
namespace Microsoft.ClearScript.Test
6666
{
67-
public class ConsoleTestObject
67+
public class GeneralTestObject
6868
{
6969
private string name;
7070
public string Name
@@ -94,7 +94,7 @@ public int Age
9494

9595
public static event EventHandler<StaticEventArgs> StaticChange;
9696

97-
public ConsoleTestObject(string name, int age)
97+
public GeneralTestObject(string name, int age)
9898
{
9999
this.name = name;
100100
this.age = age;

ClearScriptTest/JScriptEngineTest.cs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@
6262
using System;
6363
using System.Collections.Generic;
6464
using System.Diagnostics.CodeAnalysis;
65+
using System.IO;
6566
using System.Linq;
6667
using System.Runtime.InteropServices;
6768
using System.Threading;
69+
using Microsoft.ClearScript.Util;
6870
using Microsoft.ClearScript.Windows;
6971
using Microsoft.VisualStudio.TestTools.UnitTesting;
7072

@@ -491,12 +493,90 @@ public void JScriptEngine_new_NoMatch()
491493
engine.Execute("new System.Random('a')");
492494
}
493495

496+
[TestMethod, TestCategory("JScriptEngine")]
497+
public void JScriptEngine_General()
498+
{
499+
using (var console = new StringWriter())
500+
{
501+
var clr = new HostTypeCollection(type => type != typeof(Console), "mscorlib", "System", "System.Core");
502+
clr.GetNamespaceNode("System").SetPropertyNoCheck("Console", console);
503+
504+
engine.AddHostObject("host", new ExtendedHostFunctions());
505+
engine.AddHostObject("clr", clr);
506+
507+
engine.Execute(generalScript);
508+
Assert.AreEqual(MiscHelpers.FormatCode(generalScriptOutput), console.ToString().Replace("\r\n", "\n"));
509+
}
510+
}
511+
494512
// ReSharper restore InconsistentNaming
495513

496514
#endregion
497515

498516
#region miscellaneous
499517

518+
private const string generalScript =
519+
@"
520+
System = clr.System;
521+
522+
TestObject = host.type('Microsoft.ClearScript.Test.GeneralTestObject', 'ClearScriptTest');
523+
tlist = host.newObj(System.Collections.Generic.List(TestObject));
524+
tlist.Add(host.newObj(TestObject, 'Eóin', 20));
525+
tlist.Add(host.newObj(TestObject, 'Shane', 16));
526+
tlist.Add(host.newObj(TestObject, 'Cillian', 8));
527+
tlist.Add(host.newObj(TestObject, 'Sasha', 6));
528+
tlist.Add(host.newObj(TestObject, 'Brian', 3));
529+
530+
olist = host.newObj(System.Collections.Generic.List(System.Object));
531+
olist.Add({ name: 'Brian', age: 3 });
532+
olist.Add({ name: 'Sasha', age: 6 });
533+
olist.Add({ name: 'Cillian', age: 8 });
534+
olist.Add({ name: 'Shane', age: 16 });
535+
olist.Add({ name: 'Eóin', age: 20 });
536+
537+
dict = host.newObj(System.Collections.Generic.Dictionary(System.String, System.String));
538+
dict.Add('foo', 'bar');
539+
dict.Add('baz', 'qux');
540+
value = host.newVar(System.String);
541+
result = dict.TryGetValue('foo', value.out);
542+
543+
bag = host.newObj();
544+
bag.method = function (x) { System.Console.WriteLine(x * x); };
545+
bag.proc = host.del(System.Action(System.Object), bag.method);
546+
547+
expando = host.newObj(System.Dynamic.ExpandoObject);
548+
expandoCollection = host.cast(System.Collections.Generic.ICollection(System.Collections.Generic.KeyValuePair(System.String, System.Object)), expando);
549+
550+
function onChange(s, e) {
551+
System.Console.WriteLine('Property changed: {0}; new value: {1}', e.PropertyName, s[e.PropertyName]);
552+
};
553+
function onStaticChange(s, e) {
554+
System.Console.WriteLine('Property changed: {0}; new value: {1} (static event)', e.PropertyName, e.PropertyValue);
555+
};
556+
eventCookie = tlist.Item(0).Change.connect(onChange);
557+
staticEventCookie = TestObject.StaticChange.connect(onStaticChange);
558+
tlist.Item(0).Name = 'Jerry';
559+
tlist.Item(1).Name = 'Ellis';
560+
tlist.Item(0).Name = 'Eóin';
561+
tlist.Item(1).Name = 'Shane';
562+
eventCookie.disconnect();
563+
staticEventCookie.disconnect();
564+
tlist.Item(0).Name = 'Jerry';
565+
tlist.Item(1).Name = 'Ellis';
566+
tlist.Item(0).Name = 'Eóin';
567+
tlist.Item(1).Name = 'Shane';
568+
";
569+
570+
private const string generalScriptOutput =
571+
@"
572+
Property changed: Name; new value: Jerry
573+
Property changed: Name; new value: Jerry (static event)
574+
Property changed: Name; new value: Ellis (static event)
575+
Property changed: Name; new value: Eóin
576+
Property changed: Name; new value: Eóin (static event)
577+
Property changed: Name; new value: Shane (static event)
578+
";
579+
500580
// ReSharper disable UnusedMember.Local
501581

502582
private void PrivateMethod()

ClearScriptTest/V8ScriptEngineTest.cs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
using System;
6363
using System.Collections.Generic;
6464
using System.Diagnostics.CodeAnalysis;
65+
using System.IO;
6566
using System.Linq;
6667
using System.Threading;
6768
using Microsoft.ClearScript.Util;
@@ -531,12 +532,90 @@ public void V8ScriptEngine_new_NoMatch()
531532
engine.Execute("new System.Random('a')");
532533
}
533534

535+
[TestMethod, TestCategory("V8ScriptEngine")]
536+
public void V8ScriptEngine_General()
537+
{
538+
using (var console = new StringWriter())
539+
{
540+
var clr = new HostTypeCollection(type => type != typeof(Console), "mscorlib", "System", "System.Core");
541+
clr.GetNamespaceNode("System").SetPropertyNoCheck("Console", console);
542+
543+
engine.AddHostObject("host", new ExtendedHostFunctions());
544+
engine.AddHostObject("clr", clr);
545+
546+
engine.Execute(generalScript);
547+
Assert.AreEqual(MiscHelpers.FormatCode(generalScriptOutput), console.ToString().Replace("\r\n", "\n"));
548+
}
549+
}
550+
534551
// ReSharper restore InconsistentNaming
535552

536553
#endregion
537554

538555
#region miscellaneous
539556

557+
private const string generalScript =
558+
@"
559+
System = clr.System;
560+
561+
TestObject = host.type('Microsoft.ClearScript.Test.GeneralTestObject', 'ClearScriptTest');
562+
tlist = host.newObj(System.Collections.Generic.List(TestObject));
563+
tlist.Add(host.newObj(TestObject, 'Eóin', 20));
564+
tlist.Add(host.newObj(TestObject, 'Shane', 16));
565+
tlist.Add(host.newObj(TestObject, 'Cillian', 8));
566+
tlist.Add(host.newObj(TestObject, 'Sasha', 6));
567+
tlist.Add(host.newObj(TestObject, 'Brian', 3));
568+
569+
olist = host.newObj(System.Collections.Generic.List(System.Object));
570+
olist.Add({ name: 'Brian', age: 3 });
571+
olist.Add({ name: 'Sasha', age: 6 });
572+
olist.Add({ name: 'Cillian', age: 8 });
573+
olist.Add({ name: 'Shane', age: 16 });
574+
olist.Add({ name: 'Eóin', age: 20 });
575+
576+
dict = host.newObj(System.Collections.Generic.Dictionary(System.String, System.String));
577+
dict.Add('foo', 'bar');
578+
dict.Add('baz', 'qux');
579+
value = host.newVar(System.String);
580+
result = dict.TryGetValue('foo', value.out);
581+
582+
bag = host.newObj();
583+
bag.method = function (x) { System.Console.WriteLine(x * x); };
584+
bag.proc = host.del(System.Action(System.Object), bag.method);
585+
586+
expando = host.newObj(System.Dynamic.ExpandoObject);
587+
expandoCollection = host.cast(System.Collections.Generic.ICollection(System.Collections.Generic.KeyValuePair(System.String, System.Object)), expando);
588+
589+
function onChange(s, e) {
590+
System.Console.WriteLine('Property changed: {0}; new value: {1}', e.PropertyName, s[e.PropertyName]);
591+
};
592+
function onStaticChange(s, e) {
593+
System.Console.WriteLine('Property changed: {0}; new value: {1} (static event)', e.PropertyName, e.PropertyValue);
594+
};
595+
eventCookie = tlist.Item(0).Change.connect(onChange);
596+
staticEventCookie = TestObject.StaticChange.connect(onStaticChange);
597+
tlist.Item(0).Name = 'Jerry';
598+
tlist.Item(1).Name = 'Ellis';
599+
tlist.Item(0).Name = 'Eóin';
600+
tlist.Item(1).Name = 'Shane';
601+
eventCookie.disconnect();
602+
staticEventCookie.disconnect();
603+
tlist.Item(0).Name = 'Jerry';
604+
tlist.Item(1).Name = 'Ellis';
605+
tlist.Item(0).Name = 'Eóin';
606+
tlist.Item(1).Name = 'Shane';
607+
";
608+
609+
private const string generalScriptOutput =
610+
@"
611+
Property changed: Name; new value: Jerry
612+
Property changed: Name; new value: Jerry (static event)
613+
Property changed: Name; new value: Ellis (static event)
614+
Property changed: Name; new value: Eóin
615+
Property changed: Name; new value: Eóin (static event)
616+
Property changed: Name; new value: Shane (static event)
617+
";
618+
540619
// ReSharper disable UnusedMember.Local
541620

542621
private void PrivateMethod()

0 commit comments

Comments
 (0)