Skip to content
This repository was archived by the owner on Sep 9, 2019. It is now read-only.

Commit baea547

Browse files
committed
Rewrite test suite to work with XP7
. Refrain from using lang.types . Use util.cmd.Console instead of util.cmd.Command (moved to xp-framework/command) . Use util.Bytes from 6.11
1 parent 0b235ae commit baea547

10 files changed

+49
-59
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"description" : "XP Compiler",
77
"keywords": ["xp"],
88
"require" : {
9-
"xp-framework/core": "^7.0 | ^6.5",
9+
"xp-framework/core": "^7.0 | ^6.11",
1010
"xp-framework/parser": "^7.0 | ^6.0",
1111
"xp-framework/tokenize": "^7.0 | ^6.6",
1212
"xp-framework/patterns": "^7.0 | ^6.6",

src/test/php/net/xp_lang/tests/checks/ArrayAccessVerificationTest.class.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ public function string() {
7272
}
7373

7474
#[@test]
75-
public function arrayList() {
75+
public function arrayObject() {
7676
$this->assertNull(
77-
$this->verify(new InstanceCreationNode(['type' => new TypeName('lang.types.ArrayList')]))
77+
$this->verify(new InstanceCreationNode(['type' => new TypeName('php.ArrayObject')]))
7878
);
7979
}
8080

src/test/php/net/xp_lang/tests/checks/MemberAccessVerificationTest.class.php

-7
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,6 @@ public function thisPrivateMemberAccess() {
100100
);
101101
}
102102

103-
#[@test]
104-
public function integerPublicMemberAccess() {
105-
$this->assertNull(
106-
$this->verify(new MemberAccessNode($this->newInstance('lang.types.Integer'), 'value'))
107-
);
108-
}
109-
110103
#[@test]
111104
public function stringProtectedMemberAccess() {
112105
$this->assertEquals(

src/test/php/net/xp_lang/tests/compilation/PropertiesTest.class.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ public function property_with_set() {
103103
public function property_with_get_and_set_exists() {
104104
$this->assertEquals(
105105
true,
106-
$this->compile('class %s { public lang.types.Bytes buffer { get; set; } }')->hasProperty('buffer')
106+
$this->compile('class %s { public util.Bytes buffer { get; set; } }')->hasProperty('buffer')
107107
);
108108
}
109109

110110
#[@test]
111111
public function property_with_get_and_set() {
112112
$this->assertProperty(
113-
MODIFIER_PUBLIC, 'buffer', new TypeName('lang.types.Bytes'),
114-
$this->compile('class %s { public lang.types.Bytes buffer { get; set; } }')->getProperty('buffer')
113+
MODIFIER_PUBLIC, 'buffer', new TypeName('util.Bytes'),
114+
$this->compile('class %s { public util.Bytes buffer { get; set; } }')->getProperty('buffer')
115115
);
116116
}
117117

src/test/php/net/xp_lang/tests/execution/source/ClassDeclarationTest.class.php

+6-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use lang\XPClass;
44
use lang\Type;
5-
use lang\types\ArrayList;
5+
use lang\Primitive;
66

77
/**
88
* Tests class declarations
@@ -215,7 +215,7 @@ public function classConstants() {
215215
#[@test]
216216
public function staticMemberInitialization() {
217217
$class= self::define('class', $this->name, null, '{
218-
public static XPClass $arrayClass = lang.types.ArrayList::class;
218+
public static XPClass $arrayClass = lang.Type::class;
219219
}');
220220
$this->assertInstanceOf(XPClass::class, $class->getField('arrayClass')->get(null));
221221
}
@@ -227,13 +227,9 @@ public function staticMemberInitialization() {
227227
#[@test]
228228
public function memberInitialization() {
229229
$class= self::define('class', $this->name, null, '{
230-
public lang.types.ArrayList $elements = lang.types.ArrayList::class.newInstance(1, 2, 3);
230+
public lang.Type $type = lang.Type::forName("string");
231231
}');
232-
233-
with ($instance= $class->newInstance(), $elements= $class->getField('elements')->get($instance)); {
234-
$this->assertInstanceOf(ArrayList::class, $elements);
235-
$this->assertEquals(new ArrayList(1, 2, 3), $elements);
236-
}
232+
$this->assertEquals(Primitive::$STRING, $class->getField('type')->get($class->newInstance()));
237233
}
238234

239235
/**
@@ -243,15 +239,9 @@ public function memberInitialization() {
243239
#[@test]
244240
public function memberInitializationWithParent() {
245241
$class= self::define('class', $this->name, 'unittest.TestCase', '{
246-
public lang.types.ArrayList $elements = lang.types.ArrayList::class.newInstance(1, 2, 3);
242+
public lang.Type $type = lang.Type::forName("string");
247243
}');
248-
249-
with ($instance= $class->newInstance($this->name)); {
250-
$this->assertEquals($this->name, $instance->getName());
251-
$elements= $class->getField('elements')->get($instance);
252-
$this->assertInstanceOf(ArrayList::class, $elements);
253-
$this->assertEquals(new ArrayList(1, 2, 3), $elements);
254-
}
244+
$this->assertEquals(Primitive::$STRING, $class->getField('type')->get($class->newInstance('test')));
255245
}
256246

257247
/**

src/test/php/net/xp_lang/tests/execution/source/InstanceCreationTest.class.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,19 @@ public function two_anonymous_interface_instances() {
107107

108108
#[@test]
109109
public function anonymous_instance_from_abstract_base_class() {
110-
$command= $this->run('return new util.cmd.Command() {
110+
\lang\ClassLoader::defineType('net.xp_lang.tests.Command', [
111+
'kind' => 'abstract class',
112+
'extends' => ['lang.Object'],
113+
'implements' => ['lang.Runnable'],
114+
'use' => []
115+
], []);
116+
117+
$command= $this->run('return new net.xp_lang.tests.Command() {
111118
public void run() {
112119
throw new lang.MethodNotImplementedException("run");
113120
}
114121
};');
115-
$this->assertAnonymousInstanceOf('util.cmd.Command', $command);
122+
$this->assertAnonymousInstanceOf('net.xp_lang.tests.Command', $command);
116123
}
117124

118125
#[@test]

src/test/php/net/xp_lang/tests/execution/source/NavigationOperatorTest.class.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ public function method_call_on_self() {
2727

2828
#[@test]
2929
public function method_call_on_null_member() {
30-
$this->assertNull($this->run('$i= new self() { lang.types.Integer $member= null; }; return $i?.member?.intValue();'));
30+
$this->assertNull($this->run('$i= new self() { util.Bytes $member= null; }; return $i?.member?.size();'));
3131
}
3232

3333
#[@test]
3434
public function method_call_on_member() {
35-
$this->assertEquals(1, $this->run('$i= new self() { lang.types.Integer $member= new lang.types.Integer(1); }; return $i?.member?.intValue();'));
35+
$this->assertEquals(1, $this->run('$i= new self() { util.Bytes $member= new util.Bytes([1]); }; return $i?.member?.size();'));
3636
}
3737
}

src/test/php/net/xp_lang/tests/types/ArraySortingExtensions.class.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ class ArraySortingExtensions extends \lang\Object {
1111
/**
1212
* Returns a sorted array list
1313
*
14-
* @param lang.types.ArrayList self
15-
* @return lang.types.ArrayList
14+
* @param var[] self
15+
* @return var[]
1616
*/
17-
public static function sorted(\lang\types\ArrayList $self) {
17+
public static function sorted(array $self) {
1818
// Implementation here
1919
}
2020
}

src/test/php/net/xp_lang/tests/types/ScopeTest.class.php

+21-21
Original file line numberDiff line numberDiff line change
@@ -203,43 +203,43 @@ public function importNonExistantPackage() {
203203
#[@test]
204204
public function resolveFullyQualified() {
205205
$this->assertEquals(
206-
new TypeReflection(XPClass::forName('util.cmd.Command')),
207-
$this->fixture->resolveType(new TypeName('util.cmd.Command'))
206+
new TypeReflection(XPClass::forName('util.cmd.Console')),
207+
$this->fixture->resolveType(new TypeName('util.cmd.Console'))
208208
);
209209
}
210210

211211
#[@test]
212212
public function resolveUnqualified() {
213-
$this->fixture->addTypeImport('util.cmd.Command');
213+
$this->fixture->addTypeImport('util.cmd.Console');
214214
$this->assertEquals(
215-
new TypeReflection(XPClass::forName('util.cmd.Command')),
216-
$this->fixture->resolveType(new TypeName('Command'))
215+
new TypeReflection(XPClass::forName('util.cmd.Console')),
216+
$this->fixture->resolveType(new TypeName('Console'))
217217
);
218218
}
219219

220220
#[@test]
221221
public function resolveUnqualifiedByPackageImport() {
222222
$this->fixture->addPackageImport('util.cmd');
223223
$this->assertEquals(
224-
new TypeReflection(XPClass::forName('util.cmd.Command')),
225-
$this->fixture->resolveType(new TypeName('Command'))
224+
new TypeReflection(XPClass::forName('util.cmd.Console')),
225+
$this->fixture->resolveType(new TypeName('Console'))
226226
);
227227
}
228228

229229
#[@test]
230230
public function resolveArrayType() {
231231
$this->assertEquals(
232-
new TypeReference(new TypeName('util.cmd.Command[]'), Types::CLASS_KIND),
233-
$this->fixture->resolveType(new TypeName('util.cmd.Command[]'))
232+
new TypeReference(new TypeName('util.cmd.Console[]'), Types::CLASS_KIND),
233+
$this->fixture->resolveType(new TypeName('util.cmd.Console[]'))
234234
);
235235
}
236236

237237
#[@test]
238238
public function resolveUnqualifiedArrayType() {
239239
$this->fixture->addPackageImport('util.cmd');
240240
$this->assertEquals(
241-
new TypeReference(new TypeName('util.cmd.Command[]'), Types::CLASS_KIND),
242-
$this->fixture->resolveType(new TypeName('Command[]'))
241+
new TypeReference(new TypeName('util.cmd.Console[]'), Types::CLASS_KIND),
242+
$this->fixture->resolveType(new TypeName('Console[]'))
243243
);
244244
}
245245

@@ -278,32 +278,32 @@ public function usedAfterPackageImport() {
278278
#[@test]
279279
public function usedAfterPackageAndTypeImport() {
280280
$this->fixture->addPackageImport('util.cmd');
281-
$this->fixture->resolveType(new TypeName('Command'));
281+
$this->fixture->resolveType(new TypeName('Console'));
282282

283-
$this->assertEquals(['util.cmd.Command' => true], $this->fixture->used);
283+
$this->assertEquals(['util.cmd.Console' => true], $this->fixture->used);
284284
}
285285

286286
#[@test]
287287
public function usedAfterPackageAndMultipleTypeImport() {
288288
$this->fixture->addPackageImport('util.cmd');
289-
$this->fixture->resolveType(new TypeName('Command'));
290-
$this->fixture->resolveType(new TypeName('Command'));
289+
$this->fixture->resolveType(new TypeName('Console'));
290+
$this->fixture->resolveType(new TypeName('Console'));
291291

292-
$this->assertEquals(['util.cmd.Command' => true], $this->fixture->used);
292+
$this->assertEquals(['util.cmd.Console' => true], $this->fixture->used);
293293
}
294294

295295
#[@test]
296296
public function usedAfterTypeImport() {
297-
$this->fixture->addTypeImport('util.cmd.Command');
297+
$this->fixture->addTypeImport('util.cmd.Console');
298298

299-
$this->assertEquals(['util.cmd.Command' => true], $this->fixture->used);
299+
$this->assertEquals(['util.cmd.Console' => true], $this->fixture->used);
300300
}
301301

302302
#[@test]
303303
public function usedAfterMultipleTypeImport() {
304-
$this->fixture->addTypeImport('util.cmd.Command');
305-
$this->fixture->addTypeImport('util.cmd.Command');
304+
$this->fixture->addTypeImport('util.cmd.Console');
305+
$this->fixture->addTypeImport('util.cmd.Console');
306306

307-
$this->assertEquals(['util.cmd.Command' => true], $this->fixture->used);
307+
$this->assertEquals(['util.cmd.Console' => true], $this->fixture->used);
308308
}
309309
}

src/test/php/net/xp_lang/tests/types/TypeReflectionTest.class.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ public function objectClassIsNotEnumerable() {
168168

169169
#[@test]
170170
public function arrayListClassEnumerator() {
171-
$enum= (new TypeReflection(XPClass::forName('lang.types.ArrayList')))->getEnumerator();
172-
$this->assertEquals(new TypeName('int'), $enum->key);
171+
$enum= (new TypeReflection(new XPClass(\ArrayObject::class)))->getEnumerator();
172+
$this->assertEquals(new TypeName('var'), $enum->key);
173173
$this->assertEquals(new TypeName('var'), $enum->value);
174174
}
175175

0 commit comments

Comments
 (0)