summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatt Farina <[email protected]>2013-04-10 13:26:49 -0400
committerMatt Farina <[email protected]>2013-04-10 13:26:49 -0400
commit5d7cd7d13d8092017311dcb0d830dd55697d25a1 (patch)
treeec01a664d98c199fc85efa9a86120101acca84a5 /test
parentf9590a91ad948db1449a3dc61d90e9c9a71c6ee3 (diff)
Moved the ScannerTest into the Parser directory for the new work.
Diffstat (limited to 'test')
-rw-r--r--test/HTML5/Parser/ScannerTest.php118
-rw-r--r--test/HTML5/ScannerTest.php124
2 files changed, 109 insertions, 133 deletions
diff --git a/test/HTML5/Parser/ScannerTest.php b/test/HTML5/Parser/ScannerTest.php
index 5d85197..ad936df 100644
--- a/test/HTML5/Parser/ScannerTest.php
+++ b/test/HTML5/Parser/ScannerTest.php
@@ -1,24 +1,124 @@
<?php
-namespace HTML5\Parser;
-require __DIR__ . '/../TestCase.php';
+/**
+ * @file
+ * Test the Scanner. This requires the InputStream tests are all good.
+ */
+namespace HTML5\Tests\Parser;
-class ScannerTest extends TestCase {
- public function testNext() {
+use \HTML5\Parser\StringInputStream;
+use \HTML5\Parser\Scanner;
+
+require_once __DIR__ . '/../TestCase.php';
+
+class ScannerTest extends \HTML5\Tests\TestCase {
+
+ /**
+ * A canary test to make sure the basics are setup and working.
+ */
+ public function testConstruct() {
+ $is = new StringInputStream("abc");
+ $s = new Scanner($is);
+
+ $this->assertInstanceOf('\HTML5\Parser\Scanner', $s);
}
- public function testCurrent() {
+
+ public function testNext() {
+ $s = new Scanner(new StringInputStream("abc"));
+
+ $this->assertEquals('b', $s->next());
+ $this->assertEquals('c', $s->next());
}
+
public function testPosition() {
+ $s = new Scanner(new StringInputStream("abc"));
+
+ $this->assertEquals(0, $s->position());
+
+ $s->next();
+ $this->assertEquals(1, $s->position());
}
+
public function testPeek() {
+ $s = new Scanner(new StringInputStream("abc"));
+
+
+ $this->assertEquals('b', $s->peek());
+
+ $s->next();
+ $this->assertEquals('c', $s->peek());
+ }
+
+ public function testCurrent() {
+ $s = new Scanner(new StringInputStream("abc"));
+
+ // Before scanning the string begins the current is empty.
+ $this->assertEquals('a', $s->current());
+
+ $c = $s->next();
+ $this->assertEquals('b', $s->current());
+
+ // Test movement through the string.
+ $c = $s->next();
+ $this->assertEquals('c', $s->current());
}
+
public function testUnconsume() {
+ $s = new Scanner(new StringInputStream("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 StringInputStream("ab13ck45DE*"));
+
+ $this->assertEquals('ab13c', $s->getHex());
+
+ $s->next();
+ $this->assertEquals('45DE', $s->getHex());
}
- public function testGetNumeric() {
- }
- public function testAsciiAlpha() {
+
+ public function testGetAsciiAlpha() {
+ $s = new Scanner(new StringInputStream("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 StringInputStream("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 StringInputStream("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
diff --git a/test/HTML5/ScannerTest.php b/test/HTML5/ScannerTest.php
deleted file mode 100644
index 997123c..0000000
--- a/test/HTML5/ScannerTest.php
+++ /dev/null
@@ -1,124 +0,0 @@
-<?php
-/**
- * @file
- * Test the Scanner. This requires the InputStream tests are all good.
- */
-namespace HTML5\Tests;
-
-use \HTML5\Parser\StringInputStream;
-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 StringInputStream("abc");
- $s = new Scanner($is);
-
- $this->assertInstanceOf('\HTML5\Parser\Scanner', $s);
- }
-
- public function testNext() {
- $s = new Scanner(new StringInputStream("abc"));
-
- $this->assertEquals('b', $s->next());
- $this->assertEquals('c', $s->next());
- }
-
- public function testPosition() {
- $s = new Scanner(new StringInputStream("abc"));
-
- $this->assertEquals(0, $s->position());
-
- $s->next();
- $this->assertEquals(1, $s->position());
- }
-
- public function testPeek() {
- $s = new Scanner(new StringInputStream("abc"));
-
-
- $this->assertEquals('b', $s->peek());
-
- $s->next();
- $this->assertEquals('c', $s->peek());
- }
-
- public function testCurrent() {
- $s = new Scanner(new StringInputStream("abc"));
-
- // Before scanning the string begins the current is empty.
- $this->assertEquals('a', $s->current());
-
- $c = $s->next();
- $this->assertEquals('b', $s->current());
-
- // Test movement through the string.
- $c = $s->next();
- $this->assertEquals('c', $s->current());
- }
-
- public function testUnconsume() {
- $s = new Scanner(new StringInputStream("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 StringInputStream("ab13ck45DE*"));
-
- $this->assertEquals('ab13c', $s->getHex());
-
- $s->next();
- $this->assertEquals('45DE', $s->getHex());
- }
-
- public function testGetAsciiAlpha() {
- $s = new Scanner(new StringInputStream("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 StringInputStream("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 StringInputStream("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