Skip to content

Commit f28c420

Browse files
committed
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+
?>

0 commit comments

Comments
 (0)