Beispiel #1
0
 /**
  * Tests getting last element position with offset
  * @covers \Copycat\System\Charset::getLastPositionOffset()
  */
 public function testGetLastPositionOffset()
 {
     $this->assertEquals(8, Charset::getLastPositionOffset('foo.bar', '.', 0));
     $this->assertEquals(3, Charset::getLastPositionOffset('foo.bar', '.', 1));
     $this->assertEquals(8, Charset::getLastPositionOffset('foo.bar', '.', -1));
     $this->assertEquals(12, Charset::getLastPositionOffset('foo.bar.baz', '.', 0));
     $this->assertEquals(7, Charset::getLastPositionOffset('foo.bar.baz', '.', 1));
     $this->assertEquals(12, Charset::getLastPositionOffset('foo.bar.baz', '.', -1));
     try {
         $caught = false;
         Charset::getLastPositionOffset('foo.bar', '*', 0);
     } catch (Exception $exception) {
         $caught = true;
         $this->assertEquals('Impossible to find an element in a string', $exception->getMessage());
     }
     if (!$caught) {
         $this->fail('Exception was not caught');
     }
     try {
         $caught = false;
         Charset::getLastPositionOffset('foo.bar', '.', 2);
     } catch (Exception $exception) {
         $caught = true;
         $this->assertEquals('Impossible to request offset greater than number of elements', $exception->getMessage());
     }
     if (!$caught) {
         $this->fail('Exception was not caught');
     }
     try {
         $caught = false;
         Charset::getLastPositionOffset('foo.bar', '*', 1);
     } catch (Exception $exception) {
         $caught = true;
         $this->assertEquals('Impossible to request offset greater than number of elements', $exception->getMessage());
     }
     if (!$caught) {
         $this->fail('Exception was not caught');
     }
     try {
         $caught = false;
         Charset::getLastPositionOffset('foo.bar', '*', -1);
     } catch (Exception $exception) {
         $caught = true;
         $this->assertEquals('Impossible to find an element in a string', $exception->getMessage());
     }
     if (!$caught) {
         $this->fail('Exception was not caught');
     }
 }