Skip to content

Commit

Permalink
Drop support for XP < 9
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Oct 21, 2021
1 parent 46e5751 commit 71788db
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ XP Compiler ChangeLog

## ?.?.? / ????-??-??

## 7.0.0 / 2021-10-21

* Made compatible with XP 11 - @thekid
* Implemented xp-framework/rfc#341, dropping compatibility with XP 9
(@thekid)

## 6.11.0 / 2021-10-06

* Merged PR #125: Support `new T(...)` callable syntax - @thekid
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/Input.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class Input implements \IteratorAggregate {
*/
public static function newInstance($arg) {
if ('-' === $arg) {
return new FromStream(Console::$in->getStream(), '-');
return new FromStream(Console::$in->stream(), '-');
} else if (is_array($arg)) {
return new FromInputs($arg);
} else if (is_file($arg)) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/Output.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static function newInstance($arg) {
if (null === $arg) {
return new CompileOnly();
} else if ('-' === $arg) {
return new ToStream(Console::$out->getStream());
return new ToStream(Console::$out->stream());
} else if (strstr($arg, '.php')) {
return new ToFile($arg);
} else if (strstr($arg, '.xar')) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/php/lang/ast/unittest/cli/InputTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function cleanup() {

#[Test]
public function from_stdin() {
Assert::equals(new FromStream(Console::$in->getStream(), '-'), Input::newInstance('-'));
Assert::equals(new FromStream(Console::$in->stream(), '-'), Input::newInstance('-'));
}

#[Test]
Expand Down
2 changes: 1 addition & 1 deletion src/test/php/lang/ast/unittest/cli/OutputTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function compile_only() {

#[Test]
public function to_stdin() {
Assert::equals(new ToStream(Console::$out->getStream()), Output::newInstance('-'));
Assert::equals(new ToStream(Console::$out->stream()), Output::newInstance('-'));
}

#[Test]
Expand Down
23 changes: 18 additions & 5 deletions src/test/php/lang/ast/unittest/emit/TransformationsTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,18 @@ public function __construct(int $id) {
public function generates_string_representation() {
$t= $this->type('#[Repr] class <T> {
private int $id;
private string $name;
public function __construct(int $id) {
public function __construct(int $id, string $name) {
$this->id= $id;
$this->name= $name;
}
}');
Assert::true($t->hasMethod('toString'));
Assert::equals("T@[\n id => 1\n]", $t->getMethod('toString')->invoke($t->newInstance(1)));
Assert::equals(
"T@[\n id => 1\n name => \"Test\"\n]",
$t->getMethod('toString')->invoke($t->newInstance(1, 'Test'))
);
}

#[Test, Values([['id', 1], ['name', 'Test']])]
Expand All @@ -80,12 +85,20 @@ public function __construct(int $id, string $name) {
public function generates_both() {
$t= $this->type('#[Repr, Getters] class <T> {
private int $id;
private string $name;
public function __construct(int $id) {
public function __construct(int $id, string $name) {
$this->id= $id;
$this->name= $name;
}
}');
Assert::equals(1, $t->getMethod('id')->invoke($t->newInstance(1)));
Assert::equals("T@[\n id => 1\n]", $t->getMethod('toString')->invoke($t->newInstance(1)));

$instance= $t->newInstance(1, 'Test');
Assert::equals(1, $t->getMethod('id')->invoke($instance));
Assert::equals('Test', $t->getMethod('name')->invoke($instance));
Assert::equals(
"T@[\n id => 1\n name => \"Test\"\n]",
$t->getMethod('toString')->invoke($instance)
);
}
}

0 comments on commit 71788db

Please sign in to comment.