summaryrefslogtreecommitdiff
path: root/test/HTML5/Parser/ScannerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'test/HTML5/Parser/ScannerTest.php')
-rw-r--r--test/HTML5/Parser/ScannerTest.php231
1 files changed, 125 insertions, 106 deletions
diff --git a/test/HTML5/Parser/ScannerTest.php b/test/HTML5/Parser/ScannerTest.php
index b0d638e..8fa5110 100644
--- a/test/HTML5/Parser/ScannerTest.php
+++ b/test/HTML5/Parser/ScannerTest.php
@@ -8,145 +8,164 @@ namespace Masterminds\HTML5\Tests\Parser;
use Masterminds\HTML5\Parser\StringInputStream;
use Masterminds\HTML5\Parser\Scanner;
-class ScannerTest extends \Masterminds\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);
+class ScannerTest extends \Masterminds\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('\Masterminds\HTML5\Parser\Scanner', $s);
+ }
- $this->assertInstanceOf('\Masterminds\HTML5\Parser\Scanner', $s);
- }
+ public function testNext()
+ {
+ $s = new Scanner(new StringInputStream("abc"));
- public function testNext() {
- $s = new Scanner(new StringInputStream("abc"));
+ $this->assertEquals('b', $s->next());
+ $this->assertEquals('c', $s->next());
+ }
- $this->assertEquals('b', $s->next());
- $this->assertEquals('c', $s->next());
- }
+ public function testPosition()
+ {
+ $s = new Scanner(new StringInputStream("abc"));
- public function testPosition() {
- $s = new Scanner(new StringInputStream("abc"));
+ $this->assertEquals(0, $s->position());
- $this->assertEquals(0, $s->position());
+ $s->next();
+ $this->assertEquals(1, $s->position());
+ }
- $s->next();
- $this->assertEquals(1, $s->position());
- }
+ public function testPeek()
+ {
+ $s = new Scanner(new StringInputStream("abc"));
- public function testPeek() {
- $s = new Scanner(new StringInputStream("abc"));
+ $this->assertEquals('b', $s->peek());
+ $s->next();
+ $this->assertEquals('c', $s->peek());
+ }
- $this->assertEquals('b', $s->peek());
+ public function testCurrent()
+ {
+ $s = new Scanner(new StringInputStream("abc"));
- $s->next();
- $this->assertEquals('c', $s->peek());
- }
+ // Before scanning the string begins the current is empty.
+ $this->assertEquals('a', $s->current());
- public function testCurrent() {
- $s = new Scanner(new StringInputStream("abc"));
+ $c = $s->next();
+ $this->assertEquals('b', $s->current());
- // Before scanning the string begins the current is empty.
- $this->assertEquals('a', $s->current());
+ // Test movement through the string.
+ $c = $s->next();
+ $this->assertEquals('c', $s->current());
+ }
- $c = $s->next();
- $this->assertEquals('b', $s->current());
+ public function testUnconsume()
+ {
+ $s = new Scanner(new StringInputStream("abcdefghijklmnopqrst"));
- // Test movement through the string.
- $c = $s->next();
- $this->assertEquals('c', $s->current());
- }
+ // Get initial position.
+ $s->next();
+ $start = $s->position();
- public function testUnconsume() {
- $s = new Scanner(new StringInputStream("abcdefghijklmnopqrst"));
+ // Move forward a bunch of positions.
+ $amount = 7;
+ for ($i = 0; $i < $amount; $i ++) {
+ $s->next();
+ }
- // Get initial position.
- $s->next();
- $start = $s->position();
+ // Roll back the amount we moved forward.
+ $s->unconsume($amount);
- // Move forward a bunch of positions.
- $amount = 7;
- for($i = 0; $i < $amount; $i++) {
- $s->next();
+ $this->assertEquals($start, $s->position());
}
- // Roll back the amount we moved forward.
- $s->unconsume($amount);
-
- $this->assertEquals($start, $s->position());
- }
-
- public function testGetHex() {
- $s = new Scanner(new StringInputStream("ab13ck45DE*"));
+ public function testGetHex()
+ {
+ $s = new Scanner(new StringInputStream("ab13ck45DE*"));
- $this->assertEquals('ab13c', $s->getHex());
+ $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());
+ $s->next();
+ $this->assertEquals('45DE', $s->getHex());
+ }
- // Move past the 1% to scan the next group of text.
- $s->next();
- $s->next();
- $this->assertEquals('mnop', $s->getAsciiAlpha());
- }
+ public function testGetAsciiAlpha()
+ {
+ $s = new Scanner(new StringInputStream("abcdef1%mnop*"));
- public function testGetAsciiAlphaNum() {
- $s = new Scanner(new StringInputStream("abcdef1ghpo#mn94op"));
+ $this->assertEquals('abcdef', $s->getAsciiAlpha());
- $this->assertEquals('abcdef1ghpo', $s->getAsciiAlphaNum());
+ // Move past the 1% to scan the next group of text.
+ $s->next();
+ $s->next();
+ $this->assertEquals('mnop', $s->getAsciiAlpha());
+ }
- // Move past the # to scan the next group of text.
- $s->next();
- $this->assertEquals('mn94op', $s->getAsciiAlphaNum());
- }
+ public function testGetAsciiAlphaNum()
+ {
+ $s = new Scanner(new StringInputStream("abcdef1ghpo#mn94op"));
- public function testGetNumeric() {
- $s = new Scanner(new StringInputStream("1784a 45 9867 #"));
+ $this->assertEquals('abcdef1ghpo', $s->getAsciiAlphaNum());
- $this->assertEquals('1784', $s->getNumeric());
+ // Move past the # to scan the next group of text.
+ $s->next();
+ $this->assertEquals('mn94op', $s->getAsciiAlphaNum());
+ }
- // Move past the 'a ' to scan the next group of text.
- $s->next();
- $s->next();
- $this->assertEquals('45', $s->getNumeric());
- }
+ public function testGetNumeric()
+ {
+ $s = new Scanner(new StringInputStream("1784a 45 9867 #"));
- public function testCurrentLine() {
- $s = new Scanner(new StringInputStream("1784a\n45\n9867 #\nThis is a test."));
+ $this->assertEquals('1784', $s->getNumeric());
- $this->assertEquals(1, $s->currentLine());
+ // Move past the 'a ' to scan the next group of text.
+ $s->next();
+ $s->next();
+ $this->assertEquals('45', $s->getNumeric());
+ }
- // Move to the next line.
- $s->getAsciiAlphaNum(); $s->next();
- $this->assertEquals(2, $s->currentLine());
- }
+ public function testCurrentLine()
+ {
+ $s = new Scanner(new StringInputStream("1784a\n45\n9867 #\nThis is a test."));
- public function testColumnOffset() {
- $s = new Scanner(new StringInputStream("1784a a\n45 9867 #\nThis is a test."));
+ $this->assertEquals(1, $s->currentLine());
- // Move the pointer to the space.
- $s->getAsciiAlphaNum();
- $this->assertEquals(5, $s->columnOffset());
+ // Move to the next line.
+ $s->getAsciiAlphaNum();
+ $s->next();
+ $this->assertEquals(2, $s->currentLine());
+ }
- // We move the pointer ahead. There must be a better way to do this.
- $s->next(); $s->next(); $s->next(); $s->next(); $s->next(); $s->next();
- $this->assertEquals(3, $s->columnOffset());
- }
+ public function testColumnOffset()
+ {
+ $s = new Scanner(new StringInputStream("1784a a\n45 9867 #\nThis is a test."));
+
+ // Move the pointer to the space.
+ $s->getAsciiAlphaNum();
+ $this->assertEquals(5, $s->columnOffset());
+
+ // We move the pointer ahead. There must be a better way to do this.
+ $s->next();
+ $s->next();
+ $s->next();
+ $s->next();
+ $s->next();
+ $s->next();
+ $this->assertEquals(3, $s->columnOffset());
+ }
- public function testRemainingChars() {
- $string = "\n45\n9867 #\nThis is a test.";
- $s = new Scanner(new StringInputStream("1784a\n45\n9867 #\nThis is a test."));
+ public function testRemainingChars()
+ {
+ $string = "\n45\n9867 #\nThis is a test.";
+ $s = new Scanner(new StringInputStream("1784a\n45\n9867 #\nThis is a test."));
- $s->getAsciiAlphaNum();
- $this->assertEquals($string, $s->remainingChars());
- }
-} \ No newline at end of file
+ $s->getAsciiAlphaNum();
+ $this->assertEquals($string, $s->remainingChars());
+ }
+}