Пример #1
0
 /**
  * int = zero / ( digit1-9 *DIGIT )
  * 
  * @param Context $context
  */
 private function handleIntegralPart(Context $context)
 {
     // check zero
     if ($context->current() === "0") {
         if (preg_match("/^0[0-9]\$/", $context->getSequence(2))) {
             $context->throwException("Integral part must not start with 0");
         }
         $this->result .= "0";
         $context->next();
         return;
     }
     // check ( digit1-9 *DIGIT )
     $this->handleFirstDigit($context);
     $this->handleDigitSequence($context);
 }
Пример #2
0
 /**
  * @covers Peach\DF\JsonCodec\Context::throwException
  */
 public function testThrowException()
 {
     $context = new Context("This\nis\r\na pen.", new ArrayMap());
     // read "This is a "
     for ($i = 0; $i < 10; $i++) {
         $context->next();
     }
     try {
         $context->throwException("Test");
         $this->fail();
     } catch (DecodeException $e) {
         $this->assertSame("Test at line 3, column 3", $e->getMessage());
     }
 }