From 1c8f501203b60ef5aa3cb4fac84d0fe6e2d657e1 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Wed, 10 Apr 2013 10:33:21 -0400 Subject: Started unit tests on the scanner. --- test/HTML5/ScannerTest.php | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 test/HTML5/ScannerTest.php (limited to 'test/HTML5') diff --git a/test/HTML5/ScannerTest.php b/test/HTML5/ScannerTest.php new file mode 100644 index 0000000..919f8fc --- /dev/null +++ b/test/HTML5/ScannerTest.php @@ -0,0 +1,65 @@ +assertInstanceOf('\HTML5\Parser\Scanner', $s); + } + + public function testNext() { + $s = new Scanner(new InputStream("abc")); + + $this->assertEquals('a', $s->next()); + $this->assertEquals('b', $s->next()); + $this->assertEquals('c', $s->next()); + } + + public function testPosition() { + $s = new Scanner(new InputStream("abc")); + + $this->assertEquals(0, $s->position()); + + $s->next(); + $this->assertEquals(1, $s->position()); + } + + public function testPeek() { + $s = new Scanner(new InputStream("abc")); + + // The scanner is currently pointed before a. + $this->assertEquals('b', $s->peek()); + + $s->next(); + $this->assertEquals('c', $s->peek()); + } + + public function testCurrent() { + $s = new Scanner(new InputStream("abc")); + + // Before scanning the string begins the current is empty. + $this->assertEquals('', $s->current()); + + $c = $s->next(); + $this->assertEquals($c, $s->current()); + + // Test movement through the string. + $c = $s->next(); + $this->assertEquals($c, $s->current()); + } +} \ No newline at end of file -- cgit v1.2.3 From 699802c519e9779cd94dece288c840acf4c0ce51 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Wed, 10 Apr 2013 11:24:58 -0400 Subject: Added more documentation and tests to the Scanner. --- test/HTML5/ScannerTest.php | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'test/HTML5') 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 -- cgit v1.2.3