1 | <?php |
||
33 | final class RegexTest extends TestCase |
||
34 | { |
||
35 | /** |
||
36 | * @test |
||
37 | * @dataProvider valid_regex_and_content |
||
38 | */ |
||
39 | public function it_should_assert_given_regex_on_content($regex, $content) : void |
||
40 | { |
||
41 | $filter = new RegExp($regex); |
||
42 | |||
43 | $this->assertTrue( |
||
44 | $filter->__invoke($content), |
||
45 | sprintf('"%s" does NOT match on content "%s"', $regex, $content) |
||
46 | ); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @test |
||
51 | * @dataProvider invalid_regex_and_content |
||
52 | */ |
||
53 | public function it_should_not_assert_given_regex_on_content($regex, $content) : void |
||
54 | { |
||
55 | $filter = new RegExp($regex); |
||
56 | |||
57 | $this->assertFalse($filter->__invoke($content)); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @test |
||
62 | */ |
||
63 | public function it_should_return_false_if_header_does_not_have_regex_placeholder() : void |
||
64 | { |
||
65 | $filter = new RegExp('No regex'); |
||
66 | |||
67 | $this->assertFalse($filter->__invoke('No regex')); |
||
68 | } |
||
69 | |||
70 | public function valid_regex_and_content() |
||
71 | { |
||
72 | return [ |
||
73 | 'Space around content' => ['Heya %regexp:\d{2}%', ' Heya 12 '], |
||
74 | 'Content' => ['Heya %regexp:\d{2}+%', 'If you are reading it? Heya 12, you should buy me sushi.'], |
||
75 | 'Number' => ['Heya %regexp:\d{2}%', 'Heya 12'], |
||
76 | 'Mixed chars' => ['Heya %regexp:\d{2}-\d{1}\w\s+%', 'Heya 12-1a '], |
||
77 | 'Year format' => ['Heya %regexp:20\d{2}%', 'Heya 2020'], |
||
78 | 'Year format 2' => ['Heya 20%regexp:\d{2}%', 'Heya 2020'], |
||
79 | 'Year format 3' => ['Heya %regexp:20\d{2}%-%year%', 'Heya 2020-%year%'], |
||
80 | 'Year format 4' => ['Heya 20%regexp:\d{2}%-%year%', 'Heya 2020-%year%'], |
||
81 | 'Year format 5' => ['Heya 20%regexp:\d\d%-%year%', 'Heya 2020-%year%'], |
||
82 | 'Year format 6' => ['Heya 20%regexp:\\d\\d%-%year%', 'Heya 2020-%year%'], |
||
83 | 'Year format 7' => ['Heya 20%regexp:[0-9][0-9]%-%year%', 'Heya 2020-%year%'], |
||
84 | 'Year format 8' => ['Heya 20%regexp:(\d{2}?)%-%year%', 'Heya 2020-%year%'], |
||
85 | 'Year format 9' => ['Heya 20%regexp:(\d{2})?%-%year%', 'Heya 20-%year%'], |
||
86 | 'Multiple regex' => ['Heya %regexp:20\d{2}%-%year% %regexp:19-\d{1}%', 'Heya 2099-%year% 19-1'], |
||
87 | 'Max Number chars 1' => ['Heya %regexp:\d{1,2}%', 'Heya 2'], |
||
88 | 'Max Number chars 2' => ['Heya %regexp:\d{1,2}%', 'Heya 12'], |
||
89 | ]; |
||
90 | } |
||
91 | |||
92 | public function invalid_regex_and_content() |
||
93 | { |
||
94 | return [ |
||
95 | 'Space around content' => ['Heya %regexp:\d{2}+%', ' Heya 1 23 '], |
||
96 | 'Content' => ['Heya %regexp:\d{2}+%', 'If you are reading it? Heya 1a2, you should buy me sushi.'], |
||
97 | 'No Content' => ['%regexp:\d{2}+%', ''], |
||
98 | ]; |
||
99 | } |
||
100 | } |
||
101 |