Skip to content

Commit f28c420

Browse files
committedMay 22, 2015
Release tests set for PHP and Python. Totaling 136 tests.
Fixed: #27 Fixed: #6
1 parent a69c79c commit f28c420

16 files changed

+1281
-12
lines changed
 

‎README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Suggested way to build typograph is to run builder.php through web-server.
1414
E.g.:
1515
http://localhost/mdash/builder/builder.php
1616

17-
Then you will have 2 options: build for php and build for python.
17+
Then you will have 3 options: build for php, build for python, build tests for python.
1818

1919
Resulting files are located on root of the project:
2020
EMT.php
@@ -28,6 +28,18 @@ Use tools-php/online.php to test php version of the Typograph.
2828
tools-php/example.php contains few examples, how to use typograph inside php.
2929
tools-py/run.py contains examples, how to use typograph inside python.
3030

31+
TESTING
32+
=======
33+
To run tests for php version you should go to the page tools-php/test.php through web-server.
34+
On this page you hit start to run all the tests.
35+
36+
E.g.:
37+
http://localhost/mdash/tools-php/test.php
38+
39+
To python tests you need first build test set from php version through builder/builder.php, and
40+
then run the tests:
41+
cd tools-py
42+
python test.py
3143

3244
DEBUGGING
3345
=========

‎builder/builder.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
echo <<<HTML
1313
<a href="$phpself?action=installer">Сгенерировать файл типографа для PHP</a><br>
1414
<a href="$phpself?action=installerpy">Сгенерировать файл типографа для Python</a><br>
15+
<a href="$phpself?action=testpy">Сгенерировать тесты для Python</a><br>
1516
HTML;
1617
exit;
1718
}
@@ -128,9 +129,8 @@ function phpfile_read($file, &$size, $all = false)
128129
}
129130

130131
if($action == "testpy") {
131-
require_once("builder.py.php");
132132
$noecho = 1;
133-
require_once("../test.php");
133+
require_once("../tools-php/test.php");
134134
$list = FS::list_only_files("../tests/", '/^test\.[0-9a-z\.\-_]+\.php$/i');
135135

136136
if(count($list)>0)
@@ -145,12 +145,9 @@ function phpfile_read($file, &$size, $all = false)
145145
echo "В каталоге tests тесты не обнаружены";
146146
exit;
147147
}
148-
$r = file_get_contents("../EMT.test.py");
149-
//$r = str_replace ("TESTLIST", , $r);
150148

151-
file_put_contents("../tests.json", json_encode($tester->list));
152-
//file_put_contents("../test.py", $r);
153-
echo "Сгенерирован скрипт теста типографа для Python<br />";
149+
file_put_contents("../tests/tests.json", json_encode($tester->list));
150+
echo "Сгенерированы тесты типографа для Python<br />";
154151
}
155152

156153
?>

‎lib/EMT.Test.php

+243
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
<?php
2+
3+
class EMTTest {
4+
5+
public $list = array();
6+
private $info = array();
7+
private $_class = false;
8+
public $results = array();
9+
private $count = 0;
10+
public $double_test = false;
11+
12+
public $grid = "A";
13+
public $grtitle = "Неклассифицированные";
14+
15+
16+
protected function _dotest($test, $layout)
17+
{
18+
$typograph = new $this->_class;
19+
$typograph->set_tag_layout($layout);
20+
$ok = true;
21+
if(isset($test['safetags'])) {
22+
$safetags = array();
23+
if(is_string($test['safetags'])) $safetags = array($test['safetags']);
24+
else $safetags = $test['safetags'];
25+
foreach($safetags as $st) {
26+
$typograph->add_safe_tag($st);
27+
}
28+
}
29+
if(isset($test['params']) && is_array($test['params'])) $typograph->setup($test['params']);
30+
31+
/*
32+
if(isset($test['params']['map']) || isset($test['params']['maps']))
33+
{
34+
if(isset($test['params']['map']))
35+
{
36+
$ret['map'] = $test['params']['map'];
37+
$ret['disable'] = $test['params']['map_disable'];
38+
$ret['strict'] = $test['params']['map_strict'];
39+
$test['params']['maps'] = array($ret);
40+
}
41+
if(is_array($test['params']['maps']))
42+
{
43+
foreach($test['params']['maps'] as $map)
44+
{
45+
$typograph->set_enable_map
46+
($map['map'],
47+
isset($map['disable']) ? $map['disable'] : false,
48+
isset($map['strict']) ? $map['strict'] : false
49+
);
50+
}
51+
}
52+
} else {
53+
//if(isset($test['params']['ctl']))
54+
if(isset($test['params']['no_paragraph']) && $test['params']['no_paragraph'])
55+
{
56+
$typograph->get_tret('Etc')->disable_rule('paragraphs');
57+
}
58+
}*/
59+
$typograph->set_text($test['text']);
60+
return $typograph->apply();
61+
}
62+
63+
64+
protected function dotest($test)
65+
{
66+
$result = $this->_dotest($test, 1); // STYLE
67+
$ret['result'] = $result;
68+
69+
if($test['result_classes'])
70+
{
71+
$result = $this->_dotest($test, 2); // CLASSES
72+
$ret['result_classes'] = $result;
73+
}
74+
75+
$ret['error'] = false;
76+
if($ret['result'] !== $test['result']) $ret['error'] = true;
77+
if($test['result_classes']) if($ret['result_classes'] !== $test['result_classes']) $ret['error'] = true;
78+
79+
if(!$ret['error'])
80+
{
81+
// повторное типографирование оттипографированного текста
82+
if($this->double_test)
83+
{
84+
$test['text'] = $ret['result'];
85+
$ret['result_second'] = $this->_dotest($test, 1); // STYLE
86+
if($test['result_classes'])
87+
{
88+
$test['text'] = $ret['result_classes'];
89+
$ret['result_classes_second'] = $this->_dotest($test, 2); // CLASSES
90+
}
91+
92+
// повторное тестирование
93+
if($ret['result_second'] !== $test['result']) $ret['error'] = true;
94+
if($test['result_classes']) if($ret['result_classes_second'] !== $test['result_classes']) $ret['error'] = true;
95+
}
96+
97+
98+
}
99+
100+
101+
return $ret;
102+
}
103+
104+
/**
105+
* Установить имя типографа класс
106+
*
107+
* @param string $class
108+
*/
109+
public function set_typoclass($class)
110+
{
111+
$this->_class = $class;
112+
}
113+
114+
/**
115+
* Установить группу тестов
116+
*
117+
* @param string $id
118+
* @param string $title
119+
*/
120+
public function set_group($id, $title)
121+
{
122+
$this->grid = $id;
123+
$this->grtitle = $title;
124+
}
125+
126+
127+
/**
128+
* Добавить тест
129+
*
130+
* @param string $text - тестируемый тест
131+
* @param string $result - результат, который должен получится
132+
* @param string $id - Идентификатор теста или название теста, если массив, то оба
133+
* @param array/null $params - параметра (то что надо отключить/включить) и прочее, информация о тесте
134+
*/
135+
public function add_test($text, $result, $result_classes = null, $id = null, $params = null, $safetags = null)
136+
{
137+
$arr = array(
138+
'text' => $text,
139+
'result' => $result,
140+
'result_classes' => $result_classes,
141+
);
142+
if($params) $arr['params'] = $params;
143+
if($safetags) $arr['safetags'] = $safetags;
144+
if($id)
145+
{
146+
if(is_array($id))
147+
{
148+
if(isset($id['title'])) $arr['title'] = $id['title'];
149+
if(isset($id['id'])) $arr['id'] = $id['id'];
150+
}
151+
if(is_string($id)) $arr['title'] = $id;
152+
}
153+
$arr['grid'] = $this->grid;
154+
$arr['grtitle'] = $this->grtitle;
155+
$this->list[$this->count] = $arr;
156+
$this->count++;
157+
}
158+
159+
160+
161+
/**
162+
* Получить информацию об тесте
163+
*
164+
*
165+
* @param int $num
166+
* @return array
167+
* 'text' - входной текст
168+
* 'result' - то, что должно получится
169+
* 'params' - переданые параметры
170+
*/
171+
public function get_test_info($num)
172+
{
173+
if($num >= $this->count) return false;
174+
return $this->list[$num];
175+
}
176+
177+
/**
178+
* Получить количество тестов
179+
*
180+
* @return int
181+
*/
182+
public function get_test_count()
183+
{
184+
return $this->count;
185+
}
186+
187+
188+
/**
189+
* Протестировать типограф
190+
*
191+
* @return unknown
192+
*/
193+
public function testit()
194+
{
195+
if(count($this->list)==0) return true;
196+
$this->info = array();
197+
$this->results = array();
198+
if(!$this->_class) {
199+
$this->results['error'] = "Не задан класс типографа";
200+
return false;
201+
}
202+
$this->results['raw'] = array();
203+
$this->results['errors'] = array();
204+
$num = 0;
205+
$num2 = 0;
206+
$prevgr = "A";
207+
foreach($this->list as $test)
208+
{
209+
if($test['grid']!=$prevgr) $num2=0;
210+
$prevgr = $test['grid'];
211+
$num++;
212+
$num2++;
213+
$ret = $this->dotest($test);
214+
$test['grnum'] = $num2;
215+
$this->results['raw'][$num] = $ret;
216+
if($ret['error'])
217+
{
218+
$this->results['errors'][] = array(
219+
'num' => $num,
220+
);
221+
}
222+
$this->on_tested($num, $test, $ret);
223+
}
224+
if(count($this->results['errors'])>0) return false;
225+
return true;
226+
}
227+
228+
/**
229+
* То случается при обработке
230+
*
231+
* @param ште $num
232+
* @param array $test
233+
* @param array $ret
234+
*/
235+
public function on_tested($num, $test, $ret)
236+
{
237+
238+
}
239+
240+
}
241+
242+
243+
?>

‎misc/no.png

720 Bytes
Loading

‎misc/yes.png

592 Bytes
Loading

‎src-php/EMT.Tret.Number.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class EMT_Tret_Number extends EMT_Tret
2828
),
2929
'numeric_sub' => array(
3030
'description' => 'Нижний индекс',
31-
'pattern' => '/([a-zа-яё0-9])\_([\d]{1,3})([^а-яёa-z0-9]|$)/ieu',
31+
'pattern' => '/([a-zа-яё0-9])\_([\d]{1,3})([^@а-яёa-z0-9]|$)/ieu',
3232
'replacement' => '$m[1] . $this->tag($this->tag($m[2],"small"),"sub") . $m[3]'
3333
),
3434
'numeric_sup' => array(

‎src-php/EMT.Tret.Quote.php

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class EMT_Tret_Quote extends EMT_Tret
4242
'/\>(\&laquo\;)\.($|\s|\<)/ui',
4343
'/\>(\&laquo\;),($|\s|\<|\S)/ui',
4444
'/\>(\&laquo\;):($|\s|\<|\S)/ui',
45+
'/\>(\&laquo\;)\)($|\s|\<|\S)/ui',
4546
),
4647
'replacement' =>
4748
array(
@@ -50,6 +51,8 @@ class EMT_Tret_Quote extends EMT_Tret
5051
'>&raquo;.\2',
5152
'>&raquo;,\2',
5253
'>&raquo;:\2',
54+
'>&raquo;;\2',
55+
'>&raquo;)\2',
5356
),
5457
),
5558
'open_quote_adv' => array(

‎src-php/EMT.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -969,4 +969,4 @@ public static function fast_apply($text, $options = null)
969969
}
970970

971971

972-
?>
972+
?>

‎tests/test.bugs.php

+276
Large diffs are not rendered by default.

‎tests/test.em.php

+137
Large diffs are not rendered by default.

‎tests/test.nsys.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
$tester->set_group('T', "Блоки без типографирования и защищённые тэги");
4+
5+
$no_p = array('Text.paragraphs'=>'off', 'OptAlign.all'=>'off');
6+
7+
$tester->add_test("<notg>1 января 2009</notg>", "<span class=\"_notg_start\"></span>1 января 2009<span class=\"_notg_end\"></span>", null, "Отмена типографирования во всём тексте", $no_p);
8+
$tester->add_test("Я пишу текст, <notg>и не хочу,</notg> чтобы его часть типографировалась.", "Я&nbsp;пишу текст, <span class=\"_notg_start\"></span>и не хочу,<span class=\"_notg_end\"></span> чтобы его часть типографировалась.", null, "Отмена типографирования на части текста", $no_p);
9+
10+
$tester->add_test(<<<HTML
11+
<pre>Заяц сидел на опушке.</pre>
12+
HTML
13+
, <<<HTML
14+
<pre>Заяц сидел на опушке.</pre>
15+
HTML
16+
, null, "Отмена типографирования тэга pre", array('Text.paragraphs'=>'off', 'OptAlign.all'=>'off'), "pre");
17+
18+
$tester->add_test(<<<HTML
19+
<pre><code>Заяц сидел на опушке.</code></pre>
20+
HTML
21+
, <<<HTML
22+
<pre><code>Заяц сидел на опушке.</code></pre>
23+
HTML
24+
, null, "Отмена типографирования тэга pre с вложенным тэгом", array('Text.paragraphs'=>'off', 'OptAlign.all'=>'off'), "code");
25+
26+
27+
$tester->add_test(<<<HTML
28+
<code><pre>Заяц сидел на опушке.</pre></code>
29+
HTML
30+
, <<<HTML
31+
<code><pre>Заяц сидел на опушке.</pre></code>
32+
HTML
33+
, null, "Отмена типографирования тэга pre в внешним тэгом", array('Text.paragraphs'=>'off', 'OptAlign.all'=>'off'), "code");
34+
35+
?>

‎tests/test.reqbug.php

+223
Large diffs are not rendered by default.

‎tests/tests.json

+1
Large diffs are not rendered by default.

‎tools-php/online.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
// одно из правил ядра
2525
if(isset($info['way']))
2626
{
27-
if($info['way']!="reverse") $options[$opt] = ( $info['disabled'] ? "off" : "on" ) ; else $options[$opt] = ( $info['disabled'] ? "on" : "off" ) ;
27+
if($info['way']!="reverse") $options[$opt] = ( isset($info['disabled']) ? "off" : "on" ) ; else $options[$opt] = ( isset($info['disabled']) ? "on" : "off" ) ;
2828
}
2929
if(isset($info['selector']))
3030
{
31-
if(isset($info['reversed'])) $options[$opt] = ( $info['disabled'] ? "on" : "off" ); else $options[$opt] = ( $info['disabled'] ? "off" : "on" );
31+
if(isset($info['reversed'])) $options[$opt] = ( isset($info['disabled']) ? "on" : "off" ); else $options[$opt] = ( isset($info['disabled']) ? "off" : "on" );
3232
}
3333
}
3434
}
@@ -124,6 +124,10 @@
124124

125125

126126
$phpself = $_SERVER['PHP_SELF'];
127+
$typograph_style=isset($typograph_style)?$typograph_style:'';
128+
$inputdata=isset($inputdata)?$inputdata:'';
129+
$htmlresult=isset($htmlresult)?$htmlresult:'';
130+
$optdisplay=isset($optdisplay)?$optdisplay:'';
127131
echo <<<HTML
128132
<html>
129133
<head>

‎tools-php/test.php

+280
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,280 @@
1+
<?php
2+
3+
4+
require_once("../EMT.php");
5+
require_once("../lib/lib.php");
6+
require_once("../lib/EMT.Test.php");
7+
require_once("../lib/fs.php");
8+
require_once("../lib/external/finediff.php");
9+
10+
header('Content-Type: text/html; charset=utf-8');
11+
12+
if($_GET['clean']) require("clean.php");
13+
14+
class EMTTester extends EMTTest {
15+
16+
function doflush()
17+
{
18+
static $output_handler = null;
19+
if ($output_handler === null) $output_handler = @ini_get('output_handler');
20+
if ($output_handler == 'ob_gzhandler') return;
21+
flush();
22+
if (function_exists('ob_flush') AND function_exists('ob_get_length') AND ob_get_length() !== false) @ob_flush();
23+
else if (function_exists('ob_end_flush') AND function_exists('ob_start') AND function_exists('ob_get_length') AND ob_get_length() !== false)
24+
{
25+
@ob_end_flush();
26+
@ob_start();
27+
}
28+
}
29+
30+
31+
public function build_posle_nuzhno_raznica_block($type, $posle, $nuzhno, $raznica = false)
32+
{
33+
if($type == 0) $text = "";
34+
if($type == 1) $text = "<b>Инлайн стили</b>";
35+
if($type == 2) $text = "<b>Классы</b>";
36+
37+
38+
$razn = "";
39+
if($raznica)
40+
{
41+
42+
return <<<HTML
43+
$text
44+
<div style="margin-left: 5px ;font-family: monospace; font-weight: bold">
45+
ПОСЛЕ: $posle<br>
46+
НУЖНО: $nuzhno<br>
47+
РАЗЛЧ: $raznica<br>
48+
</div>
49+
HTML;
50+
}
51+
return <<<HTML
52+
$text
53+
<div style="margin-left: 5px ">
54+
<span style="font-family: monospace; font-weight: bold">ПОСЛЕ:</span> $posle<br>
55+
<span style="font-family: monospace; font-weight: bold">НУЖНО:</span> $nuzhno<br>
56+
</div>
57+
HTML;
58+
59+
60+
}
61+
62+
public function on_tested($num, $test, $ret)
63+
{
64+
$cc = urlencode($test['text']);
65+
$text = nl2br(htmlspecialchars($test['text']));
66+
$result = htmlspecialchars($test['result']);
67+
$out = htmlspecialchars($ret['result']);
68+
69+
$diffx = new FineDiff($out, $result, FineDiff::$characterGranularity);
70+
$diff = $diffx->renderDiffToHTML2();
71+
//$diffy = new FineDiff($ret['result'], $test['result'], FineDiff::$characterGranularity);
72+
//$diff_text = $diffy->renderDiffToHTML2();
73+
74+
$block_html_inline = $this->build_posle_nuzhno_raznica_block($test['result_classes']? 1: 0, $out, $result, $diff);
75+
$block_text_inline = $this->build_posle_nuzhno_raznica_block($test['result_classes']? 1: 0, $ret['result'], $test['text']);
76+
$block_html_classes = "";
77+
$block_text_classes = "";
78+
if(isset($test['result_classes']) && $test['result_classes'])
79+
{
80+
$diffc_h = new FineDiff(htmlspecialchars($ret['result_classes']), htmlspecialchars($test['result_classes']), FineDiff::$characterGranularity);
81+
$diff_h = $diffc_h->renderDiffToHTML2();
82+
//$diffc_t = new FineDiff($ret['result_classes'], $test['result_classes'], FineDiff::$characterGranularity);
83+
//$diff_t = $diffc_t->renderDiffToHTML2();
84+
85+
$block_html_classes = "<br>".$this->build_posle_nuzhno_raznica_block(2, htmlspecialchars($ret['result_classes']), htmlspecialchars($test['result_classes']), $diff_h);
86+
$block_text_classes = "<br>".$this->build_posle_nuzhno_raznica_block(2, $ret['result_classes'], $test['result_classes']);
87+
}
88+
89+
// повторное тестирование<br>
90+
$second_html = "";
91+
$second_text = "";
92+
if(isset($ret['result_second']) && $ret['result_second'])
93+
{
94+
$out_second = htmlspecialchars($ret['result_second']);
95+
$diffx2 = new FineDiff($out_second, $result, FineDiff::$characterGranularity);
96+
$diff_second = $diffx2->renderDiffToHTML2();
97+
$block_second_html_inline = $this->build_posle_nuzhno_raznica_block($test['result_classes']? 1: 0, $out_second, $result, $diff_second);
98+
$block_second_text_inline = $this->build_posle_nuzhno_raznica_block($test['result_classes']? 1: 0, $ret['result_second'], $test['text']);
99+
$block_second_html_classes = "";
100+
$block_second_text_classes = "";
101+
if(isset($test['result_classes_second']) && $test['result_classes_second'])
102+
{
103+
$diffc_h2 = new FineDiff(htmlspecialchars($ret['result_classes_second']), htmlspecialchars($test['result_classes']), FineDiff::$characterGranularity);
104+
$diff_second_h = $diffc_h2->renderDiffToHTML2();
105+
106+
$block_second_html_classes = "<br>".$this->build_posle_nuzhno_raznica_block(2, htmlspecialchars($ret['result_classes_second']), htmlspecialchars($test['result_classes']), $diff_second_h);
107+
$block_second_text_classes = "<br>".$this->build_posle_nuzhno_raznica_block(2, $ret['result_classes_second'], $test['result_classes']);
108+
}
109+
110+
$second_html = <<<HTML
111+
<br>
112+
<h4>Повторное типографирование</h4>
113+
$block_second_html_inline
114+
$block_second_html_classes
115+
HTML;
116+
$second_text = <<<HTML
117+
<br>
118+
<h4>Повторное типографирование</h4>
119+
$block_second_text_inline
120+
$block_second_text_classes
121+
HTML;
122+
}
123+
124+
125+
$infoblock = <<<HTML
126+
<div id="test{$num}_block" style="display:none;margin: 30px;">
127+
<div id="test{$num}_block_html" >
128+
<a href="#test$num" class="togglehtmlcode">Посмотреть текст</a>&nbsp;&nbsp;<a href="debug.php?inputdata=$cc" target="_blank">Открыть в отладчике</a><br>
129+
ДО: $text<br>
130+
<br>
131+
$block_html_inline
132+
$block_html_classes
133+
$second_html
134+
</div>
135+
<div id="test{$num}_block_code" style="display:none;">
136+
<a href="#test$num" class="togglehtmlcode">Посмотреть HTML</a>&nbsp;&nbsp;<a href="debug.php?inputdata=$cc" target="_blank">Открыть в отладчике</a><br>
137+
ДО: $text<br>
138+
<br>
139+
$block_text_inline
140+
$block_text_classes
141+
$second_text
142+
</div>
143+
144+
</div>
145+
HTML;
146+
$cnt = $this->get_test_count();
147+
148+
// первый тест в группе тестов
149+
if($test['grnum'] == 1)
150+
{
151+
echo <<<HTML
152+
</ul>
153+
<h3 style="margin-left: 20px">$test[grtitle]</h3>
154+
<ul style="list-style: none">
155+
HTML;
156+
}
157+
158+
echo " <li id='test$num'><span class='openlink ".($ret['error']? "witherror" : "")."'><a href='#test$num' class='seetest'><img style='margin-right: 0.7em' src='../misc/".($ret['error'] ? "no": "yes") .".png'>Тест $test[grid]".sprintf("%02d",$test['grnum'])." (".sprintf("%02d",$num)."/$cnt)". (isset($test['title'])?": ".$test['title']."" : "")."</a></span> $infoblock</li>\n";
159+
$this->doflush();
160+
}
161+
}
162+
163+
$noecho = isset($noecho)?$noecho:false;
164+
if(!$noecho) {
165+
166+
167+
$phpself = $_SERVER['PHP_SELF'];
168+
echo <<<HTML
169+
<html>
170+
<head>
171+
<title>Автотест - Типограф Евгения Муравьёва версия 3.0</title>
172+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
173+
<script>
174+
$(document).ready(function(){
175+
$('.seetest').click(function(){
176+
$($(this).attr('href')+'_block').toggle();
177+
});
178+
$('.togglehtmlcode').click(function(){
179+
$($(this).attr('href')+'_block_html').toggle();
180+
$($(this).attr('href')+'_block_code').toggle();
181+
});
182+
});
183+
</script>
184+
<style>
185+
del {
186+
color: red;
187+
background: #fdd;
188+
text-decoration: none;
189+
}
190+
ins {
191+
color: green;
192+
background: #dfd;
193+
text-decoration: none;
194+
}
195+
.openlink A:link {text-decoration: none; color: black;}
196+
.openlink A:visited {text-decoration: none; color: black;}
197+
.openlink A:active {text-decoration: none; color: black;}
198+
.openlink A:hover {text-decoration: underline; color: red;}
199+
.witherror {font-weight: bold;}
200+
</style>
201+
</head>
202+
<body>
203+
<h1>Типограф Евгения Муравьёва. Автотесты.</h1>
204+
<br>
205+
HTML;
206+
207+
if($_GET['run'])
208+
{
209+
$list = array();
210+
if($_GET['run'] == "all")
211+
{
212+
$list = FS::list_only_files("../tests/", '/^test\.[0-9a-z\.\-_]+\.php$/i');
213+
214+
} else {
215+
preg_match("/[a-z0-9\.\-_]+/i", $_GET['run'], $m);
216+
$f = $m[0];
217+
if(file_exists("../tests/test.$f.php"))
218+
{
219+
$list[] = "test.$f.php";
220+
}
221+
}
222+
223+
224+
$type = $_GET['run']=="all" ? "полное": "только группы ".$_GET['run'];
225+
echo <<<HTML
226+
Тестирование <b>$type</b>. <span style="display:none" id="results"></span>
227+
<br>
228+
<ul style="list-style: none">
229+
HTML;
230+
if(count($list)>0)
231+
{
232+
$tester = new EMTTester();
233+
$tester->double_test = isset($_GET['double_test']);
234+
$tester->set_typoclass("EMTypograph");
235+
foreach($list as $file) include("../tests/$file");
236+
$ok = $tester->testit();
237+
$result = $tester->results;
238+
} else {
239+
$result['error'] = "В каталоге tests тесты не обнаружены";
240+
}
241+
242+
if(isset($result['error']) && $result['error'])
243+
{
244+
$text = $result['error'];
245+
}else {
246+
if($ok)
247+
{
248+
$text = "УСПЕХ. ТЕСТОВ ПРОЙДЕНО: ".$tester->get_test_count() . ".";
249+
} else {
250+
$cnt = $tester->get_test_count();
251+
$err = count($tester->results['errors']);
252+
$text = "ОБНАРУЖЕНЫ ОШИБКИ. ПРОЙДЕНО ".($cnt-$err)." из $cnt.";
253+
}
254+
}
255+
256+
257+
echo <<<HTML
258+
</ul>
259+
<script>
260+
$(document).ready(function(){
261+
$('#results').text('$text');
262+
$('#results').show();
263+
});
264+
</script>
265+
HTML;
266+
267+
} else {
268+
echo "<b>Полное тестирование: <a href='$phpself?run=all&clean=1&double_test=1'>ЗАПУСК</a></b><br />";
269+
echo "Тестирование без повторного проверки: <a href='$phpself?run=all&clean=1'>ЗАПУСК</a></b><br />";
270+
}
271+
272+
echo <<<HTML
273+
<br>
274+
<br>
275+
</body>
276+
</html>
277+
HTML;
278+
}
279+
280+
?>

‎tools-py/test.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env python2.7
2+
# -*- coding: utf-8 -*-
3+
4+
import sys
5+
import re
6+
import base64
7+
import types
8+
import os.path
9+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
10+
from EMT import EMTypograph
11+
import json
12+
13+
tests = json.loads(open('../tests/tests.json').read(100000000))
14+
15+
#main
16+
def main():
17+
18+
total = 0
19+
passed = 0
20+
for test in tests:
21+
EMT = EMTypograph()
22+
if test['title'] == u'Минус в диапозоне чисел':
23+
x = 1
24+
if test.has_key('params'):
25+
EMT.setup(test['params'])
26+
if test.get('safetags'):
27+
x = test.get('safetags')
28+
if isinstance(x, basestring):
29+
x = [x]
30+
for s in x:
31+
EMT.add_safe_tag(s)
32+
EMT.set_text(test['text'])
33+
34+
passx = 0
35+
result = EMT.apply()
36+
if result == test['result']:
37+
r = u"OK "
38+
passx += 1
39+
else:
40+
r = u"FAIL "
41+
print (r + test['title'] + u'' )
42+
if result != test['result']:
43+
print(u" GOT: "+result + u'')
44+
print(u" NEED: "+test['result'] + u'')
45+
46+
del EMT
47+
48+
total +=1
49+
if passx>=1:
50+
passed += 1
51+
52+
print u'Total tests : '+str(total)
53+
print u'Passed tests: '+str(passed)
54+
print u'Failed tests: '+str(total-passed)
55+
return
56+
57+
if __name__=="__main__":
58+
main()

0 commit comments

Comments
 (0)
Please sign in to comment.