Skip to content

Commit 3fb8b8f

Browse files
Updated JavaScript test files.
1 parent 190210d commit 3fb8b8f

File tree

7 files changed

+143
-3
lines changed

7 files changed

+143
-3
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
System = clr.System;
5+
6+
TestObject = host.type('Microsoft.ClearScript.Test.GeneralTestObject', 'ClearScriptTest');
7+
tlist = host.newObj(System.Collections.Generic.List(TestObject));
8+
tlist.Add(host.newObj(TestObject, 'Eóin', 20));
9+
tlist.Add(host.newObj(TestObject, 'Shane', 16));
10+
tlist.Add(host.newObj(TestObject, 'Cillian', 8));
11+
tlist.Add(host.newObj(TestObject, 'Sasha', 6));
12+
tlist.Add(host.newObj(TestObject, 'Brian', 3));
13+
14+
olist = host.newObj(System.Collections.Generic.List(System.Object));
15+
olist.Add({ name: 'Brian', age: 3 });
16+
olist.Add({ name: 'Sasha', age: 6 });
17+
olist.Add({ name: 'Cillian', age: 8 });
18+
olist.Add({ name: 'Shane', age: 16 });
19+
olist.Add({ name: 'Eóin', age: 20 });
20+
21+
dict = host.newObj(System.Collections.Generic.Dictionary(System.String, System.String));
22+
dict.Add('foo', 'bar');
23+
dict.Add('baz', 'qux');
24+
value = host.newVar(System.String);
25+
result = dict.TryGetValue('foo', value.out);
26+
27+
bag = host.newObj();
28+
bag.method = function (x) { System.Console.WriteLine(x * x); };
29+
bag.proc = host.del(System.Action(System.Object), bag.method);
30+
31+
expando = host.newObj(System.Dynamic.ExpandoObject);
32+
expandoCollection = host.cast(System.Collections.Generic.ICollection(System.Collections.Generic.KeyValuePair(System.String, System.Object)), expando);
33+
34+
function onChange(s, e) {
35+
System.Console.WriteLine('Property changed: {0}; new value: {1}', e.PropertyName, s[e.PropertyName]);
36+
};
37+
function onStaticChange(s, e) {
38+
System.Console.WriteLine('Property changed: {0}; new value: {1} (static event)', e.PropertyName, e.PropertyValue);
39+
};
40+
eventCookie = tlist.Item(0).Change.connect(onChange);
41+
staticEventCookie = TestObject.StaticChange.connect(onStaticChange);
42+
tlist.Item(0).Name = 'Jerry';
43+
tlist.Item(1).Name = 'Ellis';
44+
tlist.Item(0).Name = 'Eóin';
45+
tlist.Item(1).Name = 'Shane';
46+
eventCookie.disconnect();
47+
staticEventCookie.disconnect();
48+
tlist.Item(0).Name = 'Jerry';
49+
tlist.Item(1).Name = 'Ellis';
50+
tlist.Item(0).Name = 'Eóin';
51+
tlist.Item(1).Name = 'Shane';
52+
53+
// ReSharper disable once WrongExpressionStatement
54+
Math.round(Math.sin(Math.PI) * 1000e16);

ClearScriptTest/JavaScript/Geometry/Geometry.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
// Licensed under the MIT license.
33

44
import * as Arithmetic from '../Arithmetic/Arithmetic.js';
5+
import * as Self from 'Geometry.js';
56

67
export class Rectangle {
78
constructor(width, height) {
89
this.width = width;
910
this.height = height;
1011
}
1112
get Area() {
12-
return Arithmetic.Multiply(this.width, this.height);
13+
return Self.Rectangle.CalculateArea(this.width, this.height);
14+
}
15+
static CalculateArea(width, height) {
16+
return Arithmetic.Multiply(width, height);
1317
}
1418
}
1519

ClearScriptTest/JavaScript/Geometry/GeometryWithDynamicImport.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@ let Arithmetic;
77
Arithmetic = await import('../Arithmetic/Arithmetic.js');
88
})();
99

10+
import * as Self from 'Geometry.js';
11+
1012
export class Rectangle {
1113
constructor(width, height) {
1214
this.width = width;
1315
this.height = height;
1416
}
1517
get Area() {
16-
return Arithmetic.Multiply(this.width, this.height);
18+
return Self.Rectangle.CalculateArea(this.width, this.height);
19+
}
20+
static CalculateArea(width, height) {
21+
return Arithmetic.Multiply(width, height);
1722
}
1823
}
1924

ClearScriptTest/JavaScript/Geometry/GeometryWithPathlessImport.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
// Licensed under the MIT license.
33

44
import * as Arithmetic from 'Arithmetic.js';
5+
import * as Self from 'Geometry.js';
56

67
export class Rectangle {
78
constructor(width, height) {
89
this.width = width;
910
this.height = height;
1011
}
1112
get Area() {
12-
return Arithmetic.Multiply(this.width, this.height);
13+
return Self.Rectangle.CalculateArea(this.width, this.height);
14+
}
15+
static CalculateArea(width, height) {
16+
return Arithmetic.Multiply(width, height);
1317
}
1418
}
1519

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
import * as Geometry from 'Geometry/Geometry.js';
5+
6+
// ReSharper disable once WrongExpressionStatement
7+
new Geometry.Square(25).Area;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CLng(Sin(4 * atn(1)) * 1000e16)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
' Copyright (c) Microsoft Corporation. All rights reserved.
2+
' Licensed under the MIT license.
3+
4+
set System = clr.System
5+
6+
set TestObjectT = host.type("Microsoft.ClearScript.Test.GeneralTestObject", "ClearScriptTest")
7+
set tlist = host.newObj(System.Collections.Generic.List(TestObjectT))
8+
call tlist.Add(host.newObj(TestObjectT, "Eóin", 20))
9+
call tlist.Add(host.newObj(TestObjectT, "Shane", 16))
10+
call tlist.Add(host.newObj(TestObjectT, "Cillian", 8))
11+
call tlist.Add(host.newObj(TestObjectT, "Sasha", 6))
12+
call tlist.Add(host.newObj(TestObjectT, "Brian", 3))
13+
14+
class VBTestObject
15+
public name
16+
public age
17+
end class
18+
19+
function createTestObject(name, age)
20+
dim testObject
21+
set testObject = new VBTestObject
22+
testObject.name = name
23+
testObject.age = age
24+
set createTestObject = testObject
25+
end function
26+
27+
set olist = host.newObj(System.Collections.Generic.List(System.Object))
28+
call olist.Add(createTestObject("Brian", 3))
29+
call olist.Add(createTestObject("Sasha", 6))
30+
call olist.Add(createTestObject("Cillian", 8))
31+
call olist.Add(createTestObject("Shane", 16))
32+
call olist.Add(createTestObject("Eóin", 20))
33+
34+
set dict = host.newObj(System.Collections.Generic.Dictionary(System.String, System.String))
35+
call dict.Add("foo", "bar")
36+
call dict.Add("baz", "qux")
37+
set value = host.newVar(System.String)
38+
result = dict.TryGetValue("foo", value.out)
39+
40+
set expando = host.newObj(System.Dynamic.ExpandoObject)
41+
set expandoCollection = host.cast(System.Collections.Generic.ICollection(System.Collections.Generic.KeyValuePair(System.String, System.Object)), expando)
42+
43+
set onEventRef = GetRef("onEvent")
44+
sub onEvent(s, e)
45+
call System.Console.WriteLine("Property changed: {0}; new value: {1}", e.PropertyName, eval("s." + e.PropertyName))
46+
end sub
47+
48+
set onStaticEventRef = GetRef("onStaticEvent")
49+
sub onStaticEvent(s, e)
50+
call System.Console.WriteLine("Property changed: {0}; new value: {1} (static event)", e.PropertyName, e.PropertyValue)
51+
end sub
52+
53+
set eventCookie = tlist.Item(0).Change.connect(onEventRef)
54+
set staticEventCookie = TestObjectT.StaticChange.connect(onStaticEventRef)
55+
tlist.Item(0).Name = "Jerry"
56+
tlist.Item(1).Name = "Ellis"
57+
tlist.Item(0).Name = "Eóin"
58+
tlist.Item(1).Name = "Shane"
59+
60+
call eventCookie.disconnect()
61+
call staticEventCookie.disconnect()
62+
tlist.Item(0).Name = "Jerry"
63+
tlist.Item(1).Name = "Ellis"
64+
tlist.Item(0).Name = "Eóin"
65+
tlist.Item(1).Name = "Shane"

0 commit comments

Comments
 (0)