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

Commit

Permalink
Rewrite test suite to work with XP7
Browse files Browse the repository at this point in the history
. 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
  • Loading branch information
thekid committed Feb 22, 2016
1 parent 0b235ae commit baea547
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 59 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"description" : "XP Compiler",
"keywords": ["xp"],
"require" : {
"xp-framework/core": "^7.0 | ^6.5",
"xp-framework/core": "^7.0 | ^6.11",
"xp-framework/parser": "^7.0 | ^6.0",
"xp-framework/tokenize": "^7.0 | ^6.6",
"xp-framework/patterns": "^7.0 | ^6.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public function string() {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,6 @@ public function thisPrivateMemberAccess() {
);
}

#[@test]
public function integerPublicMemberAccess() {
$this->assertNull(
$this->verify(new MemberAccessNode($this->newInstance('lang.types.Integer'), 'value'))
);
}

#[@test]
public function stringProtectedMemberAccess() {
$this->assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ public function property_with_set() {
public function property_with_get_and_set_exists() {
$this->assertEquals(
true,
$this->compile('class %s { public lang.types.Bytes buffer { get; set; } }')->hasProperty('buffer')
$this->compile('class %s { public util.Bytes buffer { get; set; } }')->hasProperty('buffer')
);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use lang\XPClass;
use lang\Type;
use lang\types\ArrayList;
use lang\Primitive;

/**
* Tests class declarations
Expand Down Expand Up @@ -215,7 +215,7 @@ public function classConstants() {
#[@test]
public function staticMemberInitialization() {
$class= self::define('class', $this->name, null, '{
public static XPClass $arrayClass = lang.types.ArrayList::class;
public static XPClass $arrayClass = lang.Type::class;
}');
$this->assertInstanceOf(XPClass::class, $class->getField('arrayClass')->get(null));
}
Expand All @@ -227,13 +227,9 @@ public function staticMemberInitialization() {
#[@test]
public function memberInitialization() {
$class= self::define('class', $this->name, null, '{
public lang.types.ArrayList $elements = lang.types.ArrayList::class.newInstance(1, 2, 3);
public lang.Type $type = lang.Type::forName("string");
}');

with ($instance= $class->newInstance(), $elements= $class->getField('elements')->get($instance)); {
$this->assertInstanceOf(ArrayList::class, $elements);
$this->assertEquals(new ArrayList(1, 2, 3), $elements);
}
$this->assertEquals(Primitive::$STRING, $class->getField('type')->get($class->newInstance()));
}

/**
Expand All @@ -243,15 +239,9 @@ public function memberInitialization() {
#[@test]
public function memberInitializationWithParent() {
$class= self::define('class', $this->name, 'unittest.TestCase', '{
public lang.types.ArrayList $elements = lang.types.ArrayList::class.newInstance(1, 2, 3);
public lang.Type $type = lang.Type::forName("string");
}');

with ($instance= $class->newInstance($this->name)); {
$this->assertEquals($this->name, $instance->getName());
$elements= $class->getField('elements')->get($instance);
$this->assertInstanceOf(ArrayList::class, $elements);
$this->assertEquals(new ArrayList(1, 2, 3), $elements);
}
$this->assertEquals(Primitive::$STRING, $class->getField('type')->get($class->newInstance('test')));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,19 @@ public function two_anonymous_interface_instances() {

#[@test]
public function anonymous_instance_from_abstract_base_class() {
$command= $this->run('return new util.cmd.Command() {
\lang\ClassLoader::defineType('net.xp_lang.tests.Command', [
'kind' => 'abstract class',
'extends' => ['lang.Object'],
'implements' => ['lang.Runnable'],
'use' => []
], []);

$command= $this->run('return new net.xp_lang.tests.Command() {
public void run() {
throw new lang.MethodNotImplementedException("run");
}
};');
$this->assertAnonymousInstanceOf('util.cmd.Command', $command);
$this->assertAnonymousInstanceOf('net.xp_lang.tests.Command', $command);
}

#[@test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public function method_call_on_self() {

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

#[@test]
public function method_call_on_member() {
$this->assertEquals(1, $this->run('$i= new self() { lang.types.Integer $member= new lang.types.Integer(1); }; return $i?.member?.intValue();'));
$this->assertEquals(1, $this->run('$i= new self() { util.Bytes $member= new util.Bytes([1]); }; return $i?.member?.size();'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class ArraySortingExtensions extends \lang\Object {
/**
* Returns a sorted array list
*
* @param lang.types.ArrayList self
* @return lang.types.ArrayList
* @param var[] self
* @return var[]
*/
public static function sorted(\lang\types\ArrayList $self) {
public static function sorted(array $self) {
// Implementation here
}
}
42 changes: 21 additions & 21 deletions src/test/php/net/xp_lang/tests/types/ScopeTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,43 +203,43 @@ public function importNonExistantPackage() {
#[@test]
public function resolveFullyQualified() {
$this->assertEquals(
new TypeReflection(XPClass::forName('util.cmd.Command')),
$this->fixture->resolveType(new TypeName('util.cmd.Command'))
new TypeReflection(XPClass::forName('util.cmd.Console')),
$this->fixture->resolveType(new TypeName('util.cmd.Console'))
);
}

#[@test]
public function resolveUnqualified() {
$this->fixture->addTypeImport('util.cmd.Command');
$this->fixture->addTypeImport('util.cmd.Console');
$this->assertEquals(
new TypeReflection(XPClass::forName('util.cmd.Command')),
$this->fixture->resolveType(new TypeName('Command'))
new TypeReflection(XPClass::forName('util.cmd.Console')),
$this->fixture->resolveType(new TypeName('Console'))
);
}

#[@test]
public function resolveUnqualifiedByPackageImport() {
$this->fixture->addPackageImport('util.cmd');
$this->assertEquals(
new TypeReflection(XPClass::forName('util.cmd.Command')),
$this->fixture->resolveType(new TypeName('Command'))
new TypeReflection(XPClass::forName('util.cmd.Console')),
$this->fixture->resolveType(new TypeName('Console'))
);
}

#[@test]
public function resolveArrayType() {
$this->assertEquals(
new TypeReference(new TypeName('util.cmd.Command[]'), Types::CLASS_KIND),
$this->fixture->resolveType(new TypeName('util.cmd.Command[]'))
new TypeReference(new TypeName('util.cmd.Console[]'), Types::CLASS_KIND),
$this->fixture->resolveType(new TypeName('util.cmd.Console[]'))
);
}

#[@test]
public function resolveUnqualifiedArrayType() {
$this->fixture->addPackageImport('util.cmd');
$this->assertEquals(
new TypeReference(new TypeName('util.cmd.Command[]'), Types::CLASS_KIND),
$this->fixture->resolveType(new TypeName('Command[]'))
new TypeReference(new TypeName('util.cmd.Console[]'), Types::CLASS_KIND),
$this->fixture->resolveType(new TypeName('Console[]'))
);
}

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

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

#[@test]
public function usedAfterPackageAndMultipleTypeImport() {
$this->fixture->addPackageImport('util.cmd');
$this->fixture->resolveType(new TypeName('Command'));
$this->fixture->resolveType(new TypeName('Command'));
$this->fixture->resolveType(new TypeName('Console'));
$this->fixture->resolveType(new TypeName('Console'));

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

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

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

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

$this->assertEquals(['util.cmd.Command' => true], $this->fixture->used);
$this->assertEquals(['util.cmd.Console' => true], $this->fixture->used);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ public function objectClassIsNotEnumerable() {

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

Expand Down

0 comments on commit baea547

Please sign in to comment.