1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace itertools; |
4
|
|
|
|
5
|
|
|
use PHPUnit_Framework_TestCase; |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class TemplateToSubstringMapConverterTest extends PHPUnit_Framework_TestCase |
9
|
|
|
{ |
10
|
|
|
/** @test */ |
11
|
|
|
public function testSemiColonSeprated() |
12
|
|
|
{ |
13
|
|
|
$converter = new TemplateToSubstringMapConverter(); |
14
|
|
|
$map = $converter->convert('a ; b ; c '); |
15
|
|
|
$this->assertEquals(0, $map['a']->getOffset()); |
16
|
|
|
$this->assertEquals(2, $map['a']->getLength()); |
17
|
|
|
$this->assertEquals(4, $map['b']->getOffset()); |
18
|
|
|
$this->assertEquals(4, $map['b']->getLength()); |
19
|
|
|
$this->assertEquals(10, $map['c']->getOffset()); |
20
|
|
|
$this->assertEquals(3, $map['c']->getLength()); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** @test */ |
24
|
|
|
public function testSpecifiedLengths() |
25
|
|
|
{ |
26
|
|
|
$converter = new TemplateToSubstringMapConverter(); |
27
|
|
|
$map = $converter->convert('<a > <b > <c > '); |
28
|
|
|
$this->assertEquals(0, $map['a']->getOffset()); |
29
|
|
|
$this->assertEquals(5, $map['a']->getLength()); |
30
|
|
|
$this->assertEquals(8, $map['b']->getOffset()); |
31
|
|
|
$this->assertEquals(9, $map['b']->getLength()); |
32
|
|
|
$this->assertEquals(22, $map['c']->getOffset()); |
33
|
|
|
$this->assertEquals(6, $map['c']->getLength()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** @test */ |
37
|
|
|
public function testAll() |
38
|
|
|
{ |
39
|
|
|
$converter = new TemplateToSubstringMapConverter(); |
40
|
|
|
$map = $converter->convert('a <b > c1; d', array('c1' => 'new-name')); |
41
|
|
|
$this->assertEquals(0, $map['a']->getOffset()); |
42
|
|
|
$this->assertEquals(2, $map['a']->getLength()); |
43
|
|
|
$this->assertEquals(2, $map['b']->getOffset()); |
44
|
|
|
$this->assertEquals(5, $map['b']->getLength()); |
45
|
|
|
$this->assertEquals(8, $map['new-name']->getOffset()); |
46
|
|
|
$this->assertEquals(2, $map['new-name']->getLength()); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|