summaryrefslogtreecommitdiff
path: root/lib/test-parser.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/test-parser.cc')
-rw-r--r--lib/test-parser.cc53
1 files changed, 27 insertions, 26 deletions
diff --git a/lib/test-parser.cc b/lib/test-parser.cc
index 1d0a567..d35ed01 100644
--- a/lib/test-parser.cc
+++ b/lib/test-parser.cc
@@ -1,5 +1,5 @@
/*
-** Copyright (C) 2017 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
+** Copyright (C) 2017-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public License
@@ -23,13 +23,16 @@
#include <iostream>
#include <sstream>
+#include "test-mu-common.hh"
+
#include "mu-parser.hh"
+#include "utils/mu-utils.hh"
using namespace Mu;
struct Case {
const std::string expr;
const std::string expected;
- WarningVec warnings;
+ WarningVec warnings;
};
using CaseVec = std::vector<Case>;
@@ -37,7 +40,12 @@ using CaseVec = std::vector<Case>;
static void
test_cases(const CaseVec& cases)
{
- Parser parser;
+ char *tmpdir = test_mu_common_get_random_tmpdir();
+ g_assert (tmpdir);
+ Mu::Store dummy_store{tmpdir, "/tmp", {}, {}};
+ g_free (tmpdir);
+
+ Parser parser{dummy_store, Parser::Flags::UnitTest};
for (const auto& casus : cases ) {
@@ -53,14 +61,8 @@ test_cases(const CaseVec& cases)
std::cout << "exp:" << casus.expected << std::endl;
std::cout << "got:" << ss.str() << std::endl;
}
- g_assert_true (casus.expected == ss.str());
-
- // g_assert_cmpuint (casus.warnings.size(), ==, warnings.size());
- // for (auto i = 0; i != (int)casus.warnings.size(); ++i) {
- // std::cout << "exp:" << casus.warnings[i] << std::endl;
- // std::cout << "got:" << warnings[i] << std::endl;
- // g_assert_true (casus.warnings[i] == warnings[i]);
- // }
+
+ assert_equal (casus.expected, ss.str());
}
}
@@ -69,11 +71,11 @@ test_basic ()
{
CaseVec cases = {
//{ "", R"#((atom :value ""))#"},
- { "foo", R"#((value "" "foo"))#", },
+ { "foo", R"#((value "msgid" "foo"))#", },
{ "foo or bar",
- R"#((or(value "" "foo")(value "" "bar")))#" },
+ R"#((or(value "msgid" "foo")(value "msgid" "bar")))#" },
{ "foo and bar",
- R"#((and(value "" "foo")(value "" "bar")))#"},
+ R"#((and(value "msgid" "foo")(value "msgid" "bar")))#"},
};
test_cases (cases);
@@ -84,26 +86,25 @@ test_complex ()
{
CaseVec cases = {
{ "foo and bar or cuux",
- R"#((or(and(value "" "foo")(value "" "bar")))#" +
- std::string(R"#((value "" "cuux")))#") },
-
+ R"#((or(and(value "msgid" "foo")(value "msgid" "bar")))#" +
+ std::string(R"#((value "msgid" "cuux")))#") },
{ "a and not b",
- R"#((and(value "" "a")(not(value "" "b"))))#"
+ R"#((and(value "msgid" "a")(not(value "msgid" "b"))))#"
},
{ "a and b and c",
- R"#((and(value "" "a")(and(value "" "b")(value "" "c"))))#"
+ R"#((and(value "msgid" "a")(and(value "msgid" "b")(value "msgid" "c"))))#"
},
{ "(a or b) and c",
- R"#((and(or(value "" "a")(value "" "b"))(value "" "c")))#"
+ R"#((and(or(value "msgid" "a")(value "msgid" "b"))(value "msgid" "c")))#"
},
{ "a b", // implicit and
- R"#((and(value "" "a")(value "" "b")))#"
+ R"#((and(value "msgid" "a")(value "msgid" "b")))#"
},
{ "a not b", // implicit and not
- R"#((and(value "" "a")(not(value "" "b"))))#"
+ R"#((and(value "msgid" "a")(not(value "msgid" "b"))))#"
},
{ "not b", // implicit and not
- R"#((not(value "" "b")))#"
+ R"#((not(value "msgid" "b")))#"
}
};
@@ -111,7 +112,7 @@ test_complex ()
}
-static void
+G_GNUC_UNUSED static void
test_range ()
{
CaseVec cases = {
@@ -128,7 +129,7 @@ static void
test_flatten ()
{
CaseVec cases = {
- { " Mötørhęåđ", R"#((value "" "motorhead"))#" }
+ { " Mötørhęåđ", R"#((value "msgid" "motorhead"))#" }
};
test_cases (cases);
@@ -141,7 +142,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/range", test_range);
g_test_add_func ("/parser/flatten", test_flatten);
return g_test_run ();