Reinforce parser tests

Some of them are actually too simple, and may be unuseful in tricky
situations. This patch adds a lot of test cases to provide an (almost)
bombproof safety with future patches.

Depends-On: I0bb1ed0109af66997e238b532d342d82d4c4ae19
Change-Id: I274ef306775c36be20acb662353f6537ff3f1a33
This commit is contained in:
Daimona Eaytoy 2018-04-07 12:42:17 +02:00
parent 3e9a2dfd33
commit 8cfd527f31
30 changed files with 143 additions and 10 deletions

View file

@ -1 +1,27 @@
(1 + 1 == 2) & (5 - 3 = 2) & (2 * 3 = 6) & (10 / 2 = 5) & (10 % 7 = 3) & (2 ** 4 = 16)
(1 + 1 === 2) &
(1.5 + 1.5 === 3.0) &
(2.5 + 1 === 3.5) &
(0 + 1 === 1) &
(2.5 + 0 === 2.5) &
(5 - 3 === 2) &
(5 - 3.5 === 1.5) &
(5.5 - 3.5 === 2.0) &
(1 - 0 === 1) &
(2.5 - 0 === 2.5) &
(2 * 3 === 6) &
(2 * 3.5 === 7.0) &
(2.5 * 3.5 === 8.75) &
(2.5 * 0 === 0.0) &
(10 / 2 === 5) &
(10 / 2.5 === 4.0) &
(18 / 36 === 0.5) &
(0 / 36 === 0) &
(12.5 / 2.5 === 5.0) &
(10.5 / 2.5 === 4.2) &
(10 % 7 === 3) &
(10.48762 % 7 === 3) &
(10 % 7.123576 === 3) &
(2 ** 4 === 16) &
(2.5 ** 2 === 6.25) &
(2.5 ** 0 === 1.0) &
(1000 ** 0 === 1)

View file

@ -1 +1 @@
(string(1) === "1") & (int("1") === 1) & (float(1) === 1.0)
(string(1) === "1") & (int("1") === 1) & (float(1) === 1.0) & bool(1) & !bool(0)

View file

@ -1 +1,4 @@
1 /* a */ == /* b */ "1" /* c */
1 /* a */ == /* b */ "1" /* c */ /* &
1/0
*/

View file

@ -1 +1 @@
contains_all("the foo is on the bar", "foo", "is on", "bar")
contains_all("the foo is on the bar", "foo", "is on", "bar") & !(contains_all(['foo', 'bar', 'hey'], 'foo', 'bar', 'sup')) & contains_all([1, 2, 3], '1', '2', '3')

View file

@ -1 +1 @@
contains_any("like anyone else", "else", "someone") & contains_any("street fighter", "fight")
contains_any("like anyone else", "else", "someone") & contains_any("street fighter", "fight") & !(contains_any('My foo is cute', 'bar', 'wtf')) & contains_any([[1], [2,3]], 1)

View file

@ -0,0 +1 @@
MATCH

View file

@ -0,0 +1 @@
"quux" contains "ux" & ['1', 'foo'] contains '1' & !('fo obar' contains 'foo') & ['foo'] contains 'f'

View file

@ -1,2 +1,2 @@
/* In filter language, the exponentiation is left-associative */
(2 ** 3 ** 2) == 64
(2 ** 3 ** 2) === 64

View file

@ -1 +1 @@
(5 / 2 = 2.5) & (5. / 2 = 2.5) & (5 / 2. = 2.5) & (int(.5) = 0)
(5 / 2 === 2.5) & (int(5 / 2) === 2) & (5. / 2 === 2.5) & (5 / 2. === 2.5) & (int(.5) === 0)

View file

@ -0,0 +1 @@
MATCH

View file

@ -0,0 +1,4 @@
/* More complete tests for get_matches are in AbuseFilterParserTest.php */
a := get_matches('I am a (dog|cat)', 'What did you say?');
get_matches('The (truth|pineapple) is (?:rarely)? pure and (nee*v(ah|er) sh?imple)', 'The truth is rarely pure and never simple, Wilde said') == ['The truth is rarely pure and never simple', 'truth', 'never simple', 'er'] &
a === [false, false]

View file

@ -1 +1 @@
"foo" in "foobar" & "quux" contains "ux"
"foo" in "foobar" & '1' in ['1', 'foo'] & !('foo' in 'fo obar') & 'f' in ['foo']

View file

@ -0,0 +1 @@
MATCH

View file

@ -0,0 +1,8 @@
/* Examples from [[mw:Extension:AbuseFilter/Rules format#Arithmetic]] */
1 + 1 === 2 &
2 * 2 === 4 &
12 / 24 === 0.5 &
24 / 12 === 2 &
9 ** 2 === 81 &
6 % 5 === 1

View file

@ -0,0 +1 @@
MATCH

View file

@ -0,0 +1,13 @@
/* Examples from [[mw:Extension:AbuseFilter/Rules format#Boolean operations]] */
(1 | 1) &
(1 | 0) &
!(0 | 0) &
(1 & 1) &
!(1 & 0) &
!(0 & 0) &
!(1 ^ 1) &
(1 ^ 0) &
!(0 ^ 0) &
!(!1)

View file

@ -0,0 +1 @@
MATCH

View file

@ -0,0 +1,20 @@
/* Examples from [[mw:Extension:AbuseFilter/Rules format#Simple comparisons]] */
!(1 == 2) &
(1 <= 2) &
!(1 >= 2) &
(1 != 2) &
(1 < 2) &
!(1 > 2) &
(2 = 2) &
('' == false) &
!('' === false) &
(1 == true) &
!(1 === true) &
(['1','2','3'] == ['1','2','3']) &
([1,2,3] === [1,2,3]) &
(['1','2','3'] == [1,2,3]) &
!(['1','2','3'] === [1,2,3]) &
([1,1,''] == [true, true, false]) &
!(['1'] == '1')

View file

@ -0,0 +1 @@
MATCH

View file

@ -0,0 +1,22 @@
/* Examples from [[mw:Extension:AbuseFilter/Rules format#Functions]] */
length( "Wikipedia" ) === 9 &
lcase( "WikiPedia" ) === 'wikipedia' &
ccnorm( "w1k1p3d14" ) === 'WIKIPEDIA' &
ccnorm( "ωɨƙɩƐƉ1α" ) === 'WIKIPEDIA' &
ccnorm_contains_any( "w1k1p3d14", "wiKiP3D1A", "foo", "bar" ) === true &
ccnorm_contains_any( "w1k1p3d14", "foo", "bar", "baz" ) === false &
ccnorm_contains_any( "w1k1p3d14 is 4w3s0me", "bar", "baz", "some" ) === true &
ccnorm( "ìíîïĩїį!ľ₤ĺľḷĿ" ) === 'IIIIIII!LLLLLL' &
norm( "!!ω..ɨ..ƙ..ɩ....Ɛ.Ɖ@@1%%α!!" ) === 'WIKIPEDAIA' &
norm( "F00 B@rr" ) === 'FOBAR' &
rmdoubles( "foobybboo" ) === 'fobybo' &
specialratio( "Wikipedia!" ) === 0.1 &
count( "foo", "foofooboofoo" ) === 3 &
count( "foo,bar,baz" ) === 3 &
rmspecials( "FOOBAR!!1" ) === 'FOOBAR1' &
rescape( "abc* (def)" ) === 'abc\* \(def\)' &
str_replace( "foobarbaz", "bar", "-" ) === 'foo-baz' &
ip_in_range( "127.0.10.0", "127.0.0.0/12" ) === true &
contains_any( "foobar", "x", "y", "f" ) === true &
get_matches( "(foo?ba+r) is (so+ good)", "fobaaar is soooo good to eat" ) === ['fobaaar is soooo good', 'fobaaar', 'soooo good']

View file

@ -0,0 +1 @@
MATCH

View file

@ -0,0 +1,9 @@
/* Examples from [[mw:Extension:AbuseFilter/Rules format#Keywords]] */
("1234" like "12?4") &
("1234" like "12*") &
("foo" in "foobar") &
("o" in ["foo", "bar"]) &
("foo" regex "\w+") &
("a\b" regex "a\\\\b") &
("a\b" regex "a\x5C\x5Cb")

View file

@ -0,0 +1 @@
MATCH

View file

@ -0,0 +1,10 @@
/* Examples from [[mw:Extension:AbuseFilter/Rules format#Lists]] */
a_list := [ 5, 6, 7, 10];
a_list[0] == 5 &
length(a_list) == 4 &
string(a_list) == "5\n6\n7\n10\n" &
5 in a_list == true &
'5' in a_list == true &
'5\n6' in a_list == true &
1 in a_list == true

View file

@ -1 +1,8 @@
(1 > 0) & (0 < 1) & (2 >= 2) & (2 <= 2)
1 > 0 &
0 < 1 &
2 >= 2 &
2 <= 2 &
0.1 < 0.2 &
0.001 <= 0.001 &
-0.01 < 0.01 &
0 >= -0.0001

View file

@ -0,0 +1 @@
NOT_MATCH

View file

@ -0,0 +1,2 @@
/* The division by zero should not be executed and not crash the filter */
false & 1/0

View file

@ -1 +0,0 @@
MATCH