Skip to content

Commit

Permalink
Reference lang.ast.unittest.CodeGenTest
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Mar 23, 2024
1 parent 4a9ebbe commit f1bd59e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/php/lang/ast/CodeGen.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use lang\ast\emit\{Reflection, Declaration, Incomplete};

/** @test lang.ast.unittest.CodeGenTest */
class CodeGen {
private $id= 0;
public $scope= [];
Expand Down
62 changes: 62 additions & 0 deletions src/test/php/lang/ast/unittest/CodeGenTest.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php namespace lang\ast\unittest;

use lang\Value;
use lang\ast\CodeGen;
use lang\ast\emit\{Declaration, InType, Reflection, Incomplete};
use lang\ast\nodes\ClassDeclaration;
use lang\ast\types\IsValue;
use test\{Assert, Test};

class CodeGenTest {

#[Test]
public function can_create() {
new CodeGen();
}


#[Test]
public function lookup_self() {
$fixture= new CodeGen();
$context= $fixture->enter(new InType(new ClassDeclaration([], new IsValue('\\T'), null, [], [], null, null, 1)));

Assert::equals(new Declaration($context->type, $fixture), $fixture->lookup('self'));
}

#[Test]
public function lookup_parent() {
$fixture= new CodeGen();
$fixture->enter(new InType(new ClassDeclaration([], new IsValue('\\T'), new IsValue('\\lang\\Value'), [], [], null, null, 1)));

Assert::equals(new Reflection(Value::class), $fixture->lookup('parent'));
}

#[Test]
public function lookup_parent_without_parent() {
$fixture= new CodeGen();
$fixture->enter(new InType(new ClassDeclaration([], new IsValue('\\T'), null, [], [], null, null, 1)));

Assert::null($fixture->lookup('parent'));
}

#[Test]
public function lookup_named() {
$fixture= new CodeGen();
$context= $fixture->enter(new InType(new ClassDeclaration([], new IsValue('\\T'), null, [], [], null, null, 1)));

Assert::equals(new Declaration($context->type, $fixture), $fixture->lookup('\\T'));
}

#[Test]
public function lookup_value_interface() {
$fixture= new CodeGen();

Assert::equals(new Reflection(Value::class), $fixture->lookup('\\lang\\Value'));
}

#[Test]
public function lookup_non_existant() {
$fixture= new CodeGen();
Assert::instance(Incomplete::class, $fixture->lookup('\\NotFound'));
}
}

0 comments on commit f1bd59e

Please sign in to comment.