summaryrefslogtreecommitdiff
path: root/vendor/kzykhys/pygments/test/KzykHys/Pygments/PygmentsTest.php
blob: 2110e0d87f8ec3d47bc46c0917f5325349eabdb6 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php

use KzykHys\Pygments\Pygments;
use Symfony\Component\Finder\Finder;

/**
 * @author Kazuyuki Hayashi <hayashi@valnur.net>
 */
class PygmentsTest extends PHPUnit_Framework_TestCase
{

    /**
     * @dataProvider provideSamples
     */
    public function testHighlight($input, $expected, $expectedL, $lexer)
    {
        $pygments = new Pygments();

        $this->assertEquals($expected, $pygments->highlight($input, null, 'html'));
        $this->assertEquals($expected, $pygments->highlight($input, $lexer, 'html'));
        $this->assertEquals($expectedL, $pygments->highlight($input, null, 'html', array('linenos' => 1)));
    }

    /**
     * @dataProvider provideCss
     */
    public function testGetCss($expected, $expectedA, $style)
    {
        $pygments = new Pygments();

        $this->assertEquals($expected, $pygments->getCss($style));
        $this->assertEquals($expectedA, $pygments->getCss($style, '.syntax'));
    }

    public function testGetLexers()
    {
        $pygments = new Pygments();
        $lexers = $pygments->getLexers();

        $this->assertArrayHasKey('python', $lexers);
    }

    public function testGetFormatters()
    {
        $pygments = new Pygments();
        $formatters = $pygments->getFormatters();

        $this->assertArrayHasKey('html', $formatters);
    }

    public function testGetStyles()
    {
        $pygments = new Pygments();
        $styles = $pygments->getStyles();

        $this->assertArrayHasKey('monokai', $styles);
    }

    public function testGuessLexer()
    {
        $pygments = new Pygments();

        $this->assertEquals('php', $pygments->guessLexer('index.php'));
        $this->assertEquals('go', $pygments->guessLexer('main.go'));
    }

    public function provideSamples()
    {
        $finder = new Finder();
        $finder
            ->in(__DIR__ . '/Resources/example')
            ->name("*.in")
            ->notName('*.linenos.out')
            ->files()
            ->ignoreVCS(true);

        $samples = array();

        /* @var \Symfony\Component\Finder\SplFileInfo $file */
        foreach ($finder as $file) {
            $samples[] = array(
                $file->getContents(),
                file_get_contents(str_replace('.in', '.out', $file->getPathname())),
                file_get_contents(str_replace('.in', '.linenos.out', $file->getPathname())),
                preg_replace('/\..*/', '', $file->getFilename())
            );
        }

        return $samples;
    }

    public function provideCss()
    {
        $finder = new Finder();
        $finder
            ->in(__DIR__ . '/Resources/css')
            ->files()
            ->ignoreVCS(true)
            ->name('*.css')
            ->notName('*.prefix.css');

        $css = array();

        /* @var \Symfony\Component\Finder\SplFileInfo $file */
        foreach ($finder as $file) {
            $css[] = array(
                $file->getContents(),
                file_get_contents(str_replace('.css', '.prefix.css', $file->getPathname())),
                str_replace('.css', '', $file->getFilename())
            );
        }

        return $css;
    }

}