Skip to content
This repository was archived by the owner on Sep 20, 2021. It is now read-only.

Commit e4ec8db

Browse files
committed
test(llk) Add test cases for the offset feature.
1 parent 683ef45 commit e4ec8db

File tree

4 files changed

+78
-20
lines changed

4 files changed

+78
-20
lines changed

Llk/Rule/Token.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,15 @@ public function getValue()
245245
/**
246246
* Set token offset.
247247
*
248-
* @param int $offset
249-
* @return void
248+
* @param int $offset Offset.
249+
* @return int
250250
*/
251251
public function setOffset($offset)
252252
{
253+
$old = $this->_offset;
253254
$this->_offset = $offset;
255+
256+
return $old;
254257
}
255258

256259
/**

Llk/TreeNode.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,29 +176,29 @@ public function getValueToken()
176176
}
177177

178178
/**
179-
* Get token offset.
179+
* Get value value.
180180
*
181-
* @return int
181+
* @return string
182182
*/
183-
public function getOffset()
183+
public function getValueValue()
184184
{
185185
return
186-
isset($this->_value['offset'])
187-
? $this->_value['offset']
188-
: 0;
186+
isset($this->_value['value'])
187+
? $this->_value['value']
188+
: null;
189189
}
190190

191191
/**
192-
* Get value value.
192+
* Get token offset.
193193
*
194-
* @return string
194+
* @return int
195195
*/
196-
public function getValueValue()
196+
public function getOffset()
197197
{
198198
return
199-
isset($this->_value['value'])
200-
? $this->_value['value']
201-
: null;
199+
isset($this->_value['offset'])
200+
? $this->_value['offset']
201+
: 0;
202202
}
203203

204204
/**

Test/Unit/Llk/Rule/Token.php

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,12 @@ public function case_get_value()
240240
{
241241
$this
242242
->given(
243-
$name = 'foo',
244-
$tokenName = 'bar',
245-
$nodeId = 'baz',
246-
$unification = 0,
247-
$value = 'qux',
248-
$token = new SUT($name, $tokenName, $nodeId, $unification),
243+
$name = 'foo',
244+
$tokenName = 'bar',
245+
$nodeId = 'baz',
246+
$unification = 0,
247+
$value = 'qux',
248+
$token = new SUT($name, $tokenName, $nodeId, $unification),
249249
$token->setValue($value)
250250
)
251251
->when($result = $token->getValue())
@@ -254,6 +254,41 @@ public function case_get_value()
254254
->isEqualTo($value);
255255
}
256256

257+
public function case_set_offset()
258+
{
259+
$this
260+
->given(
261+
$name = 'foo',
262+
$tokenName = 'bar',
263+
$nodeId = 'baz',
264+
$unification = 0,
265+
$offset = 42,
266+
$token = new SUT($name, $tokenName, $nodeId, $unification)
267+
)
268+
->when($result = $token->setOffset($offset))
269+
->then
270+
->integer($result)
271+
->isZero();
272+
}
273+
274+
public function case_get_offset()
275+
{
276+
$this
277+
->given(
278+
$name = 'foo',
279+
$tokenName = 'bar',
280+
$nodeId = 'baz',
281+
$unification = 0,
282+
$offset = 42,
283+
$token = new SUT($name, $tokenName, $nodeId, $unification),
284+
$token->setOffset($offset)
285+
)
286+
->when($result = $token->getOffset())
287+
->then
288+
->integer($result)
289+
->isEqualTo($offset);
290+
}
291+
257292
public function case_set_kept()
258293
{
259294
$this

Test/Unit/Llk/TreeNode.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,26 @@ public function case_get_value_value_undefined()
229229
->isNull();
230230
}
231231

232+
public function case_get_offset()
233+
{
234+
$this
235+
->given($node = new SUT('foo', ['offset' => 42]))
236+
->when($result = $node->getOffset())
237+
->then
238+
->integer($result)
239+
->isEqualTo(42);
240+
}
241+
242+
public function case_get_offset_undefined()
243+
{
244+
$this
245+
->given($node = new SUT('foo', ['bar']))
246+
->when($result = $node->getOffset())
247+
->then
248+
->integer($result)
249+
->isZero();
250+
}
251+
232252
public function case_is_token()
233253
{
234254
$this

0 commit comments

Comments
 (0)