diff options
author | Matt Farina <[email protected]> | 2013-04-10 11:24:58 -0400 |
---|---|---|
committer | Matt Farina <[email protected]> | 2013-04-10 11:24:58 -0400 |
commit | 699802c519e9779cd94dece288c840acf4c0ce51 (patch) | |
tree | 78afd610c3bbadb51c4aa0608bf34bc26a308527 /test/HTML5/ScannerTest.php | |
parent | 703bfebdb9ac177f108e2e86af92b2f59cdc8ab8 (diff) |
Added more documentation and tests to the Scanner.
Diffstat (limited to 'test/HTML5/ScannerTest.php')
-rw-r--r-- | test/HTML5/ScannerTest.php | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/HTML5/ScannerTest.php b/test/HTML5/ScannerTest.php index 919f8fc..251dcfa 100644 --- a/test/HTML5/ScannerTest.php +++ b/test/HTML5/ScannerTest.php @@ -62,4 +62,67 @@ class ScannerTest extends TestCase { $c = $s->next(); $this->assertEquals($c, $s->current()); } + + public function testUnconsume() { + $s = new Scanner(new InputStream("abcdefghijklmnopqrst")); + + // Get initial position. + $s->next(); + $start = $s->position(); + + // Move forward a bunch of positions. + $amount = 7; + for($i = 0; $i < $amount; $i++) { + $s->next(); + } + + // Roll back the amount we moved forward. + $s->unconsume($amount); + + $this->assertEquals($start, $s->position()); + } + + // public function testGetHex() { + // $s = new Scanner(new InputStream("abcdef%mnop*")); + + // $s->next(); + + // $this->assertEquals('bcdef', $s->getHex()); + + // echo $s->next(); echo $s->next(); echo $s->position(); echo $s->getHex(); + + // //$this->assertEquals('mnop', $s->getHex()); + // } + + public function testGetAsciiAlpha() { + $s = new Scanner(new InputStream("abcdef1%mnop*")); + + $this->assertEquals('abcdef', $s->getAsciiAlpha()); + + // Move past the 1% to scan the next group of text. + $s->next(); + $s->next(); + $this->assertEquals('mnop', $s->getAsciiAlpha()); + } + + public function testGetAsciiAlphaNum() { + $s = new Scanner(new InputStream("abcdef1ghpo#mn94op")); + + $this->assertEquals('abcdef1ghpo', $s->getAsciiAlphaNum()); + + // Move past the # to scan the next group of text. + $s->next(); + $this->assertEquals('mn94op', $s->getAsciiAlphaNum()); + } + + public function testGetNumeric() { + $s = new Scanner(new InputStream("1784a 45 9867 #")); + + $this->assertEquals('1784', $s->getNumeric()); + + // Move past the 'a ' to scan the next group of text. + $s->next(); + $s->next(); + $this->assertEquals('45', $s->getNumeric()); + } }
\ No newline at end of file |