summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatt Farina <[email protected]>2013-04-10 10:33:21 -0400
committerMatt Farina <[email protected]>2013-04-10 10:33:21 -0400
commit1c8f501203b60ef5aa3cb4fac84d0fe6e2d657e1 (patch)
tree58518042aa52f796f5bea75bfc83a51ca4dd9abd /test
parent115ce6b633e14050f93049f96b14bf0b6f5f631f (diff)
Started unit tests on the scanner.
Diffstat (limited to 'test')
-rw-r--r--test/HTML5/ScannerTest.php65
1 files changed, 65 insertions, 0 deletions
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 @@
+<?php
+/**
+ * @file
+ * Test the Scanner. This requires the InputStream tests are all good.
+ */
+namespace HTML5\Tests;
+
+use \HTML5\InputStream;
+use \HTML5\Parser\Scanner;
+
+require_once 'TestCase.php';
+
+class ScannerTest extends TestCase {
+
+ /**
+ * A canary test to make sure the basics are setup and working.
+ */
+ public function testConstruct() {
+ $is = new InputStream("abc");
+ $s = new Scanner($is);
+
+ $this->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