Repository navigation
Expand file tree
/
Copy pathASVariableTests.java
More file actions
213 lines (203 loc) · 7.05 KB
/
Copy pathASVariableTests.java
File metadata and controls
213 lines (203 loc) · 7.05 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package as;
import org.junit.Test;
/**
* Feature tests for AS Namespaces.
*/
public class ASVariableTests extends ASFeatureTestsBase
{
@Test
public void ASVariableTests_stringInitializeEmptyString()
{
// all tests can assume that flash.display.Sprite
// flash.system.System and flash.events.Event have been imported
String[] imports = new String[]
{
};
String[] declarations = new String[]
{
"public static const foo:String = ''",
};
String[] testCode = new String[]
{
"assertEqual('empty string', foo, '');",
};
String source = getAS(imports, declarations, testCode, new String[0]);
compileAndRun(source);
}
@Test
public void ASVariableTests_stringInitializeNull()
{
// all tests can assume that flash.display.Sprite
// flash.system.System and flash.events.Event have been imported
String[] imports = new String[]
{
};
String[] declarations = new String[]
{
"public static const foo:String = null",
};
String[] testCode = new String[]
{
"assertEqual('null', foo, null);",
};
String source = getAS(imports, declarations, testCode, new String[0]);
compileAndRun(source);
}
@Test
public void ASVariableTests_stringInitializeUndefined()
{
// all tests can assume that flash.display.Sprite
// flash.system.System and flash.events.Event have been imported
String[] imports = new String[]
{
};
String[] declarations = new String[]
{
"public static const foo:String = undefined",
};
String[] testCode = new String[]
{
"assertEqual('null', foo, null);",
};
String source = getAS(imports, declarations, testCode, new String[0]);
compileAndRun(source);
}
@Test
public void ASVariableTests_AnyInitializeUndefined()
{
// all tests can assume that flash.display.Sprite
// flash.system.System and flash.events.Event have been imported
String[] imports = new String[]
{
};
String[] declarations = new String[]
{
"public static const foo:* = undefined",
};
String[] testCode = new String[]
{
"assertEqual('null', foo, undefined);",
};
String source = getAS(imports, declarations, testCode, new String[0]);
compileAndRun(source);
}
@Test
public void ASVariableTests_localVarSameNameAsPrivateMethodError()
{
// all tests can assume that flash.display.Sprite
// flash.system.System and flash.events.Event have been imported
String[] imports = new String[]
{
};
String[] declarations = new String[]
{
"private function isVertical():Boolean { return false; }",
};
String[] testCode = new String[]
{
// this threw an exception when the generated code
// tried to call the value of the local var.
// mxmlc will generate a call to the method
// without require a this.isVertical to reference
// the instance method.
"var isVertical:Boolean = isVertical();",
"assertEqual('null', isVertical, false);",
};
String source = getAS(imports, declarations, testCode, new String[0]);
compileAndExpectErrors(source, false, false, false, new String[0],
"Call to isVertical is not a function.\n");
}
@Test
public void ASVariableTests_constIsClassCastFunction()
{
// all tests can assume that flash.display.Sprite
// flash.system.System and flash.events.Event have been imported
String[] imports = new String[]
{
};
String[] declarations = new String[]
{
"private const innerClass:InnerClass = null;",
};
String[] testCode = new String[]
{
"if (false) { var test:Object = innerClass('foo')};",
};
String[] extraCode = new String[]
{
"class InnerClass",
"{",
" public function InnerClass(obj:Object)",
" {",
" }",
"}"
};
String source = getAS(imports, declarations, testCode, extraCode);
compileAndRun(source);
}
@Test
public void ASVariableTests_localVarSameNameAsPrivateMethod()
{
// all tests can assume that flash.display.Sprite
// flash.system.System and flash.events.Event have been imported
String[] imports = new String[]
{
};
String[] declarations = new String[]
{
"private function isVertical():Boolean { return false; }",
};
String[] testCode = new String[]
{
// this threw an exception when the generated code
// tried to call the value of the local var.
// mxmlc will generate a call to the method
// without require a this.isVertical to reference
// the instance method.
"var isVertical:Boolean = isVertical();",
"assertEqual('null', isVertical, false);",
};
String source = getAS(imports, declarations, testCode, new String[0]);
compileAndRun(source, false, false, false, new String[]{ "-compiler.mxml.compatibility-version=4.6.0" } );
}
/*
public void ASVariableTests_VectorInitializer()
{
// all tests can assume that flash.display.Sprite
// flash.system.System and flash.events.Event have been imported
String[] imports = new String[]
{
};
String[] declarations = new String[]
{
"public static var arr:Array = Array('foo', 'bar', 'baz');",
"public static var foo:Vector.<String> = new Vector.<String>('foo', 'bar', 'baz');",
"public static var bar:Vector.<String> = Vector.<String>('foo', 'bar', 'baz');",
};
String[] testCode = new String[]
{
"assertEqual('length', foo.length, 3, 4);",
};
String source = getAS(imports, declarations, testCode, new String[0]);
compileAndRun(source);
}
*/
}