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') 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