diff --git a/lib/Makefile.am b/lib/Makefile.am index baa76656..ca690155 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -22,13 +22,15 @@ SUBDIRS= parser . tests AM_CFLAGS= \ $(WARN_CFLAGS) \ + $(GMIME_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(GUILE_CFLAGS) \ -Wno-format-nonliteral \ -Wno-switch-enum \ -Wno-suggest-attribute=format \ -Wno-deprecated-declarations \ - $(GMIME_CFLAGS) \ - $(GLIB_CFLAGS) \ - $(GUILE_CFLAGS) + -Wno-inline + AM_CXXFLAGS= \ $(WARN_CXXFLAGS) \ diff --git a/lib/parser/Makefile.am b/lib/parser/Makefile.am index c1557ac5..6894f8b4 100644 --- a/lib/parser/Makefile.am +++ b/lib/parser/Makefile.am @@ -18,24 +18,6 @@ include $(top_srcdir)/gtest.mk @VALGRIND_CHECK_RULES@ -noinst_PROGRAMS= \ - tokenize \ - parse - -tokenize_SOURCES= \ - tokenize.cc - -tokenize_LDADD= \ - $(GCOV_LDADD) \ - libmuxparser.la - -parse_SOURCES= \ - parse.cc - -parse_LDADD= \ - $(GCOV_LDADD) \ - libmuxparser.la - AM_CXXFLAGS= \ -I$(srcdir)/.. \ -I$(top_srcdir)/lib \ @@ -46,12 +28,34 @@ AM_CXXFLAGS= \ -Wno-inline \ -Wno-switch-enum -libmuxparser_la_LIBADD= \ +AM_CPPFLAGS= \ + $(GCOV_CFLAGS) + +AM_LDFLAGS= \ $(WARN_LDFLAGS) \ - $(GLIB_LIBS) \ - $(XAPIAN_LIBS) \ $(GCOV_LDADD) +noinst_PROGRAMS= \ + tokenize \ + parse + +tokenize_SOURCES= \ + tokenize.cc + +tokenize_LDADD= \ + $(WARN_LDFLAGS) \ + $(GCOV_LDADD) \ + libmuxparser.la + +parse_SOURCES= \ + parse.cc + +parse_LDADD= \ + $(WARN_LDFLAGS) \ + $(GCOV_LDADD) \ + libmuxparser.la + + noinst_LTLIBRARIES= \ libmuxparser.la @@ -68,20 +72,25 @@ libmuxparser_la_SOURCES= \ xapian.cc \ xapian.hh +libmuxparser_la_LIBADD= \ + $(WARN_LDFLAGS) \ + $(GLIB_LIBS) \ + $(XAPIAN_LIBS) + VALGRIND_SUPPRESSIONS_FILES= ${top_srcdir}/mux.supp noinst_PROGRAMS+=$(TEST_PROGS) TEST_PROGS += test-tokenizer test_tokenizer_SOURCES=test-tokenizer.cc -test_tokenizer_LDADD=libmuxparser.la +test_tokenizer_LDADD=$(GCOV_LDADD) libmuxparser.la TEST_PROGS += test-parser test_parser_SOURCES=test-parser.cc -test_parser_LDADD=libmuxparser.la +test_parser_LDADD=$(GCOV_LDADD) libmuxparser.la TEST_PROGS += test-utils test_utils_SOURCES=test-utils.cc -test_utils_LDADD=libmuxparser.la +test_utils_LDADD= $(GCOV_LDADD) libmuxparser.la TESTS=$(TEST_PROGS) diff --git a/lib/parser/proc-iface.hh b/lib/parser/proc-iface.hh index a57e4b0d..e13fd0ff 100644 --- a/lib/parser/proc-iface.hh +++ b/lib/parser/proc-iface.hh @@ -112,7 +112,7 @@ struct DummyProc: public ProcIface { // For testing } bool is_range_field (const std::string& field) const override { - return false; + return field == "range"; } Range process_range (const std::string& field, const std::string& lower, diff --git a/lib/parser/test-parser.cc b/lib/parser/test-parser.cc index 2eea921f..e0e144d7 100644 --- a/lib/parser/test-parser.cc +++ b/lib/parser/test-parser.cc @@ -92,12 +92,35 @@ test_complex () }, { "(a or b) and c", R"#((and(or(value "" "a")(value "" "b"))(value "" "c")))#" + }, + { "a b", // implicit and + R"#((and(value "" "a")(value "" "b")))#" + }, + { "a not b", // implicit and not + R"#((andnot(value "" "a")(value "" "b")))#" + }, + { "not b", // implicit and not + R"#((not(value "" "b")))#" } }; test_cases (cases); } + +static void +test_range () +{ + CaseVec cases = { + { "range:a..b", // implicit and + R"#((range "range" "a" "b"))#" + }, + }; + + test_cases (cases); +} + + static void test_flatten () { @@ -115,6 +138,7 @@ main (int argc, char *argv[]) g_test_add_func ("/parser/basic", test_basic); g_test_add_func ("/parser/complex", test_complex); + g_test_add_func ("/parser/range", test_range); g_test_add_func ("/parser/flatten", test_flatten); return g_test_run (); diff --git a/lib/parser/test-tokenizer.cc b/lib/parser/test-tokenizer.cc index a773890c..d796d957 100644 --- a/lib/parser/test-tokenizer.cc +++ b/lib/parser/test-tokenizer.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include "tokenizer.hh" @@ -128,6 +129,20 @@ test_escape () } +static void +test_to_string () +{ + std::stringstream ss; + for (const auto t: tokenize ("foo and bar xor not cuux or fnorb")) + ss << t << ' '; + + g_assert_true (ss.str() == + "3: [foo] 7: [and] 11: [bar] " + "15: [xor] 19: [not] 24: [cuux] " + "27: [or] 33: [fnorb] "); +} + + int main (int argc, char *argv[]) { @@ -137,6 +152,7 @@ main (int argc, char *argv[]) g_test_add_func ("/tokens/specials", test_specials); g_test_add_func ("/tokens/ops", test_ops); g_test_add_func ("/tokens/escape", test_escape); + g_test_add_func ("/tokens/to-string", test_to_string); return g_test_run (); } diff --git a/lib/parser/test-utils.cc b/lib/parser/test-utils.cc index efcf3dd4..366eb33f 100644 --- a/lib/parser/test-utils.cc +++ b/lib/parser/test-utils.cc @@ -44,8 +44,8 @@ test_cases(const CaseVec& cases, ProcFunc proc) if (g_test_verbose()) { std::cout << "\n"; std::cout << casus.expr << ' ' << casus.is_first << std::endl; - std::cout << "exp:" << casus.expected << std::endl; - std::cout << "got:" << res << std::endl; + std::cout << "exp: '" << casus.expected << "'" << std::endl; + std::cout << "got: '" << res << "'" << std::endl; } g_assert_true (casus.expected == res); @@ -119,6 +119,40 @@ test_size () } +static void +test_flatten () +{ + CaseVec cases = { + { "Менделе́ев", true, "менделеев" }, + { "", false, "" }, + { "Ångström", true, "angstrom" }, + }; + + test_cases (cases, [](auto s, auto f){ return utf8_flatten(s); }); +} + +static void +test_clean () +{ + CaseVec cases = { + { "\t a\t\nb ", true, "a b" }, + { "", false, "" }, + { "Ångström", true, "Ångström" }, + }; + + test_cases (cases, [](auto s, auto f){ return utf8_clean(s); }); +} + + +static void +test_format () +{ + g_assert_true (format ("hello %s, %u", "world", 123) == + "hello world, 123"); +} + + + int main (int argc, char *argv[]) { @@ -127,6 +161,9 @@ main (int argc, char *argv[]) g_test_add_func ("/utils/date-basic", test_date_basic); g_test_add_func ("/utils/date-ymwdhMs", test_date_ymwdhMs); g_test_add_func ("/utils/size", test_size); + g_test_add_func ("/utils/flatten", test_flatten); + g_test_add_func ("/utils/clean", test_clean); + g_test_add_func ("/utils/format", test_format); return g_test_run (); }