FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
TextFragmentTest.php
1 <?php
2 /*
3 Copyright (C) 2014, Siemens AG
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 namespace Fossology\Lib\Data;
20 
21 class TextFragmentTest extends \PHPUnit\Framework\TestCase
22 {
23  const START_OFFSET = 10;
24 
25  const CONTENT = "foo bar baz";
26 
30  private $fragment;
31 
32  protected function setUp()
33  {
34  $this->fragment = new TextFragment(self::START_OFFSET, self::CONTENT);
35  }
36 
37  public function testGetStartOffset()
38  {
39  assertThat($this->fragment->getStartOffset(), is(self::START_OFFSET));
40  }
41 
42  public function testGetEndOffset()
43  {
44  assertThat($this->fragment->getEndOffset(), is(self::START_OFFSET + 11));
45  }
46 
47  public function testGetSliceRegular()
48  {
49  assertThat($this->fragment->getSlice(self::START_OFFSET, self::START_OFFSET + 3), is("foo"));
50  assertThat($this->fragment->getSlice(self::START_OFFSET + 4, self::START_OFFSET + 4 + 3), is("bar"));
51  assertThat($this->fragment->getSlice(self::START_OFFSET + 8, self::START_OFFSET + 8 + 3), is("baz"));
52  }
53 
54  public function testGetSliceWithoutEnd()
55  {
56  assertThat($this->fragment->getSlice(self::START_OFFSET + 8), is("baz"));
57  }
58 
59  public function testGetSliceAtLeftEdge()
60  {
61  assertThat($this->fragment->getSlice(self::START_OFFSET - 1, self::START_OFFSET - 1 + 3), is("fo"));
62  }
63 
64  public function testGetSliceAtRightEdge()
65  {
66  assertThat($this->fragment->getSlice(self::START_OFFSET + 9, self::START_OFFSET + 9 + 3), is("az"));
67  }
68 }