-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy path006_proto.xml
More file actions
170 lines (124 loc) · 3.7 KB
/
006_proto.xml
File metadata and controls
170 lines (124 loc) · 3.7 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?xml version="1.0" encoding="utf-8" ?>
<!--
/*****************************************************************************
*
* ReoScript - .NET Script Language Engine
*
* https://github.com/unvell/ReoScript
*
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
* KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
* PURPOSE.
*
* This software released under MIT license.
* Copyright (c) 2012-2019 Jingwood, unvell.com, all rights reserved.
*
****************************************************************************/
-->
<test-suite id="006" name="proto">
<test-case id="001" name="instance">
<script>
var t = debug.assert;
function A() { }
var a = new A();
t( a.__proto__ == A.prototype );
</script>
</test-case>
<test-case id="002" name="property extension">
<script>
var t = debug.assert;
Array.prototype.reverse = function() {
var rs = [];
for(var i = this.length-1; i >= 0; i--) {
rs.push(this[i]);
}
return rs;
};
var a = [1,2,3].reverse();
t( a[0], 3 );
t( a[1], 2 );
t( a[2], 1 );
</script>
</test-case>
<test-case id="003" name="own property">
<script>
var t = debug.assert;
function A() {
this.funInProto = function() { return "fun in instance"; };
}
var a = new A();
t( a.funInProto() == "fun in instance" );
t( a.hasOwnProperty('funInProto') == true );
t( A.prototype.hasOwnProperty('funInProto') == false);
t( a.hasOwnProperty('hasOwnProperty') == false );
</script>
</test-case>
<test-case id="004" name="string">
<script>
var t = debug.assert;
var str = "hello world";
t( str.hasOwnProperty('trim') == false );
t( str.hasOwnProperty('length') == true );
</script>
</test-case>
<test-case id="005">
<script>
var t = debug.assert;
var str = "hello world";
t( str.fun == null );
String.prototype.fun = function() {};
t( str.fun != null );
t( str.hasOwnProperty('fun') == false );
t( String.prototype.hasOwnProperty('fun') == true );
</script>
</test-case>
<test-case id="006">
<script>
var t = debug.assert;
function A() { }
var a = new A(), b = { };
A.prototype.age = 10;
t( a.age == 10 );
t( a.hasOwnProperty('age') == false );
t( b.age == null );
t( b.hasOwnProperty('age') == false );
</script>
</test-case>
<test-case id="007" name="inherit">
<script>
var t = debug.assert;
var arr = [];
function Super() {
this.run = function() { return 'run'; };
}
function SubClass() {
this.__proto__ = new Super();
this.run2 = function() { return 'run2'; };
}
var sub = new SubClass();
t( sub.run != null );
t( sub.run2 != null );
t( sub.run() == 'run' );
t( sub.run2() == 'run2' );
// override
sub.run = function() { return 'override'; };
t( sub.run() == 'override' );
t( sub.run2() == 'run2' );
</script>
</test-case>
<test-case id="008" name="property in prototype">
<script>
var t = debug.assert;
Array.prototype.aa = 10;
var a = [];
t( a.aa, 10 );
a.aa += 5;
t( Array.prototype.aa, 10 );
t( a.aa, 15 );
Array.prototype.aa = 20;
t( a.aa, 15 );
t( Array.prototype.aa, 20 );
</script>
</test-case>
</test-suite>