@@ -41,41 +41,74 @@ $matches = [
4141 ['%[a-c]+% ' , 'abc ' ],
4242 ['%[]% ' , '%[]% ' ],
4343 ['. \\+*?[^]$(){}=!<>|:-# ' , '. \\+*?[^]$(){}=!<>|:-# ' ],
44+ ['~\d+~ ' , '123 ' ],
45+ ['#\d+# ' , '123 ' ],
4446];
4547
4648$ notMatches = [
47- ['a ' , ' a ' ],
48- ['%a% ' , "a \nb " ],
49- ['%a% ' , '' ],
50- ['%A% ' , '' ],
51- ['a%s%b ' , "a \nb " ],
52- ['%s?% ' , 'a ' ],
53- ['a%c%c ' , 'abbc ' ],
54- ['a%c%c ' , 'ac ' ],
55- ['a%c%c ' , "a \nc " ],
56- ['%d% ' , '' ],
57- ['%i% ' , '-123.5 ' ],
58- ['%i% ' , '' ],
59- ['%f% ' , '' ],
60- ['%h% ' , 'gh ' ],
61- ['%h% ' , '' ],
62- ['%w% ' , ', ' ],
63- ['%w% ' , '' ],
64- ['%[a-c]+% ' , 'Abc ' ],
49+ ['' , 'a ' , '' , 'a ' ],
50+ ['a ' , ' a ' , 'a ' , ' a ' ],
51+ ["a \nb " , "a \r\nx " , "a \nb " , "a \nx " ],
52+ ["a \r\nb " , "a \nx " , "a \nb " , "a \nx " ],
53+ ["a \t \nb " , "a \nx " , "a \nb " , "a \nx " ],
54+ ["a \nb " , "a \t \nx " , "a \nb " , "a \nx " ],
55+ ["a \t\r\n\t " , 'x ' , 'a ' , 'x ' ],
56+ ['a ' , "x \t\r\n\t " , 'a ' , 'x ' ],
57+ ['%a% ' , "a \nb " , 'a ' , "a \nb " ],
58+ ['%a% ' , '' , '%a% ' , '' ],
59+ ['%A% ' , '' , '%A% ' , '' ],
60+ ['a%s%b ' , "a \nb " , 'a%s%b ' , "a \nb " ],
61+ ['%s?% ' , 'a ' , '' , 'a ' ],
62+ ['a%c%c ' , 'abbc ' , 'abc ' , 'abbc ' ],
63+ ['a%c%c ' , 'ac ' , 'acc ' , 'ac ' ],
64+ ['a%c%c ' , "a \nc " , 'a%c%c ' , "a \nc " ],
65+ ['%d% ' , '' , '%d% ' , '' ],
66+ ['%i% ' , '-123.5 ' , '-123 ' , '-123.5 ' ],
67+ ['%i% ' , '' , '%i% ' , '' ],
68+ ['%f% ' , '' , '%f% ' , '' ],
69+ ['%h% ' , 'gh ' , '%h% ' , 'gh ' ],
70+ ['%h% ' , '' , '%h% ' , '' ],
71+ ['%w% ' , ', ' , '%w% ' , ', ' ],
72+ ['%w% ' , '' , '%w% ' , '' ],
73+ ['%[a-c]+% ' , 'Abc ' , '%[a-c]+% ' , 'Abc ' ],
74+ ['foo%d%foo ' , 'foo123baz ' , 'foo123foo ' , 'foo123baz ' ],
75+ ['foo%d%bar ' , 'foo123baz ' , 'foo123bar ' , 'foo123baz ' ],
76+ ['foo%d?%foo ' , 'foo123baz ' , 'foo123foo ' , 'foo123baz ' ],
77+ ['foo%d?%bar ' , 'foo123baz ' , 'foo123bar ' , 'foo123baz ' ],
78+ ['%a%x ' , 'abc ' , 'abcx ' , 'abc ' ],
79+ ['~%d%~ ' , '~123~ ' , '~%d%~ ' , '~123~ ' ],
6580];
6681
6782foreach ($ matches as $ case ) {
68- list ($ expected , $ value ) = $ case ;
69- Assert::match ($ expected , $ value );
83+ list ($ expected , $ actual ) = $ case ;
84+ Assert::match ($ expected , $ actual );
7085}
7186
7287foreach ($ notMatches as $ case ) {
73- list ($ expected , $ value ) = $ case ;
74- Assert::exception (function () use ($ expected , $ value ) {
75- Assert::match ($ expected , $ value );
76- }, 'Tester\AssertException ' , '%A% should match %A% ' );
88+ list ($ expected , $ actual , $ expected2 , $ actual2 ) = $ case ;
89+ $ expected3 = str_replace ('% ' , '%% ' , $ expected2 );
90+ $ actual3 = str_replace ('% ' , '%% ' , $ actual2 );
91+
92+ $ ex = Assert::exception (function () use ($ expected , $ actual ) {
93+ Assert::match ($ expected , $ actual );
94+ }, 'Tester\AssertException ' , "' $ actual3' should match ' $ expected3' " );
95+
96+ Assert::same ($ expected2 , $ ex ->expected );
97+ Assert::same ($ actual2 , $ ex ->actual );
7798}
7899
100+
101+ Assert::same ('' , Assert::expandMatchingPatterns ('' , '' )[0 ]);
102+ Assert::same ('abc ' , Assert::expandMatchingPatterns ('abc ' , 'a ' )[0 ]);
103+ Assert::same ('a ' , Assert::expandMatchingPatterns ('%a?% ' , 'a ' )[0 ]);
104+ Assert::same ('123a ' , Assert::expandMatchingPatterns ('%d?%a ' , '123b ' )[0 ]);
105+ Assert::same ('a ' , Assert::expandMatchingPatterns ('a ' , 'a ' )[0 ]);
106+ Assert::same ('ab ' , Assert::expandMatchingPatterns ('ab ' , 'abc ' )[0 ]);
107+ Assert::same ('abcx ' , Assert::expandMatchingPatterns ('%a%x ' , 'abc ' )[0 ]);
108+ Assert::same ('a123c ' , Assert::expandMatchingPatterns ('a%d%c ' , 'a123x ' )[0 ]);
109+ Assert::same ('a%A%b ' , Assert::expandMatchingPatterns ('a%A%b ' , 'axc ' )[0 ]);
110+
111+
79112Assert::exception (function () {
80113 Assert::match (NULL , '' );
81114}, 'Exception ' , 'Pattern must be a string. ' );
0 commit comments