public function testScanUntil() { $s = new StringScanner("Fri Dec 12 1975 14:39"); $this->assertEquals("Fri Dec 1", $s->scanUntil('/1/'), '$s->scanUntil("/1/") should return "Fri Dec 1"'); $this->assertEquals("1", $s->matched); $this->assertEquals("Fri Dec ", $s->preMatch, '$s->preMatch should be "Fri Dec "'); $this->assertNull($s->scanUntil('/XYZ/'), '$s->scanUntil("/XYZ/") should return null for the string "Fri Dec 12 1975 14:39"'); $s = new StringScanner('$complex ? \'php\' : "nothing", another="test"'); $return = $s->scanUntil('/[^,\\}](?=[,\\}])/'); $this->assertEquals($return, $s->scanned, 'Return value of scanUntil() should be equals $scanner->scanned'); $this->assertEquals('$complex ? \'php\' : "nothing"', $return, "The scanned value must contain the match"); $this->assertEquals('$complex ? \'php\' : "nothing', $s->prematch); $this->assertEquals(', another="test"', $s->postMatch); $s = new StringScanner('$complex ? \'php\' : "nothing"}'); $return = $s->scanUntil('/(?=[,\\}])/'); $this->assertEquals($return, $s->scanned, 'Return value of scanUntil() should be equals $scanner->scanned'); $this->assertEquals('$complex ? \'php\' : "nothing"', $return, "The scanned value must contain the match"); $this->assertEquals('$complex ? \'php\' : "nothing"', $s->prematch); $this->assertEquals('}', $s->postMatch); //$s = new StringScanner('$complex ? \'php\' : "nothing"}'); }
function testGetScanned() { $sc = new StringScanner("foobar blorg bla"); $res = $sc->getScanned(); $this->assertEqual($res, ""); $sc->scan("foobar"); $res = $sc->getScanned(); $this->assertEqual($res, "foobar"); $sc->scanUntil("rg"); $res = $sc->getScanned(); $this->assertEqual($res, "foobar blorg"); }