From baea547f970b59b2aa7ea61b84b5518ea0d779e6 Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Mon, 22 Feb 2016 01:29:04 +0100 Subject: [PATCH] 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 --- composer.json | 2 +- .../ArrayAccessVerificationTest.class.php | 4 +- .../MemberAccessVerificationTest.class.php | 7 ---- .../compilation/PropertiesTest.class.php | 6 +-- .../source/ClassDeclarationTest.class.php | 22 +++------- .../source/InstanceCreationTest.class.php | 11 ++++- .../source/NavigationOperatorTest.class.php | 4 +- .../types/ArraySortingExtensions.class.php | 6 +-- .../xp_lang/tests/types/ScopeTest.class.php | 42 +++++++++---------- .../tests/types/TypeReflectionTest.class.php | 4 +- 10 files changed, 49 insertions(+), 59 deletions(-) diff --git a/composer.json b/composer.json index d79f240cf..edc0cbdc2 100755 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/test/php/net/xp_lang/tests/checks/ArrayAccessVerificationTest.class.php b/src/test/php/net/xp_lang/tests/checks/ArrayAccessVerificationTest.class.php index d709cd9bb..72241c5f9 100644 --- a/src/test/php/net/xp_lang/tests/checks/ArrayAccessVerificationTest.class.php +++ b/src/test/php/net/xp_lang/tests/checks/ArrayAccessVerificationTest.class.php @@ -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')])) ); } diff --git a/src/test/php/net/xp_lang/tests/checks/MemberAccessVerificationTest.class.php b/src/test/php/net/xp_lang/tests/checks/MemberAccessVerificationTest.class.php index ee95f4837..068831b47 100644 --- a/src/test/php/net/xp_lang/tests/checks/MemberAccessVerificationTest.class.php +++ b/src/test/php/net/xp_lang/tests/checks/MemberAccessVerificationTest.class.php @@ -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( diff --git a/src/test/php/net/xp_lang/tests/compilation/PropertiesTest.class.php b/src/test/php/net/xp_lang/tests/compilation/PropertiesTest.class.php index 0480c73a9..39ab52247 100755 --- a/src/test/php/net/xp_lang/tests/compilation/PropertiesTest.class.php +++ b/src/test/php/net/xp_lang/tests/compilation/PropertiesTest.class.php @@ -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') ); } diff --git a/src/test/php/net/xp_lang/tests/execution/source/ClassDeclarationTest.class.php b/src/test/php/net/xp_lang/tests/execution/source/ClassDeclarationTest.class.php index 1d4497286..54b48372f 100644 --- a/src/test/php/net/xp_lang/tests/execution/source/ClassDeclarationTest.class.php +++ b/src/test/php/net/xp_lang/tests/execution/source/ClassDeclarationTest.class.php @@ -2,7 +2,7 @@ use lang\XPClass; use lang\Type; -use lang\types\ArrayList; +use lang\Primitive; /** * Tests class declarations @@ -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)); } @@ -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())); } /** @@ -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'))); } /** diff --git a/src/test/php/net/xp_lang/tests/execution/source/InstanceCreationTest.class.php b/src/test/php/net/xp_lang/tests/execution/source/InstanceCreationTest.class.php index 569bd66f3..be440f252 100644 --- a/src/test/php/net/xp_lang/tests/execution/source/InstanceCreationTest.class.php +++ b/src/test/php/net/xp_lang/tests/execution/source/InstanceCreationTest.class.php @@ -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] diff --git a/src/test/php/net/xp_lang/tests/execution/source/NavigationOperatorTest.class.php b/src/test/php/net/xp_lang/tests/execution/source/NavigationOperatorTest.class.php index 2dd7dc736..c22432997 100644 --- a/src/test/php/net/xp_lang/tests/execution/source/NavigationOperatorTest.class.php +++ b/src/test/php/net/xp_lang/tests/execution/source/NavigationOperatorTest.class.php @@ -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();')); } } diff --git a/src/test/php/net/xp_lang/tests/types/ArraySortingExtensions.class.php b/src/test/php/net/xp_lang/tests/types/ArraySortingExtensions.class.php index 957c70420..2764fc5bd 100644 --- a/src/test/php/net/xp_lang/tests/types/ArraySortingExtensions.class.php +++ b/src/test/php/net/xp_lang/tests/types/ArraySortingExtensions.class.php @@ -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 } } diff --git a/src/test/php/net/xp_lang/tests/types/ScopeTest.class.php b/src/test/php/net/xp_lang/tests/types/ScopeTest.class.php index 257908f17..c946f473b 100644 --- a/src/test/php/net/xp_lang/tests/types/ScopeTest.class.php +++ b/src/test/php/net/xp_lang/tests/types/ScopeTest.class.php @@ -203,17 +203,17 @@ 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')) ); } @@ -221,16 +221,16 @@ public function resolveUnqualified() { 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[]')) ); } @@ -238,8 +238,8 @@ public function resolveArrayType() { 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[]')) ); } @@ -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); } } \ No newline at end of file diff --git a/src/test/php/net/xp_lang/tests/types/TypeReflectionTest.class.php b/src/test/php/net/xp_lang/tests/types/TypeReflectionTest.class.php index e2bf0e48f..ddbef0fea 100644 --- a/src/test/php/net/xp_lang/tests/types/TypeReflectionTest.class.php +++ b/src/test/php/net/xp_lang/tests/types/TypeReflectionTest.class.php @@ -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); }