Index: trunk/extensions/AbuseFilter/parser_native/maketest.cpp |
— | — | @@ -0,0 +1,54 @@ |
| 2 | +/* |
| 3 | + * Copyright (c) 2008 Andrew Garrett. |
| 4 | + * Copyright (c) 2008 River Tarnell <river@wikimedia.org> |
| 5 | + * Derived from public domain code contributed by Victor Vasiliev. |
| 6 | + * |
| 7 | + * Permission is granted to anyone to use this software for any purpose, |
| 8 | + * including commercial applications, and to alter it and redistribute it |
| 9 | + * freely. This software is provided 'as-is', without any express or |
| 10 | + * implied warranty. |
| 11 | + */ |
| 12 | + |
| 13 | +/* |
| 14 | + * Generate a test case for af_parser. |
| 15 | + * Usage: maketest <filter> [VAR=value] [VAR=value...] |
| 16 | + */ |
| 17 | + |
| 18 | +#include <iostream> |
| 19 | + |
| 20 | +#include <boost/format.hpp> |
| 21 | + |
| 22 | +int |
| 23 | +main(int argc, char **argv) |
| 24 | +{ |
| 25 | + char zero = 0; |
| 26 | + |
| 27 | + if (argc < 2) { |
| 28 | + std::cerr << boost::format("usage: %s <filter> [VAR=value...]") % argv[0]; |
| 29 | + return 1; |
| 30 | + } |
| 31 | + |
| 32 | + std::cout.write(argv[1], strlen(argv[1])); |
| 33 | + std::cout.write(&zero, 1); |
| 34 | + |
| 35 | + argc -= 2; |
| 36 | + argv += 2; |
| 37 | + |
| 38 | + while (argc) { |
| 39 | + char *s = strchr(*argv, '='); |
| 40 | + if (s == NULL) { |
| 41 | + std::cerr << "error: variable with no value: " << *argv << '\n'; |
| 42 | + return 1; |
| 43 | + } |
| 44 | + |
| 45 | + std::cout.write(*argv, s - *argv); |
| 46 | + std::cout.write(&zero, 1); |
| 47 | + *s++ = '\0'; |
| 48 | + std::cout.write(s, strlen(s)); |
| 49 | + std::cout.write(&zero, 1); |
| 50 | + |
| 51 | + argc--; |
| 52 | + argv++; |
| 53 | + } |
| 54 | + std::cout.write(&zero, 1); |
| 55 | +} |
Index: trunk/extensions/AbuseFilter/parser_native/expr.cpp |
— | — | @@ -13,6 +13,7 @@ |
14 | 14 | |
15 | 15 | #include "parser.h" |
16 | 16 | #include "afstring.h" |
| 17 | +#include "affunctions.h" |
17 | 18 | |
18 | 19 | template<typename charT> |
19 | 20 | afp::basic_datum<charT> |
— | — | @@ -23,13 +24,6 @@ |
24 | 25 | |
25 | 26 | template<typename charT> |
26 | 27 | afp::basic_datum<charT> |
27 | | -f_norm(std::vector<afp::basic_datum<charT> > const &args) |
28 | | -{ |
29 | | - return args[0]; |
30 | | -} |
31 | | - |
32 | | -template<typename charT> |
33 | | -afp::basic_datum<charT> |
34 | 28 | f_length(std::vector<afp::basic_datum<charT> > const &args) |
35 | 29 | { |
36 | 30 | return afp::basic_datum<charT>::from_int(args[0].toString().size()); |
— | — | @@ -49,7 +43,7 @@ |
50 | 44 | e.add_variable(make_u32fray("TWO"), afp::u32datum::from_int(2)); |
51 | 45 | e.add_variable(make_u32fray("THREE"), afp::u32datum::from_int(3)); |
52 | 46 | e.add_function(make_u32fray("add"), f_add<UChar32>); |
53 | | - e.add_function(make_u32fray("norm"), f_norm<UChar32>); |
| 47 | + e.add_function(make_u32fray("norm"), afp::af_norm<UChar32>); |
54 | 48 | e.add_function(make_u32fray("length"), f_length<UChar32>); |
55 | 49 | |
56 | 50 | try { |
Index: trunk/extensions/AbuseFilter/parser_native/runtests.sh |
— | — | @@ -0,0 +1,24 @@ |
| 2 | +#! /bin/ksh |
| 3 | + |
| 4 | +npass=0 |
| 5 | +nfail=0 |
| 6 | +ntotal=0 |
| 7 | + |
| 8 | +for test in *.t; do |
| 9 | + echo "$test \c" |
| 10 | + filter=$(head -1 $test) |
| 11 | + vars=$(tail +2 $test) |
| 12 | + expect=$(cat ${test%.t}.r) |
| 13 | + result=$(../maketest "$filter" $vars | (cd ..; ./af_parser)) |
| 14 | + if [ "$expect" = "$result" ]; then |
| 15 | + echo ...ok |
| 16 | + npass=$((npass + 1)) |
| 17 | + else |
| 18 | + echo ...FAIL |
| 19 | + nfail=$((nfail + 1)) |
| 20 | + fi |
| 21 | + |
| 22 | + ntotal=$((ntotal + 1)) |
| 23 | +done |
| 24 | + |
| 25 | +echo "Ran $ntotal tests. PASS: $npass FAIL: $nfail" |
Property changes on: trunk/extensions/AbuseFilter/parser_native/runtests.sh |
___________________________________________________________________ |
Added: svn:executable |
1 | 26 | + * |
Index: trunk/extensions/AbuseFilter/parser_native/tests/length.r |
— | — | @@ -0,0 +1 @@ |
| 2 | +MATCH |
Index: trunk/extensions/AbuseFilter/parser_native/tests/length.t |
— | — | @@ -0,0 +1 @@ |
| 2 | +length("foobar") == 6 |
Index: trunk/extensions/AbuseFilter/parser_native/tests/like.r |
— | — | @@ -0,0 +1 @@ |
| 2 | +MATCH |
Index: trunk/extensions/AbuseFilter/parser_native/tests/like.t |
— | — | @@ -0,0 +1 @@ |
| 2 | +"foobér" like "foob?r" & "quux" matches "qu*x" |
Index: trunk/extensions/AbuseFilter/parser_native/tests/prec.r |
— | — | @@ -0,0 +1 @@ |
| 2 | +MATCH |
Index: trunk/extensions/AbuseFilter/parser_native/tests/prec.t |
— | — | @@ -0,0 +1 @@ |
| 2 | +(1 + 2 * 3 = 7) & (2 ** 2 * 2 = 8) & (1 - 1 - 1 = -1) |
Index: trunk/extensions/AbuseFilter/parser_native/tests/float.r |
— | — | @@ -0,0 +1 @@ |
| 2 | +MATCH |
Index: trunk/extensions/AbuseFilter/parser_native/tests/float.t |
— | — | @@ -0,0 +1 @@ |
| 2 | +(5 / 2 = 2) & (5. / 2 = 2.5) & (5 / 2. = 2.5) & (int(.5) = 0) |
Index: trunk/extensions/AbuseFilter/parser_native/tests/whitespace1.r |
— | — | @@ -0,0 +1 @@ |
| 2 | +MATCH |
Index: trunk/extensions/AbuseFilter/parser_native/tests/whitespace1.t |
— | — | @@ -0,0 +1 @@ |
| 2 | +1 == length("a") |
Index: trunk/extensions/AbuseFilter/parser_native/tests/ord.r |
— | — | @@ -0,0 +1 @@ |
| 2 | +MATCH |
Index: trunk/extensions/AbuseFilter/parser_native/tests/ord.t |
— | — | @@ -0,0 +1 @@ |
| 2 | +(1 > 0) & (0 < 1) & (2 >= 2) & (2 <= 2) |
Index: trunk/extensions/AbuseFilter/parser_native/tests/utf8.r |
— | — | @@ -0,0 +1 @@ |
| 2 | +MATCH |
Index: trunk/extensions/AbuseFilter/parser_native/tests/lcase.r |
— | — | @@ -0,0 +1 @@ |
| 2 | +MATCH |
Index: trunk/extensions/AbuseFilter/parser_native/tests/utf8.t |
— | — | @@ -0,0 +1 @@ |
| 2 | +length("áéý") == 3 |
Index: trunk/extensions/AbuseFilter/parser_native/tests/lcase.t |
— | — | @@ -0,0 +1 @@ |
| 2 | +lcase("FÁmí") = "fámí" |
Index: trunk/extensions/AbuseFilter/parser_native/tests/whitespace.r |
— | — | @@ -0,0 +1 @@ |
| 2 | +MATCH |
Index: trunk/extensions/AbuseFilter/parser_native/tests/whitespace.t |
— | — | @@ -0,0 +1,2 @@ |
| 2 | +1 == FOO |
| 3 | +FOO=1 |
Index: trunk/extensions/AbuseFilter/parser_native/tests/eq.r |
— | — | @@ -0,0 +1 @@ |
| 2 | +MATCH |
Index: trunk/extensions/AbuseFilter/parser_native/tests/string.r |
— | — | @@ -0,0 +1 @@ |
| 2 | +MATCH |
Index: trunk/extensions/AbuseFilter/parser_native/tests/in.r |
— | — | @@ -0,0 +1 @@ |
| 2 | +MATCH |
Index: trunk/extensions/AbuseFilter/parser_native/tests/arith.r |
— | — | @@ -0,0 +1 @@ |
| 2 | +MATCH |
Index: trunk/extensions/AbuseFilter/parser_native/tests/eq.t |
— | — | @@ -0,0 +1 @@ |
| 2 | +(1 == 1) & (1 != 2) & (1 === 1) & (1 == "1") & (1 !== "1") |
Index: trunk/extensions/AbuseFilter/parser_native/tests/tern.r |
— | — | @@ -0,0 +1 @@ |
| 2 | +MATCH |
Index: trunk/extensions/AbuseFilter/parser_native/tests/string.t |
— | — | @@ -0,0 +1 @@ |
| 2 | +"\xA3" = "£" & "a\tb" = "a b" & "a\qb" = "aqb" |
Index: trunk/extensions/AbuseFilter/parser_native/tests/in.t |
— | — | @@ -0,0 +1 @@ |
| 2 | +"foo" in "foobar" & "quux" contains "ux" |
Index: trunk/extensions/AbuseFilter/parser_native/tests/arith.t |
— | — | @@ -0,0 +1 @@ |
| 2 | +(1 + 1 == 2) & (5 - 3 = 2) & (2 * 3 = 6) & (10 / 2 = 5) & (10 % 7 = 3) & (2 ** 4 = 16) |
Index: trunk/extensions/AbuseFilter/parser_native/tests/regex.r |
— | — | @@ -0,0 +1 @@ |
| 2 | +MATCH |
Index: trunk/extensions/AbuseFilter/parser_native/tests/tern.t |
— | — | @@ -0,0 +1 @@ |
| 2 | +1 ? 0 ? 3 : 4 : 5 == 4 |
Index: trunk/extensions/AbuseFilter/parser_native/tests/numbers.r |
— | — | @@ -0,0 +1 @@ |
| 2 | +MATCH |
Index: trunk/extensions/AbuseFilter/parser_native/tests/norm.r |
— | — | @@ -0,0 +1 @@ |
| 2 | +MATCH |
Index: trunk/extensions/AbuseFilter/parser_native/tests/regex.t |
— | — | @@ -0,0 +1 @@ |
| 2 | +"foobér" rlike "^[fq]o{2}\\S.r$" & "foo" regex "^f..?.$" |
Index: trunk/extensions/AbuseFilter/parser_native/tests/norm.t |
— | — | @@ -0,0 +1 @@ |
| 2 | +norm("foo") = "F0" & norm("anyone") = "ANY0NE" |
Index: trunk/extensions/AbuseFilter/parser_native/tests/numbers.t |
— | — | @@ -0,0 +1 @@ |
| 2 | +ax = 10 & Fx = 15 & 10o = 8 & 10b = 2 |
Index: trunk/extensions/AbuseFilter/parser_native/makefile |
— | — | @@ -35,6 +35,7 @@ |
36 | 36 | syntax_check-syntax_check.o |
37 | 37 | |
38 | 38 | expr_objs = \ |
| 39 | + expr-equiv.o \ |
39 | 40 | expr-expr.o |
40 | 41 | |
41 | 42 | xml_objs = \ |
— | — | @@ -44,8 +45,11 @@ |
45 | 46 | evaluate-equiv.o \ |
46 | 47 | evaluate-evaluate.o |
47 | 48 | |
48 | | -progs = check af_parser syntax_check af_expr expr evaluate xml |
| 49 | +maketest_objs = \ |
| 50 | + maketest-maketest.o |
49 | 51 | |
| 52 | +progs = check af_parser syntax_check af_expr expr evaluate xml maketest |
| 53 | + |
50 | 54 | all: $(progs) |
51 | 55 | |
52 | 56 | af_expr: $(af_expr_objs) |
— | — | @@ -62,6 +66,8 @@ |
63 | 67 | $(CXX) $(CXXFLAGS) -o $@ $(evaluate_objs) $(LDFLAGS) $(LIBS) |
64 | 68 | xml: $(xml_objs) |
65 | 69 | $(CXX) $(CXXFLAGS) -o $@ $(xml_objs) $(LDFLAGS) $(LIBS) |
| 70 | +maketest: $(maketest_objs) |
| 71 | + $(CXX) $(CXXFLAGS) -o $@ $(maketest_objs) $(LDFLAGS) |
66 | 72 | |
67 | 73 | $(af_expr_objs): af_expr-%.o: %.cpp |
68 | 74 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ -c $(@:af_expr-%.o=%.cpp) |
— | — | @@ -84,6 +90,12 @@ |
85 | 91 | $(xml_objs): xml-%.o: %.cpp |
86 | 92 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ -c $(@:xml-%.o=%.cpp) |
87 | 93 | |
| 94 | +$(maketest_objs): maketest-%.o: %.cpp |
| 95 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ -c $(@:maketest-%.o=%.cpp) |
| 96 | + |
| 97 | +test: maketest af_parser |
| 98 | + cd tests && ../runtests.sh |
| 99 | + |
88 | 100 | clean: |
89 | 101 | rm -f *.o $(progs) |
90 | 102 | |
Index: trunk/extensions/AbuseFilter/parser_native/parser.h |
— | — | @@ -243,7 +243,7 @@ |
244 | 244 | * letters and underscore only) are returned as the |
245 | 245 | * empty string. |
246 | 246 | */ |
247 | | - variable = leaf_node_d[ +(upper_p | '_') ] |
| 247 | + variable = reduced_node_d[ +(upper_p | '_') ] |
248 | 248 | ; |
249 | 249 | |
250 | 250 | /* |
— | — | @@ -251,7 +251,7 @@ |
252 | 252 | */ |
253 | 253 | function = |
254 | 254 | ( |
255 | | - root_node_d[ leaf_node_d[ |
| 255 | + root_node_d[ reduced_node_d[ |
256 | 256 | +(lower_p | '_') |
257 | 257 | ] ] |
258 | 258 | >> inner_node_d[ |