-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
82 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/test/php/lang/ast/unittest/nodes/SignatureTest.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php namespace lang\ast\unittest\nodes; | ||
|
||
use lang\ast\nodes\{Signature, Parameter}; | ||
use lang\ast\types\IsLiteral; | ||
use test\{Assert, Test, Values}; | ||
|
||
class SignatureTest extends NodeTest { | ||
|
||
#[Test] | ||
public function can_create() { | ||
new Signature(); | ||
} | ||
|
||
#[Test] | ||
public function without_parameters() { | ||
Assert::equals([], (new Signature())->parameters); | ||
} | ||
|
||
#[Test] | ||
public function parameters() { | ||
$params= [new Parameter('arg', null)]; | ||
Assert::equals($params, (new Signature($params))->parameters); | ||
} | ||
|
||
#[Test] | ||
public function without_returns() { | ||
Assert::null((new Signature([]))->returns); | ||
} | ||
|
||
#[Test] | ||
public function returns_string() { | ||
$type= new IsLiteral('string'); | ||
Assert::equals($type, (new Signature([], $type))->returns); | ||
} | ||
|
||
#[Test] | ||
public function without_by_ref() { | ||
Assert::false((new Signature([], null))->byref); | ||
} | ||
|
||
#[Test, Values([true, false])] | ||
public function by_ref($value) { | ||
Assert::equals($value, (new Signature([], null, $value))->byref); | ||
} | ||
|
||
#[Test] | ||
public function add_parameter() { | ||
$param= new Parameter('arg', null); | ||
|
||
$signature= new Signature(); | ||
$signature->add($param); | ||
|
||
Assert::equals([$param], $signature->parameters); | ||
} | ||
|
||
#[Test] | ||
public function insert_parameter_at_beginning() { | ||
$a= new Parameter('a', null); | ||
$b= new Parameter('b', null); | ||
$c= new Parameter('c', null); | ||
|
||
$signature= new Signature([$a, $b]); | ||
$signature->insert(0, $c); | ||
|
||
Assert::equals([$c, $a, $b], $signature->parameters); | ||
} | ||
|
||
#[Test] | ||
public function insert_parameter_at_offset() { | ||
$a= new Parameter('a', null); | ||
$b= new Parameter('b', null); | ||
$c= new Parameter('c', null); | ||
|
||
$signature= new Signature([$a, $b]); | ||
$signature->insert(1, $c); | ||
|
||
Assert::equals([$a, $c, $b], $signature->parameters); | ||
} | ||
} |