mirror of https://github.com/djcb/mu.git
parser: add more tests
This commit is contained in:
parent
a4fefc7256
commit
0e5e8b6bce
|
@ -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) \
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 ();
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <vector>
|
||||
#include <glib.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#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: <data> [foo] 7: <and> [and] 11: <data> [bar] "
|
||||
"15: <xor> [xor] 19: <not> [not] 24: <data> [cuux] "
|
||||
"27: <or> [or] 33: <data> [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 ();
|
||||
}
|
||||
|
|
|
@ -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 ();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue