|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace coreTests\Rules; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use CommonTestClass; |
|
7
|
|
|
use kalanis\kw_table\core\Table\Rules; |
|
8
|
|
|
use kalanis\kw_table\core\TableException; |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class EvalRuleTest extends CommonTestClass |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @throws TableException |
|
15
|
|
|
*/ |
|
16
|
|
|
public function testMatch(): void |
|
17
|
|
|
{ |
|
18
|
|
|
$lib = new Rules\REval('<3'); |
|
19
|
|
|
$this->assertTrue($lib->validate('2')); |
|
20
|
|
|
$this->assertFalse($lib->validate('name')); |
|
21
|
|
|
$this->assertFalse($lib->validate('8')); |
|
22
|
|
|
|
|
23
|
|
|
$lib = new Rules\REval('> 5'); |
|
24
|
|
|
$this->assertTrue($lib->validate(10)); |
|
25
|
|
|
|
|
26
|
|
|
$lib = new Rules\REval('!= 10'); |
|
27
|
|
|
$this->assertFalse($lib->validate(10)); |
|
28
|
|
|
$this->assertTrue($lib->validate(7)); |
|
29
|
|
|
|
|
30
|
|
|
$lib = new Rules\REval('= cosy'); |
|
31
|
|
|
$this->assertFalse($lib->validate('wat')); |
|
32
|
|
|
$this->assertFalse($lib->validate(2)); |
|
33
|
|
|
$this->assertTrue($lib->validate('cosy')); |
|
34
|
|
|
|
|
35
|
|
|
$lib = new Rules\REval('<= 5'); |
|
36
|
|
|
$this->assertTrue($lib->validate(4)); |
|
37
|
|
|
$this->assertTrue($lib->validate(5)); |
|
38
|
|
|
$this->assertFalse($lib->validate(6)); |
|
39
|
|
|
|
|
40
|
|
|
$lib = new Rules\REval('>= 5'); |
|
41
|
|
|
$this->assertFalse($lib->validate(4)); |
|
42
|
|
|
$this->assertTrue($lib->validate(5)); |
|
43
|
|
|
$this->assertTrue($lib->validate(6)); |
|
44
|
|
|
|
|
45
|
|
|
$lib = new Rules\REval('== 5'); |
|
46
|
|
|
$this->assertTrue($lib->validate('5')); |
|
47
|
|
|
$this->assertFalse($lib->validate(5)); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @throws TableException |
|
52
|
|
|
*/ |
|
53
|
|
|
public function testBadMatch(): void |
|
54
|
|
|
{ |
|
55
|
|
|
$lib = new Rules\REval('<== 3'); |
|
56
|
|
|
$this->expectException(TableException::class); |
|
57
|
|
|
$this->expectExceptionMessage('Unrecognized expression sign'); |
|
58
|
|
|
$lib->validate('10'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @throws TableException |
|
63
|
|
|
*/ |
|
64
|
|
|
public function testBadQuery(): void |
|
65
|
|
|
{ |
|
66
|
|
|
$lib = new Rules\REval('call3'); |
|
67
|
|
|
$this->expectException(TableException::class); |
|
68
|
|
|
$this->expectExceptionMessage('Unrecognized expression pattern'); |
|
69
|
|
|
$lib->validate('10'); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|