test cases for regexes in mlr filter

This commit is contained in:
John Kerl 2015-10-06 22:53:19 -04:00
parent e9c50c2832
commit bbddecf57c
4 changed files with 52 additions and 2 deletions

View file

@ -816,8 +816,8 @@ static function_lookup_t FUNCTION_LOOKUP_TABLE[] = {
{ FUNC_CLASS_MATH, "%", 2 , "Remainder; never negative-valued."},
{ FUNC_CLASS_MATH, "**", 2 , "Exponentiation; same as pow."},
{ FUNC_CLASS_BOOLEAN, "=~", 2 , "String (left-hand side) matches regex (right-hand side) [under construction]."},
{ FUNC_CLASS_BOOLEAN, "!=~", 2 , "String (left-hand side) does not match regex (right-hand side) [under construction]."},
{ FUNC_CLASS_BOOLEAN, "=~", 2 , "String (left-hand side) matches regex (right-hand side), e.g. '$name =~ \"^a.*b$\"'."},
{ FUNC_CLASS_BOOLEAN, "!=~", 2 , "String (left-hand side) does not match regex (right-hand side), e.g. '$name !=~ \"^a.*b$\"'."},
{ FUNC_CLASS_BOOLEAN, "==", 2 , "String/numeric equality. Mixing number and string results in string compare."},
{ FUNC_CLASS_BOOLEAN, "!=", 2 , "String/numeric inequality. Mixing number and string results in string compare."},
{ FUNC_CLASS_BOOLEAN, ">", 2 , "String/numeric greater-than. Mixing number and string results in string compare."},

View file

@ -1490,6 +1490,46 @@ mlr filter -v $x<$a*$b+-$c /dev/null
- (operator):
c (field_name).
mlr filter -v $x =~ "bcd" ./reg_test/input/regex.dkvp
=~ (operator):
x (field_name).
bcd (literal).
x=abcd,y=ghi
x=abcde,y=ghi
mlr filter -v $x =~ "^bcd" ./reg_test/input/regex.dkvp
=~ (operator):
x (field_name).
^bcd (literal).
mlr filter -v $x =~ "^abc" ./reg_test/input/regex.dkvp
=~ (operator):
x (field_name).
^abc (literal).
x=abc,y=def
x=abcd,y=ghi
x=abcde,y=ghi
mlr filter -v $x =~ "^abc$" ./reg_test/input/regex.dkvp
=~ (operator):
x (field_name).
^abc$ (literal).
x=abc,y=def
mlr filter -v $x =~ "^a.*d$" ./reg_test/input/regex.dkvp
=~ (operator):
x (field_name).
^a.*d$ (literal).
x=abcd,y=ghi
mlr filter -v $x =~ "^a.*"."d$" ./reg_test/input/regex.dkvp
=~ (operator):
x (field_name).
. (operator):
^a.* (literal).
d$ (literal).
x=abcd,y=ghi
mlr --csvlite put $gmt=sec2gmt($sec) ./reg_test/input/sec2gmt
sec,gmt
0,1970-01-01T00:00:00Z

View file

@ -0,0 +1,3 @@
x=abc,y=def
x=abcd,y=ghi
x=abcde,y=ghi

View file

@ -308,6 +308,13 @@ run_mlr filter -v '$x<$a*-$b+$c' /dev/null
run_mlr filter -v '$x<$a+$b*-$c' /dev/null
run_mlr filter -v '$x<$a*$b+-$c' /dev/null
run_mlr filter -v '$x =~ "bcd"' $indir/regex.dkvp
run_mlr filter -v '$x =~ "^bcd"' $indir/regex.dkvp
run_mlr filter -v '$x =~ "^abc"' $indir/regex.dkvp
run_mlr filter -v '$x =~ "^abc$"' $indir/regex.dkvp
run_mlr filter -v '$x =~ "^a.*d$"' $indir/regex.dkvp
run_mlr filter -v '$x =~ "^a.*"."d$"' $indir/regex.dkvp
run_mlr --csvlite put '$gmt=sec2gmt($sec)' $indir/sec2gmt
run_mlr --csvlite put '$sec=gmt2sec($gmt)' $indir/gmt2sec