aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2017-10-27 09:55:54 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2017-10-27 09:55:54 +0200
commite4ec8dbb75d07591e7c7f45c66266cbefccbfdc7 (patch)
treea9b1a0f0dabd439991337560185ec99f9e153078
parent683ef45e443d851ae0243c21ca5987bc74657811 (diff)
downloadCompiler-e4ec8dbb75d07591e7c7f45c66266cbefccbfdc7.zip
Compiler-e4ec8dbb75d07591e7c7f45c66266cbefccbfdc7.tar.gz
Compiler-e4ec8dbb75d07591e7c7f45c66266cbefccbfdc7.tar.bz2
test(llk) Add test cases for the offset feature.
-rw-r--r--Llk/Rule/Token.php7
-rw-r--r--Llk/TreeNode.php24
-rw-r--r--Test/Unit/Llk/Rule/Token.php47
-rw-r--r--Test/Unit/Llk/TreeNode.php20
4 files changed, 78 insertions, 20 deletions
diff --git a/Llk/Rule/Token.php b/Llk/Rule/Token.php
index 8b7ae6f..bd49564 100644
--- a/Llk/Rule/Token.php
+++ b/Llk/Rule/Token.php
@@ -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;
}
/**
diff --git a/Llk/TreeNode.php b/Llk/TreeNode.php
index cd29f2e..1ea4e78 100644
--- a/Llk/TreeNode.php
+++ b/Llk/TreeNode.php
@@ -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;
}
/**
diff --git a/Test/Unit/Llk/Rule/Token.php b/Test/Unit/Llk/Rule/Token.php
index 6ddb1f2..2a66fc1 100644
--- a/Test/Unit/Llk/Rule/Token.php
+++ b/Test/Unit/Llk/Rule/Token.php
@@ -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
diff --git a/Test/Unit/Llk/TreeNode.php b/Test/Unit/Llk/TreeNode.php
index 0233e28..2c911cc 100644
--- a/Test/Unit/Llk/TreeNode.php
+++ b/Test/Unit/Llk/TreeNode.php
@@ -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