Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 05996fc

Browse files
authored
Merge pull request #91 from scrivo/chore/utf8-tests
2 parents 9cafee6 + e252d65 commit 05996fc

6 files changed

Lines changed: 144 additions & 41 deletions

File tree

test/CasesFromIssuesTest.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
/* Copyright (c) 2013-2019 Geert Bergman ([email protected]), highlight.php
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
* 3. Neither the name of "highlight.js", "highlight.php", nor the names of its
14+
* contributors may be used to endorse or promote products derived from this
15+
* software without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
* POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
use Highlight\Highlighter;
31+
use Symfony\Component\Finder\Finder;
32+
33+
class CasesFromIssuesTest extends PHPUnit_Framework_TestCase
34+
{
35+
private static function parseFileName($filename)
36+
{
37+
$re = '/(\d+)(?:-\[(\w+)])?(\.expected)?\.txt/';
38+
$matches = array();
39+
40+
preg_match($re, $filename, $matches);
41+
42+
return array(
43+
'issueNumber' => $matches[1],
44+
'languages' => isset($matches[2]) ? $matches[2] : null,
45+
'expected' => isset($matches[3]),
46+
);
47+
}
48+
49+
public static function projectSpecificIssueProvider()
50+
{
51+
$specialCases = array();
52+
53+
$cases = new Finder();
54+
$cases
55+
->in(__DIR__ . '/issues/')
56+
->sortByName()
57+
->files()
58+
;
59+
60+
foreach ($cases as $case) {
61+
$config = self::parseFileName($case->getFilename());
62+
63+
if (!isset($specialCases[$config['issueNumber']])) {
64+
$specialCases[$config['issueNumber']] = array(
65+
'issueNumber' => $config['issueNumber'],
66+
'source' => '',
67+
'expected' => '',
68+
'languages' => $config['languages'],
69+
);
70+
}
71+
72+
if ($config['expected']) {
73+
$specialCases[$config['issueNumber']]['expected'] = trim($case->getContents());
74+
} else {
75+
$specialCases[$config['issueNumber']]['source'] = trim($case->getContents());
76+
}
77+
}
78+
79+
return $specialCases;
80+
}
81+
82+
/**
83+
* @dataProvider projectSpecificIssueProvider
84+
*/
85+
public function testIssueSpecificCases($issueNumber, $source, $expected, $languages)
86+
{
87+
$hl = new Highlighter();
88+
$actual = $hl->highlight($languages, $source);
89+
90+
$errMessage = sprintf("Unit test added for Issue #%d failed", $issueNumber);
91+
92+
$this->assertEquals($expected, $actual->value, $errMessage);
93+
}
94+
}

test/UnicodeTest.php

Lines changed: 0 additions & 41 deletions
This file was deleted.

test/issues/87-[php].expected.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<span class="hljs-meta">&lt;?php</span>
2+
<span class="hljs-keyword">use</span> <span class="hljs-title">yii</span>\<span class="hljs-title">helpers</span>\<span class="hljs-title">Html</span>;
3+
<span class="hljs-keyword">use</span> <span class="hljs-title">yii</span>\<span class="hljs-title">widgets</span>\<span class="hljs-title">ActiveForm</span>;
4+
5+
$form = ActiveForm::begin([
6+
<span class="hljs-string">'id'</span> =&gt; <span class="hljs-string">'login-form'</span>,
7+
<span class="hljs-string">'options'</span> =&gt; [<span class="hljs-string">'class'</span> =&gt; <span class="hljs-string">'form-horizontal'</span>],
8+
]) <span class="hljs-meta">?&gt;</span>
9+
<span class="hljs-meta">&lt;?</span>= $form-&gt;field($model, <span class="hljs-string">'username'</span>) <span class="hljs-meta">?&gt;</span>
10+
<span class="hljs-meta">&lt;?</span>= $form-&gt;field($model, <span class="hljs-string">'password'</span>)-&gt;passwordInput() <span class="hljs-meta">?&gt;</span>
11+
12+
&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">form</span>-<span class="hljs-title">group</span>"&gt;
13+
&lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">lg</span>-<span class="hljs-title">offset</span>-1 <span class="hljs-title">col</span>-<span class="hljs-title">lg</span>-11"&gt;
14+
&lt;?= <span class="hljs-title">Html</span>::<span class="hljs-title">submitButton</span>('Вход', ['<span class="hljs-title">class</span>' =&gt; '<span class="hljs-title">btn</span> <span class="hljs-title">btn</span>-<span class="hljs-title">primary</span>']) ?&gt;
15+
&lt;/<span class="hljs-title">div</span>&gt;
16+
&lt;/<span class="hljs-title">div</span>&gt;
17+
&lt;?<span class="hljs-title">php</span> <span class="hljs-title">ActiveForm</span>::<span class="hljs-title">end</span>() ?&gt;</span>

test/issues/87-[php].txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
use yii\helpers\Html;
3+
use yii\widgets\ActiveForm;
4+
5+
$form = ActiveForm::begin([
6+
'id' => 'login-form',
7+
'options' => ['class' => 'form-horizontal'],
8+
]) ?>
9+
<?= $form->field($model, 'username') ?>
10+
<?= $form->field($model, 'password')->passwordInput() ?>
11+
12+
<div class="form-group">
13+
<div class="col-lg-offset-1 col-lg-11">
14+
<?= Html::submitButton('Вход', ['class' => 'btn btn-primary']) ?>
15+
</div>
16+
</div>
17+
<?php ActiveForm::end() ?>

test/issues/90-[c].expected.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<span class="hljs-keyword">if</span> (FELTÉTEL)
2+
{
3+
IGAZ ÁG
4+
}
5+
<span class="hljs-keyword">else</span>
6+
{
7+
HAMIS ÁG
8+
}

test/issues/90-[c].txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
if (FELTÉTEL)
2+
{
3+
IGAZ ÁG
4+
}
5+
else
6+
{
7+
HAMIS ÁG
8+
}

0 commit comments

Comments
 (0)