mirror of https://github.com/djcb/mu.git
lib: update for api changes, update tests
With the new Sexp. And expand unit tests.
This commit is contained in:
parent
ae9607530f
commit
fd7c011195
|
@ -141,21 +141,21 @@ build_metadata(const QueryMatch& qmatch)
|
|||
static_cast<unsigned>(td & 0xffff),
|
||||
0));
|
||||
if (qmatch.has_flag(QueryMatch::Flags::Root))
|
||||
mdata.put_props(":root", Sexp::t());
|
||||
mdata.put_props(":root", Sexp::t_sym);
|
||||
if (qmatch.has_flag(QueryMatch::Flags::Related))
|
||||
mdata.put_props(":related", Sexp::t());
|
||||
mdata.put_props(":related", Sexp::t_sym);
|
||||
if (qmatch.has_flag(QueryMatch::Flags::First))
|
||||
mdata.put_props(":first-child", Sexp::t());
|
||||
mdata.put_props(":first-child", Sexp::t_sym);
|
||||
if (qmatch.has_flag(QueryMatch::Flags::Last))
|
||||
mdata.put_props(":last-child", Sexp::t());
|
||||
mdata.put_props(":last-child", Sexp::t_sym);
|
||||
if (qmatch.has_flag(QueryMatch::Flags::Orphan))
|
||||
mdata.put_props(":orphan", Sexp::t());
|
||||
mdata.put_props(":orphan", Sexp::t_sym);
|
||||
if (qmatch.has_flag(QueryMatch::Flags::Duplicate))
|
||||
mdata.put_props(":duplicate", Sexp::t());
|
||||
mdata.put_props(":duplicate", Sexp::t_sym);
|
||||
if (qmatch.has_flag(QueryMatch::Flags::HasChild))
|
||||
mdata.put_props(":has-child", Sexp::t());
|
||||
mdata.put_props(":has-child", Sexp::t_sym);
|
||||
if (qmatch.has_flag(QueryMatch::Flags::ThreadSubject))
|
||||
mdata.put_props(":thread-subject", Sexp::t());
|
||||
mdata.put_props(":thread-subject", Sexp::t_sym);
|
||||
|
||||
return mdata;
|
||||
}
|
||||
|
@ -700,7 +700,7 @@ Server::Private::find_handler(const Command& cmd)
|
|||
/* before sending new results, send an 'erase' message, so the frontend
|
||||
* knows it should erase the headers buffer. this will ensure that the
|
||||
* output of two finds will not be mixed. */
|
||||
output_sexp(Sexp().put_props(":erase", Sexp::t()));
|
||||
output_sexp(Sexp().put_props(":erase", Sexp::t_sym));
|
||||
const auto foundnum{output_results(*qres, static_cast<size_t>(batch_size))};
|
||||
output_sexp(Sexp().put_props(":found", foundnum));
|
||||
}
|
||||
|
@ -844,9 +844,9 @@ Server::Private::perform_move(Store::Id docid,
|
|||
/* note, the :move t thing is a hint to the frontend that it
|
||||
* could remove the particular header */
|
||||
if (different_mdir)
|
||||
sexp.put_props(":move", Sexp::t());
|
||||
sexp.put_props(":move", Sexp::t_sym);
|
||||
if (!no_view && id == docid)
|
||||
sexp.put_props(":maybe-view", Sexp::t());
|
||||
sexp.put_props(":maybe-view", Sexp::t_sym);
|
||||
output_sexp(std::move(sexp));
|
||||
}
|
||||
}
|
||||
|
@ -1000,7 +1000,7 @@ Server::Private::sent_handler(const Command& cmd)
|
|||
throw Error{Error::Code::Store, "failed to add path: %s",
|
||||
docid.error().what()};
|
||||
output_sexp(Sexp().put_props(
|
||||
":sent", Sexp::t(),
|
||||
":sent", Sexp::t_sym,
|
||||
":path", path,
|
||||
":docid", docid.value()));
|
||||
}
|
||||
|
|
|
@ -582,8 +582,8 @@ Boo!
|
|||
const auto moved_sexp{moved_msg.sexp()};
|
||||
//std::cerr << "@@ " << *moved_msg << '\n';
|
||||
g_assert_true(moved_sexp.plistp());
|
||||
g_assert_true(moved_sexp.has_prop(":path"));
|
||||
assert_equal(moved_sexp.get_prop(":path").string(), new_path);
|
||||
g_assert_true(!!moved_sexp.get_prop(":path"));
|
||||
assert_equal(moved_sexp.get_prop(":path").value().string(), new_path);
|
||||
|
||||
/*
|
||||
* find new message with query, ensure it's really that new one.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** Copyright (C) 2020-2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
** Copyright (C) 2020-2023 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the GNU General Public License as published by the
|
||||
|
@ -31,7 +31,7 @@ constexpr std::size_t UnlimitedAsyncQueueSize{0};
|
|||
|
||||
template <typename ItemType, /**< the type of Item to queue */
|
||||
std::size_t MaxSize = UnlimitedAsyncQueueSize, /**< maximum size for the queue */
|
||||
typename Allocator = std::allocator<ItemType>> /**< allocator the items */
|
||||
typename Allocator = std::allocator<ItemType>> /**< allocator for the items */
|
||||
|
||||
class AsyncQueue {
|
||||
public:
|
||||
|
@ -45,8 +45,6 @@ class AsyncQueue {
|
|||
|
||||
using Timeout = std::chrono::steady_clock::duration;
|
||||
|
||||
#define LOCKED std::unique_lock<std::mutex> lock(m_);
|
||||
|
||||
/**
|
||||
* Push an item to the end of the queue by moving it
|
||||
*
|
||||
|
@ -55,8 +53,7 @@ class AsyncQueue {
|
|||
*
|
||||
* @return true if the item was pushed; false otherwise.
|
||||
*/
|
||||
bool push(const value_type& item, Timeout timeout = {})
|
||||
{
|
||||
bool push(const value_type& item, Timeout timeout = {}) {
|
||||
return push(std::move(value_type(item)), timeout);
|
||||
}
|
||||
|
||||
|
@ -68,8 +65,7 @@ class AsyncQueue {
|
|||
*
|
||||
* @return true if the item was pushed; false otherwise.
|
||||
*/
|
||||
bool push(value_type&& item, Timeout timeout = {})
|
||||
{
|
||||
bool push(value_type&& item, Timeout timeout = {}) {
|
||||
std::unique_lock lock{m_};
|
||||
|
||||
if (!unlimited()) {
|
||||
|
@ -94,8 +90,7 @@ class AsyncQueue {
|
|||
*
|
||||
* @return true if an item was popped (into val), false otherwise.
|
||||
*/
|
||||
bool pop(value_type& val, Timeout timeout = {})
|
||||
{
|
||||
bool pop(value_type& val, Timeout timeout = {}) {
|
||||
std::unique_lock lock{m_};
|
||||
|
||||
if (timeout != Timeout{}) {
|
||||
|
@ -119,8 +114,7 @@ class AsyncQueue {
|
|||
* Clear the queue
|
||||
*
|
||||
*/
|
||||
void clear()
|
||||
{
|
||||
void clear() {
|
||||
std::unique_lock lock{m_};
|
||||
q_.clear();
|
||||
cv_full_.notify_one();
|
||||
|
@ -132,8 +126,7 @@ class AsyncQueue {
|
|||
*
|
||||
* @return the size
|
||||
*/
|
||||
size_type size() const
|
||||
{
|
||||
size_type size() const {
|
||||
std::unique_lock lock{m_};
|
||||
return q_.size();
|
||||
}
|
||||
|
@ -145,21 +138,14 @@ class AsyncQueue {
|
|||
*
|
||||
* @return the maximum size
|
||||
*/
|
||||
size_type max_size() const
|
||||
{
|
||||
if (unlimited())
|
||||
return q_.max_size();
|
||||
else
|
||||
return MaxSize;
|
||||
}
|
||||
size_type max_size() const { return unlimited() ? q_.max_size() : MaxSize; }
|
||||
|
||||
/**
|
||||
* Is the queue empty?
|
||||
*
|
||||
* @return true or false
|
||||
*/
|
||||
bool empty() const
|
||||
{
|
||||
bool empty() const {
|
||||
std::unique_lock lock{m_};
|
||||
return q_.empty();
|
||||
}
|
||||
|
@ -170,8 +156,7 @@ class AsyncQueue {
|
|||
*
|
||||
* @return true or false.
|
||||
*/
|
||||
bool full() const
|
||||
{
|
||||
bool full() const {
|
||||
if (unlimited())
|
||||
return false;
|
||||
|
||||
|
|
|
@ -51,9 +51,6 @@ validate(const CommandHandler::CommandInfoMap& cmap,
|
|||
const CommandHandler::CommandInfo& cmd_info,
|
||||
const Command& cmd)
|
||||
{
|
||||
if (g_test_verbose())
|
||||
std::cout << cmd.to_string(Sexp::Format::TypeInfo) << '\n';
|
||||
|
||||
// all required parameters must be present
|
||||
for (auto&& arg : cmd_info.args) {
|
||||
|
||||
|
@ -121,6 +118,7 @@ CommandHandler::invoke(const Command& cmd, bool do_validate) const
|
|||
}
|
||||
|
||||
|
||||
// LCOV_EXCL_START
|
||||
#ifdef BUILD_TESTS
|
||||
|
||||
#include "mu-test-utils.hh"
|
||||
|
@ -224,6 +222,10 @@ test_command_fail()
|
|||
g_assert_false(call(cmap, "(my-command2)"));
|
||||
g_assert_false(call(cmap, "(my-command :param1 123 :param2 123)"));
|
||||
g_assert_false(call(cmap, "(my-command :param1 \"hello\" :param2 \"123\")"));
|
||||
|
||||
g_assert_false(call(cmap, "(my-command"));
|
||||
|
||||
g_assert_false(!!Command::make_parse(R"((foo :bar 123 :cuux "456" :boo nil :bah))"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -245,3 +247,4 @@ main(int argc, char* argv[]) try {
|
|||
}
|
||||
|
||||
#endif /*BUILD_TESTS*/
|
||||
// LCOV_EXCL_STOP
|
||||
|
|
|
@ -47,9 +47,6 @@ namespace Mu {
|
|||
|
||||
struct Command: public Sexp {
|
||||
|
||||
using iterator = List::iterator;
|
||||
using const_iterator = List::const_iterator;
|
||||
|
||||
static Result<Command> make(Sexp&& sexp) try {
|
||||
return Ok(Command{std::move(sexp)});
|
||||
} catch (const Error& e) {
|
||||
|
|
|
@ -64,6 +64,8 @@ static bool is_a_tty{};
|
|||
static std::string hist_path;
|
||||
static size_t max_lines{};
|
||||
|
||||
// LCOV_EXCL_START
|
||||
|
||||
bool
|
||||
Mu::have_readline()
|
||||
{
|
||||
|
@ -133,3 +135,5 @@ Mu::save_line(const std::string& line)
|
|||
add_history(line.c_str());
|
||||
#endif /*HAVE_READLINE*/
|
||||
}
|
||||
|
||||
// LCOV_EXCL_STOP
|
||||
|
|
Loading…
Reference in New Issue