Browse Source

test(llk) Add test cases for the offset feature.

pull/76/head
Ivan Enderlin 2 years ago
parent
commit
e4ec8dbb75
No known key found for this signature in database
4 changed files with 78 additions and 20 deletions
  1. 5
    2
      Llk/Rule/Token.php
  2. 12
    12
      Llk/TreeNode.php
  3. 41
    6
      Test/Unit/Llk/Rule/Token.php
  4. 20
    0
      Test/Unit/Llk/TreeNode.php

+ 5
- 2
Llk/Rule/Token.php View File

@@ -245,12 +245,15 @@ class Token extends Rule
/**
* Set token offset.
*
* @param int $offset
* @return void
* @param int $offset Offset.
* @return int
*/
public function setOffset($offset)
{
$old = $this->_offset;
$this->_offset = $offset;

return $old;
}

/**

+ 12
- 12
Llk/TreeNode.php View File

@@ -176,29 +176,29 @@ class TreeNode implements Visitor\Element
}

/**
* Get token offset.
* Get value value.
*
* @return int
* @return string
*/
public function getOffset()
public function getValueValue()
{
return
isset($this->_value['offset'])
? $this->_value['offset']
: 0;
isset($this->_value['value'])
? $this->_value['value']
: null;
}

/**
* Get value value.
* Get token offset.
*
* @return string
* @return int
*/
public function getValueValue()
public function getOffset()
{
return
isset($this->_value['value'])
? $this->_value['value']
: null;
isset($this->_value['offset'])
? $this->_value['offset']
: 0;
}

/**

+ 41
- 6
Test/Unit/Llk/Rule/Token.php View File

@@ -240,12 +240,12 @@ class Token extends Test\Unit\Suite
{
$this
->given(
$name = 'foo',
$tokenName = 'bar',
$nodeId = 'baz',
$unification = 0,
$value = 'qux',
$token = new SUT($name, $tokenName, $nodeId, $unification),
$name = 'foo',
$tokenName = 'bar',
$nodeId = 'baz',
$unification = 0,
$value = 'qux',
$token = new SUT($name, $tokenName, $nodeId, $unification),
$token->setValue($value)
)
->when($result = $token->getValue())
@@ -254,6 +254,41 @@ class Token extends Test\Unit\Suite
->isEqualTo($value);
}

public function case_set_offset()
{
$this
->given(
$name = 'foo',
$tokenName = 'bar',
$nodeId = 'baz',
$unification = 0,
$offset = 42,
$token = new SUT($name, $tokenName, $nodeId, $unification)
)
->when($result = $token->setOffset($offset))
->then
->integer($result)
->isZero();
}

public function case_get_offset()
{
$this
->given(
$name = 'foo',
$tokenName = 'bar',
$nodeId = 'baz',
$unification = 0,
$offset = 42,
$token = new SUT($name, $tokenName, $nodeId, $unification),
$token->setOffset($offset)
)
->when($result = $token->getOffset())
->then
->integer($result)
->isEqualTo($offset);
}

public function case_set_kept()
{
$this

+ 20
- 0
Test/Unit/Llk/TreeNode.php View File

@@ -229,6 +229,26 @@ class TreeNode extends Test\Unit\Suite
->isNull();
}

public function case_get_offset()
{
$this
->given($node = new SUT('foo', ['offset' => 42]))
->when($result = $node->getOffset())
->then
->integer($result)
->isEqualTo(42);
}

public function case_get_offset_undefined()
{
$this
->given($node = new SUT('foo', ['bar']))
->when($result = $node->getOffset())
->then
->integer($result)
->isZero();
}

public function case_is_token()
{
$this

Loading…
Cancel
Save