summaryrefslogtreecommitdiff
path: root/test/HTML5/ScannerTest.php
blob: 919f8fc6fff93b8b62f653894c86a35a81fa32d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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());
  }
}