diff options
author | Technosophos <[email protected]> | 2013-04-10 11:09:59 -0500 |
---|---|---|
committer | Technosophos <[email protected]> | 2013-04-10 11:09:59 -0500 |
commit | 926d5cdb70cae58bdb06d549f777591086b67b6f (patch) | |
tree | d11ef62dfedfb8dd2278e2ed581a95557140774c | |
parent | 00fc6a82f4dbbb4ac475489a7bd86bf1e665eaa4 (diff) | |
parent | 734464d5194b7a7ada25376955859b0d3a608ab1 (diff) |
Merge branch 'master' of github.com:technosophos/HTML5-PHP
-rw-r--r-- | src/HTML5/Parser/Scanner.php | 13 | ||||
-rw-r--r-- | test/HTML5/ScannerTest.php | 41 |
2 files changed, 23 insertions, 31 deletions
diff --git a/src/HTML5/Parser/Scanner.php b/src/HTML5/Parser/Scanner.php index 2500dab..10698d7 100644 --- a/src/HTML5/Parser/Scanner.php +++ b/src/HTML5/Parser/Scanner.php @@ -18,7 +18,7 @@ class Scanner { /** * Create a new Scanner. * - * @param \HTML5\InputStream $input + * @param \HTML5\Parser\InputStream $input * An InputStream to be scanned. */ public function __construct($input) { @@ -36,10 +36,7 @@ class Scanner { } /** - * Take a peek at the character after the next character in the data. - * - * For example, you start scanning the string abc. The pointer is before a. - * When you start peek() will return b while next() will return a. + * Take a peek at the next character in the data. * * @return string * The next character. @@ -86,15 +83,13 @@ class Scanner { } /** - * Get the next group of that is a hex value. + * Get the next group of that contains hex characters. * * Note, along with getting the characters the pointer in the data will be * moved as well. - * - * @todo There is a potential for many false positives with this method. Make it more accurate. * * @return string - * The next group that is a hex value. + * The next group that is hex characters. */ public function getHex() { return $this->is->charsWhile(self::CHARS_HEX); diff --git a/test/HTML5/ScannerTest.php b/test/HTML5/ScannerTest.php index 251dcfa..8c341fa 100644 --- a/test/HTML5/ScannerTest.php +++ b/test/HTML5/ScannerTest.php @@ -5,7 +5,7 @@ */ namespace HTML5\Tests; -use \HTML5\InputStream; +use \HTML5\Parser\StringInputStream; use \HTML5\Parser\Scanner; require_once 'TestCase.php'; @@ -16,14 +16,14 @@ class ScannerTest extends TestCase { * A canary test to make sure the basics are setup and working. */ public function testConstruct() { - $is = new InputStream("abc"); + $is = new StringInputStream("abc"); $s = new Scanner($is); $this->assertInstanceOf('\HTML5\Parser\Scanner', $s); } public function testNext() { - $s = new Scanner(new InputStream("abc")); + $s = new Scanner(new StringInputStream("abc")); $this->assertEquals('a', $s->next()); $this->assertEquals('b', $s->next()); @@ -31,7 +31,7 @@ class ScannerTest extends TestCase { } public function testPosition() { - $s = new Scanner(new InputStream("abc")); + $s = new Scanner(new StringInputStream("abc")); $this->assertEquals(0, $s->position()); @@ -40,7 +40,7 @@ class ScannerTest extends TestCase { } public function testPeek() { - $s = new Scanner(new InputStream("abc")); + $s = new Scanner(new StringInputStream("abc")); // The scanner is currently pointed before a. $this->assertEquals('b', $s->peek()); @@ -50,21 +50,21 @@ class ScannerTest extends TestCase { } public function testCurrent() { - $s = new Scanner(new InputStream("abc")); + $s = new Scanner(new StringInputStream("abc")); // Before scanning the string begins the current is empty. - $this->assertEquals('', $s->current()); + $this->assertEquals('a', $s->current()); $c = $s->next(); - $this->assertEquals($c, $s->current()); + $this->assertEquals('b', $s->current()); // Test movement through the string. $c = $s->next(); - $this->assertEquals($c, $s->current()); + $this->assertEquals('c', $s->current()); } public function testUnconsume() { - $s = new Scanner(new InputStream("abcdefghijklmnopqrst")); + $s = new Scanner(new StringInputStream("abcdefghijklmnopqrst")); // Get initial position. $s->next(); @@ -82,20 +82,17 @@ class ScannerTest extends TestCase { $this->assertEquals($start, $s->position()); } - // public function testGetHex() { - // $s = new Scanner(new InputStream("abcdef%mnop*")); + public function testGetHex() { + $s = new Scanner(new StringInputStream("ab13ck45DE*")); - // $s->next(); + $this->assertEquals('ab13c', $s->getHex()); - // $this->assertEquals('bcdef', $s->getHex()); - - // echo $s->next(); echo $s->next(); echo $s->position(); echo $s->getHex(); - - // //$this->assertEquals('mnop', $s->getHex()); - // } + $s->next(); + $this->assertEquals('45DE', $s->getHex()); + } public function testGetAsciiAlpha() { - $s = new Scanner(new InputStream("abcdef1%mnop*")); + $s = new Scanner(new StringInputStream("abcdef1%mnop*")); $this->assertEquals('abcdef', $s->getAsciiAlpha()); @@ -106,7 +103,7 @@ class ScannerTest extends TestCase { } public function testGetAsciiAlphaNum() { - $s = new Scanner(new InputStream("abcdef1ghpo#mn94op")); + $s = new Scanner(new StringInputStream("abcdef1ghpo#mn94op")); $this->assertEquals('abcdef1ghpo', $s->getAsciiAlphaNum()); @@ -116,7 +113,7 @@ class ScannerTest extends TestCase { } public function testGetNumeric() { - $s = new Scanner(new InputStream("1784a 45 9867 #")); + $s = new Scanner(new StringInputStream("1784a 45 9867 #")); $this->assertEquals('1784', $s->getNumeric()); |