Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest git+https://github.com/llnl/clippy@master
# python -m pip install pytest git+https://github.com/llnl/clippy@master
python -m pip install pytest git+https://github.com/llnl/clippy@sbromberger/stream-stderr


- name: Install Boost
Expand Down Expand Up @@ -47,14 +48,15 @@ jobs:
# git clone https://github.com/LLNL/clippy-cpp --branch $GITHUB_HEAD_REF $TMPDIR

mkdir -p build
cd build && cmake -DBOOST_ROOT=$BOOST_ROOT .. && make && cd ..
cd build && cmake -DMODERN_CMAKE_BUILD_TESTING=ON -DBUILD_TESTING=ON -DBOOST_ROOT=$BOOST_ROOT .. && make && cd ..
ls -l build/test
BACKEND=$PWD/build/test
echo "BACKEND=$BACKEND" >> $GITHUB_ENV

- name: Run Python test framework
env:
CLIPPY_BACKEND_PATH: ${{ env.BACKEND }}
CLIPPY_BACKEND_PATH: ${{ github.workspace }}/build/test
# CLIPPY_BACKEND_PATH: ${{ env.BACKEND }}
run: |
echo "backend = $BACKEND"
echo "backend = $CLIPPY_BACKEND_PATH"
pytest .
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
/.cache
/**/build
/**/build.*
/.idea/
CMakeDoxyfile.in
CMakeDoxygenDefaults.cmake
Expand Down
3 changes: 0 additions & 3 deletions test/TestBag/insert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

#include "clippy/clippy.hpp"
#include <boost/json.hpp>
#include <iostream>

namespace boostjsn = boost::json;

static const std::string class_name = "ClippyBag";
static const std::string method_name = "insert";
Expand Down
5 changes: 2 additions & 3 deletions test/TestBag/remove_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
//
// SPDX-License-Identifier: MIT

#include <algorithm>
#include <boost/json.hpp>
#include <clippy/clippy.hpp>
#include <iostream>
#include <jsonlogic/src.hpp>
#include <list>
// #include <logic.hpp>
Expand Down Expand Up @@ -37,7 +35,8 @@ int main(int argc, char **argv) {
auto apply_jl = [&jlrule](int value) {
boostjsn::object data;
data["value"] = value;
return truthy(jlrule.apply(jsonlogic::json_accessor(std::move(data))));
auto res = jlrule.apply(jsonlogic::json_accessor(data));
return jsonlogic::unpack_value<bool>(res);
};

the_bag.remove_if(apply_jl);
Expand Down
3 changes: 3 additions & 0 deletions test/TestGraph/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
set(CMAKE_BUILD_TYPE Debug)


add_test(TestGraph __init__)
add_test(TestGraph __str__)
# add_test(TestGraph assign)
Expand Down
116 changes: 45 additions & 71 deletions test/TestGraph/where.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,67 @@
#include <vector>

#include "clippy/selector.hpp"
#include "jsonlogic/logic.hpp"
#include "testgraph.hpp"

template <typename M>
auto parse_where_expression(M& mvmap_, boost::json::object& expression,
boost::json::object& submission_data) {
std::cerr << " parse_where_expression: expression: " << expression
<< std::endl;
// std::cerr << " parse_where_expression: expression: " << expression
// << std::endl;
boost::json::object exp2(expression);

std::shared_ptr<jsonlogic::logic_rule> jlrule =
std::make_shared<jsonlogic::logic_rule>(
jsonlogic::create_logic(exp2["rule"]));
// std::cerr << "past create_logic\n";
auto vars = jlrule->variable_names();
// boost::json::object submission_data{};
std::vector<boost::json::string> vars;
// jsonlogic::any_expr expression_rule_;

// we use expression_rule_ (and expression_rule; see below) in order to avoid
// having to recompute this every time we call the lambda.
jsonlogic::logic_rule jlrule = jsonlogic::create_logic(exp2["rule"]);
// std::tie(expression_rule_, vars, std::ignore) =
// jsonlogic::create_logic(exp2["rule"]);

std::cerr << "parse_where: # of vars: " << vars.size() << std::endl;
for (const auto& var : vars) {
std::cerr << " apply_jl var dump: var: " << var << std::endl;
}
// this works around a deficiency in C++ compilers where
// unique pointers moved into a lambda cannot be moved into
// an std::function.
// jsonlogic::expr* rawexpr = expression_rule_.release();
// std::shared_ptr<jsonlogic::expr> expression_rule{rawexpr};
// std::shared_ptr<jsonlogic::logic_rule> jlshared{&jlrule};

auto apply_jl = [rule=std::move(jlrule), vars, &mvmap_,
// std::cerr << "parse_where: # of vars: " << vars.size() << std::endl;
// for (const auto& var : vars) {
// std::cerr << " apply_jl var dump: var: " << var << std::endl;
// }

auto apply_jl = [&expression, jlrule, &mvmap_,
&submission_data](mvmap::locator loc) mutable {
std::cerr << " apply_jl: # of vars: " << vars.size() << std::endl;
auto vars = jlrule->variable_names();
// std::cerr << " apply_jl: # of vars: " << vars.size() << std::endl;
for (const auto& var : vars) {
std::cerr << " apply_jl: var: " << var << std::endl;
// std::cerr << " apply_jl: var: " << var << std::endl;
auto var_sel = selector(std::string(var));
std::cerr << " apply_jl: var_sel = " << var_sel << std::endl;
// std::cerr << " apply_jl: var_sel = " << var_sel << std::endl;
// if (!var_sel.headeq("node")) {
// std::cerr << "selector is not a node selector; skipping." <<
// std::endl; continue;
// }
auto var_tail = var_sel.tail().value();
std::string var_str = std::string(var_sel);
std::cerr << " apply_jl: var: " << var_sel << std::endl;
// std::cerr << " apply_jl: var: " << var_sel << std::endl;
if (mvmap_.has_series(var_tail)) {
std::cerr << " apply_jl: has series: " << var_sel << std::endl;
// std::cerr << " apply_jl: has series: " << var_sel << std::endl;
auto val = mvmap_.get_as_variant(var_tail, loc);
if (val.has_value()) {
std::cerr << " apply_jl: val has value" << std::endl;
// std::cerr << " apply_jl: val has value" << std::endl;
std::visit(
[&submission_data, &loc, &var_str](auto&& v) {
submission_data[var_str] = boost::json::value(v);
std::cerr << " apply_jl: submission_data[" << var_str
<< "] = " << v << " at loc " << loc << "."
<< std::endl;
// std::cerr << " apply_jl: submission_data[" << var_str
// << "] = " << v << " at loc " << loc << "."
// << std::endl;
},
*val);
} else {
Expand All @@ -64,11 +79,13 @@ auto parse_where_expression(M& mvmap_, boost::json::object& expression,
std::cerr << " apply_jl: no series for " << var_sel << std::endl;
}
}
std::cerr << " apply_jl: submission_data: " << submission_data
<< std::endl;
jsonlogic::any_value res = rule.apply(jsonlogic::json_accessor(submission_data));
std::cerr << " apply_jl: res: " << res << std::endl;
return truthy(res);
// std::cerr << " apply_jl: submission_data: " << submission_data
// << std::endl;
auto res = jlrule->apply(jsonlogic::json_accessor(submission_data));
// jsonlogic::apply(
// *expression_rule, jsonlogic::data_accessor(submission_data));
// std::cerr << " apply_jl: res: " << res << std::endl;
return jsonlogic::unpack_value<bool>(res);
};

return apply_jl;
Expand All @@ -79,59 +96,16 @@ std::vector<testgraph::node_t> where_nodes(const testgraph::testgraph& g,
std::vector<testgraph::node_t> filtered_results;
// boost::json::object exp2(expression);

std::cerr << " where: expression: " << expression << std::endl;
// auto [_a /*unused*/, vars, _b /*unused*/] =
// jsonlogic::translateNode(exp2["rule"]);

// auto nodemap = g.nodemap();
// boost::json::object submission_data{};
// auto apply_jl = [&expression, &vars, &nodemap,
// &submission_data](testgraph::node_t key) {
// for (const auto& var : vars) {
// auto var_sel = selector(std::string(var));
// if (!var_sel.headeq("node")) {
// std::cerr << "selector is not a node selector; skipping." <<
// std::endl; continue;
// }
// auto var_tail = var_sel.tail().value();
// std::string var_str = std::string(var_sel);
// std::cerr << " apply_jl: var: " << var_sel << std::endl;
// if (nodemap.has_series(var_tail)) {
// std::cerr << " apply_jl: has series: " << var_sel << std::endl;
// auto val = nodemap.get_as_variant(var_tail, key);
// if (val.has_value()) {
// std::cerr << " apply_jl: val has value" << std::endl;
// std::visit(
// [&submission_data, &key, &var_str](auto&& v) {
// submission_data[var_str] = boost::json::value(v);
// std::cerr << " apply_jl: submission_data[" << var_str
// << "] = " << v << " at key " << key << "."
// << std::endl;
// },
// val.value());
// } else {
// std::cerr << " apply_jl: no value for " << var_sel << std::endl;
// submission_data[var_str] = boost::json::value();
// }
// } else {
// std::cerr << " apply_jl: no series for " << var_sel << std::endl;
// }
// }

// jsonlogic::any_expr res =
// jsonlogic::apply(expression["rule"], submission_data);
// std::cerr << " apply_jl: res: " << res << std::endl;
// return jsonlogic::unpack_value<bool>(res);
// };
// std::cerr << " where: expression: " << expression << std::endl;

auto nodemap = g.nodemap();
boost::json::object submission_data;
auto apply_jl = parse_where_expression(nodemap, expression, submission_data);
nodemap.for_all([&filtered_results, &apply_jl, &nodemap, &expression](
const auto& key, const auto& loc) {
std::cerr << " where for_all key: " << key << std::endl;
nodemap.for_all([&filtered_results, &apply_jl, &nodemap,
&expression](const auto &key, const auto &loc) {
// std::cerr << " where for_all key: " << key << std::endl;
if (apply_jl(loc)) {
std::cerr << " where: applied!" << std::endl;
// std::cerr << " where: applied!" << std::endl;
filtered_results.push_back(key);
}
});
Expand Down
2 changes: 0 additions & 2 deletions test/TestSet/remove_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
//
// SPDX-License-Identifier: MIT

#include <algorithm>
#include <boost/json.hpp>
#include <clippy/clippy.hpp>
#include <iostream>
#include <jsonlogic/src.hpp>
#include <set>

Expand Down
2 changes: 1 addition & 1 deletion test/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
llnl-clippy >= 0.4
llnl-clippy >= 0.4.2
pytest>=7,<8
Loading