-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesthelpers.php
More file actions
64 lines (50 loc) · 1.19 KB
/
testhelpers.php
File metadata and controls
64 lines (50 loc) · 1.19 KB
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
<?php
require_once __DIR__ . '/vendor/autoload.php';
function testRule($r, $ycases, $ncase, $show = true,$method=null)
{
if($method == null){
$method = function ($rule,$data){
return preg_match($rule,$data);
};
}
out("\nr:{$r}", 'info', $show);
foreach ($ycases as $v) {
out("\nycase " . $v, 'info', $show);
if ($method($r, $v)) {
out('true', 'success', $show);
} else {
out('false', 'error', $show);
};
}
foreach ($ncase as $v) {
out("\nncase " . $v, 'info', $show);
if ($method($r, $v)) {
out('false', 'error', $show);
} else {
out('true', 'success', $show);
};
}
}
function out($text, $color = null, $show = true)
{
if (!$show) {
return;
}
$styles = array(
'success' => "\033[0;32m%s\033[0m",
'error' => "\033[31;31m%s\033[0m",
'info' => "\033[33;33m%s\033[0m"
);
$format = '%s';
if (isset($styles[$color])) {
$format = $styles[$color];
}
printf($format, $text);
}
function error($str, $exit = false)
{
out($str, 'error');
if ($exit) {
exit;
}
}