mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-04-30 19:09:26 +08:00
Fix #690: Apply clang-format consistently with CI
Applied clang-format-19 to all source files to enforce consistent formatting according to the existing .clang-format configuration. Added auto-clang-format GitHub Actions workflow (from cpp-best-practices/cmake_template) that runs on pull requests to automatically format and commit any style violations going forward. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
bb06919061
commit
65cf24b1ed
23
.github/workflows/auto-clang-format.yml
vendored
Normal file
23
.github/workflows/auto-clang-format.yml
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
name: auto-clang-format
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: DoozyX/clang-format-lint-action@v0.20
|
||||
with:
|
||||
source: '.'
|
||||
exclude: './third_party ./external'
|
||||
extensions: 'h,cpp,hpp'
|
||||
clangFormatVersion: 19
|
||||
inplace: True
|
||||
- uses: EndBug/add-and-commit@v9
|
||||
with:
|
||||
author_name: Clang Robot
|
||||
author_email: robot@example.com
|
||||
message: ':art: Committing clang-format changes'
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@ -11,14 +11,14 @@
|
||||
#ifndef CHAISCRIPT_EMSCRIPTEN_EVAL_HPP_
|
||||
#define CHAISCRIPT_EMSCRIPTEN_EVAL_HPP_
|
||||
|
||||
#include <string>
|
||||
#include <chaiscript/chaiscript.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace detail {
|
||||
inline chaiscript::ChaiScript &get_chai_instance() {
|
||||
static chaiscript::ChaiScript chai;
|
||||
return chai;
|
||||
}
|
||||
inline chaiscript::ChaiScript &get_chai_instance() {
|
||||
static chaiscript::ChaiScript chai;
|
||||
return chai;
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
inline void chaiscript_eval(const std::string &input) {
|
||||
|
||||
@ -18,11 +18,11 @@
|
||||
|
||||
#include "dispatchkit/function_call.hpp"
|
||||
|
||||
//#include "dispatchkit/dispatchkit.hpp"
|
||||
// #include "dispatchkit/dispatchkit.hpp"
|
||||
#include "dispatchkit/bootstrap.hpp"
|
||||
#include "dispatchkit/bootstrap_stl.hpp"
|
||||
#include "dispatchkit/operators.hpp"
|
||||
//#include "dispatchkit/boxed_value.hpp"
|
||||
// #include "dispatchkit/boxed_value.hpp"
|
||||
#include "dispatchkit/register_function.hpp"
|
||||
#include "language/chaiscript_prelude.hpp"
|
||||
#include "utility/json_wrap.hpp"
|
||||
|
||||
@ -65,7 +65,6 @@ namespace chaiscript {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool is_explicit() const noexcept { return m_option_explicit; }
|
||||
|
||||
void set_explicit(const bool t_explicit) noexcept { m_option_explicit = t_explicit; }
|
||||
|
||||
@ -148,11 +148,11 @@ namespace chaiscript {
|
||||
};
|
||||
|
||||
/**
|
||||
* A Proxy_Function implementation designed for creating a new
|
||||
* Dynamic_Object
|
||||
* that is automatically guarded based on the first param based on the
|
||||
* param's type name
|
||||
*/
|
||||
* A Proxy_Function implementation designed for creating a new
|
||||
* Dynamic_Object
|
||||
* that is automatically guarded based on the first param based on the
|
||||
* param's type name
|
||||
*/
|
||||
class Dynamic_Object_Constructor final : public Proxy_Function_Base {
|
||||
public:
|
||||
Dynamic_Object_Constructor(std::string t_type_name, const Proxy_Function &t_func)
|
||||
|
||||
@ -64,7 +64,7 @@ namespace chaiscript::dispatch::detail {
|
||||
Function_Signature(Ret (Class::*f)(Param...) volatile &) -> Function_Signature<Ret, Function_Params<volatile Class &, Param...>, false, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) volatile &noexcept)
|
||||
Function_Signature(Ret (Class::*f)(Param...) volatile & noexcept)
|
||||
-> Function_Signature<Ret, Function_Params<volatile Class &, Param...>, true, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
@ -72,20 +72,20 @@ namespace chaiscript::dispatch::detail {
|
||||
-> Function_Signature<Ret, Function_Params<volatile const Class &, Param...>, false, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) volatile const &noexcept)
|
||||
Function_Signature(Ret (Class::*f)(Param...) volatile const & noexcept)
|
||||
-> Function_Signature<Ret, Function_Params<volatile const Class &, Param...>, true, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) &) -> Function_Signature<Ret, Function_Params<Class &, Param...>, false, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) &noexcept) -> Function_Signature<Ret, Function_Params<Class &, Param...>, true, true>;
|
||||
Function_Signature(Ret (Class::*f)(Param...) & noexcept) -> Function_Signature<Ret, Function_Params<Class &, Param...>, true, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) const &) -> Function_Signature<Ret, Function_Params<const Class &, Param...>, false, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) const &noexcept) -> Function_Signature<Ret, Function_Params<const Class &, Param...>, true, true>;
|
||||
Function_Signature(Ret (Class::*f)(Param...) const & noexcept) -> Function_Signature<Ret, Function_Params<const Class &, Param...>, true, true>;
|
||||
|
||||
// && reference specifier
|
||||
|
||||
@ -93,7 +93,7 @@ namespace chaiscript::dispatch::detail {
|
||||
Function_Signature(Ret (Class::*f)(Param...) volatile &&) -> Function_Signature<Ret, Function_Params<volatile Class &&, Param...>, false, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) volatile &&noexcept)
|
||||
Function_Signature(Ret (Class::*f)(Param...) volatile && noexcept)
|
||||
-> Function_Signature<Ret, Function_Params<volatile Class &&, Param...>, true, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
@ -101,20 +101,20 @@ namespace chaiscript::dispatch::detail {
|
||||
-> Function_Signature<Ret, Function_Params<volatile const Class &&, Param...>, false, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) volatile const &&noexcept)
|
||||
Function_Signature(Ret (Class::*f)(Param...) volatile const && noexcept)
|
||||
-> Function_Signature<Ret, Function_Params<volatile const Class &&, Param...>, true, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) &&) -> Function_Signature<Ret, Function_Params<Class &&, Param...>, false, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) &&noexcept) -> Function_Signature<Ret, Function_Params<Class &&, Param...>, true, true>;
|
||||
Function_Signature(Ret (Class::*f)(Param...) && noexcept) -> Function_Signature<Ret, Function_Params<Class &&, Param...>, true, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) const &&) -> Function_Signature<Ret, Function_Params<const Class &&, Param...>, false, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) const &&noexcept)
|
||||
Function_Signature(Ret (Class::*f)(Param...) const && noexcept)
|
||||
-> Function_Signature<Ret, Function_Params<const Class &&, Param...>, true, true>;
|
||||
|
||||
template<typename Ret, typename Class>
|
||||
|
||||
@ -170,8 +170,8 @@ namespace chaiscript {
|
||||
};
|
||||
|
||||
/**
|
||||
* Used internally for handling a return value from a Proxy_Function call
|
||||
*/
|
||||
* Used internally for handling a return value from a Proxy_Function call
|
||||
*/
|
||||
template<>
|
||||
struct Handle_Return<Boxed_Number> {
|
||||
static Boxed_Value handle(const Boxed_Number &r) noexcept { return r.bv; }
|
||||
@ -182,8 +182,8 @@ namespace chaiscript {
|
||||
};
|
||||
|
||||
/**
|
||||
* Used internally for handling a return value from a Proxy_Function call
|
||||
*/
|
||||
* Used internally for handling a return value from a Proxy_Function call
|
||||
*/
|
||||
template<>
|
||||
struct Handle_Return<void> {
|
||||
static Boxed_Value handle() { return void_var(); }
|
||||
|
||||
@ -165,13 +165,13 @@ namespace chaiscript {
|
||||
};
|
||||
|
||||
/**
|
||||
* Pure virtual base class for all Proxy_Function implementations
|
||||
* Proxy_Functions are a type erasure of type safe C++
|
||||
* function calls. At runtime parameter types are expected to be
|
||||
* tested against passed in types.
|
||||
* Dispatch_Engine only knows how to work with Proxy_Function, no other
|
||||
* function classes.
|
||||
*/
|
||||
* Pure virtual base class for all Proxy_Function implementations
|
||||
* Proxy_Functions are a type erasure of type safe C++
|
||||
* function calls. At runtime parameter types are expected to be
|
||||
* tested against passed in types.
|
||||
* Dispatch_Engine only knows how to work with Proxy_Function, no other
|
||||
* function classes.
|
||||
*/
|
||||
class Proxy_Function_Base {
|
||||
public:
|
||||
virtual ~Proxy_Function_Base() = default;
|
||||
|
||||
@ -32,9 +32,9 @@ namespace chaiscript {
|
||||
namespace chaiscript {
|
||||
namespace exception {
|
||||
/**
|
||||
* Exception thrown when there is a mismatch in number of
|
||||
* parameters during Proxy_Function execution
|
||||
*/
|
||||
* Exception thrown when there is a mismatch in number of
|
||||
* parameters during Proxy_Function execution
|
||||
*/
|
||||
struct arity_error : std::range_error {
|
||||
arity_error(int t_got, int t_expected)
|
||||
: std::range_error("Function dispatch arity mismatch")
|
||||
@ -54,9 +54,9 @@ namespace chaiscript {
|
||||
namespace dispatch {
|
||||
namespace detail {
|
||||
/**
|
||||
* Used by Proxy_Function_Impl to return a list of all param types
|
||||
* it contains.
|
||||
*/
|
||||
* Used by Proxy_Function_Impl to return a list of all param types
|
||||
* it contains.
|
||||
*/
|
||||
template<typename Ret, typename... Params>
|
||||
std::vector<Type_Info> build_param_type_list(Ret (*)(Params...)) {
|
||||
/// \note somehow this is responsible for a large part of the code generation
|
||||
@ -64,10 +64,10 @@ namespace chaiscript {
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by Proxy_Function_Impl to determine if it is equivalent to another
|
||||
* Proxy_Function_Impl object. This function is primarily used to prevent
|
||||
* registration of two functions with the exact same signatures
|
||||
*/
|
||||
* Used by Proxy_Function_Impl to determine if it is equivalent to another
|
||||
* Proxy_Function_Impl object. This function is primarily used to prevent
|
||||
* registration of two functions with the exact same signatures
|
||||
*/
|
||||
template<typename Ret, typename... Params>
|
||||
bool compare_types_cast(Ret (*)(Params...), const chaiscript::Function_Params ¶ms, const Type_Conversions_State &t_conversions) noexcept {
|
||||
try {
|
||||
|
||||
@ -542,9 +542,8 @@ namespace chaiscript {
|
||||
= detail::Cast_Helper<const std::pair<Boxed_Value, Boxed_Value> &>::cast(t_bv, nullptr);
|
||||
|
||||
auto pair = std::make_pair(
|
||||
detail::Cast_Helper<Left>::cast(from_pair.first, nullptr),
|
||||
detail::Cast_Helper<Right>::cast(from_pair.second, nullptr)
|
||||
);
|
||||
detail::Cast_Helper<Left>::cast(from_pair.first, nullptr),
|
||||
detail::Cast_Helper<Right>::cast(from_pair.second, nullptr));
|
||||
|
||||
return Boxed_Value(std::move(pair));
|
||||
};
|
||||
|
||||
@ -593,13 +593,13 @@ namespace chaiscript {
|
||||
|
||||
} // namespace exception
|
||||
|
||||
//static
|
||||
// static
|
||||
bool AST_Node::get_bool_condition(const Boxed_Value &t_bv, const chaiscript::detail::Dispatch_State &t_ss) {
|
||||
try {
|
||||
return t_ss->boxed_cast<bool>(t_bv);
|
||||
} catch (const exception::bad_boxed_cast &) {
|
||||
throw exception::eval_error("Condition not boolean");
|
||||
}
|
||||
try {
|
||||
return t_ss->boxed_cast<bool>(t_bv);
|
||||
} catch (const exception::bad_boxed_cast &) {
|
||||
throw exception::eval_error("Condition not boolean");
|
||||
}
|
||||
}
|
||||
|
||||
namespace parser {
|
||||
|
||||
@ -136,8 +136,9 @@ namespace chaiscript {
|
||||
m_engine.add(fun([this](const std::string &s) { m_print_handler(s + "\n"); }), "println_string");
|
||||
|
||||
m_engine.add(fun([this](const std::function<void(const std::string &)> &t_handler) {
|
||||
m_print_handler = t_handler;
|
||||
}), "set_print_handler");
|
||||
m_print_handler = t_handler;
|
||||
}),
|
||||
"set_print_handler");
|
||||
|
||||
m_engine.add(fun([this]() { m_engine.dump_system(); }), "dump_system");
|
||||
m_engine.add(fun([this](const Boxed_Value &t_bv) { m_engine.dump_object(t_bv); }), "dump_object");
|
||||
@ -278,7 +279,6 @@ namespace chaiscript {
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/// \brief Set a custom handler for print output, used by both print_string and println_string
|
||||
/// \param[in] t_handler Function to call with the string to print
|
||||
void set_print_handler(std::function<void(const std::string &)> t_handler) {
|
||||
@ -287,7 +287,7 @@ namespace chaiscript {
|
||||
|
||||
/// \brief Virtual destructor for ChaiScript
|
||||
virtual ~ChaiScript_Basic() = default;
|
||||
|
||||
|
||||
/// \brief Constructor for ChaiScript
|
||||
/// \param[in] t_lib Standard library to apply to this ChaiScript instance
|
||||
/// \param[in] t_modulepaths Vector of paths to search when attempting to load a binary module
|
||||
|
||||
@ -10,13 +10,13 @@
|
||||
#ifndef CHAISCRIPT_EVAL_HPP_
|
||||
#define CHAISCRIPT_EVAL_HPP_
|
||||
|
||||
#include <algorithm>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -389,11 +389,11 @@ namespace chaiscript {
|
||||
|
||||
// static and public so we can use this to process Switch_AST_Node case equality
|
||||
static Boxed_Value do_oper(const chaiscript::detail::Dispatch_State &t_ss,
|
||||
Operators::Opers t_oper,
|
||||
const std::string &t_oper_string,
|
||||
const Boxed_Value &t_lhs,
|
||||
const Boxed_Value &t_rhs,
|
||||
std::atomic_uint_fast32_t &t_loc) {
|
||||
Operators::Opers t_oper,
|
||||
const std::string &t_oper_string,
|
||||
const Boxed_Value &t_lhs,
|
||||
const Boxed_Value &t_rhs,
|
||||
std::atomic_uint_fast32_t &t_loc) {
|
||||
try {
|
||||
if (t_oper != Operators::Opers::invalid && t_lhs.get_type_info().is_arithmetic() && t_rhs.get_type_info().is_arithmetic()) {
|
||||
// If it's an arithmetic operation we want to short circuit dispatch
|
||||
@ -1271,8 +1271,7 @@ namespace chaiscript {
|
||||
const auto process_statement = [&](const AST_Node_Impl<T> &stmt) {
|
||||
if (stmt.identifier == AST_Node_Type::Def) {
|
||||
const auto &def_node = static_cast<const Def_AST_Node<T> &>(stmt);
|
||||
target_ns[def_node.children[0]->text] =
|
||||
Boxed_Value(Def_AST_Node<T>::make_proxy_function(def_node, t_ss));
|
||||
target_ns[def_node.children[0]->text] = Boxed_Value(Def_AST_Node<T>::make_proxy_function(def_node, t_ss));
|
||||
} else if (stmt.identifier == AST_Node_Type::Assign_Decl
|
||||
|| stmt.identifier == AST_Node_Type::Const_Assign_Decl) {
|
||||
const auto &var_name = stmt.children[0]->text;
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#ifndef CHAISCRIPT_SIMPLEJSON_WRAP_HPP
|
||||
#define CHAISCRIPT_SIMPLEJSON_WRAP_HPP
|
||||
|
||||
#include "json.hpp"
|
||||
#include "../dispatchkit/dynamic_object.hpp"
|
||||
#include "json.hpp"
|
||||
|
||||
namespace chaiscript {
|
||||
class json_wrap {
|
||||
|
||||
25270
unittests/catch.hpp
25270
unittests/catch.hpp
File diff suppressed because it is too large
Load Diff
@ -605,7 +605,9 @@ TEST_CASE("Utility_Test utility class wrapper for enum") {
|
||||
}
|
||||
|
||||
// Issue #601: add_class for enums should work directly with ChaiScript reference
|
||||
enum class Issue601_EnumClass { Apple, Banana, Pear };
|
||||
enum class Issue601_EnumClass { Apple,
|
||||
Banana,
|
||||
Pear };
|
||||
|
||||
TEST_CASE("Issue 601: add_class enum with ChaiScript reference directly") {
|
||||
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser());
|
||||
@ -626,7 +628,9 @@ TEST_CASE("Issue 601: add_class enum with ChaiScript reference directly") {
|
||||
}
|
||||
|
||||
// Also test non-scoped enum directly with ChaiScript reference
|
||||
enum Issue601_PlainEnum { Issue601_Red = 0, Issue601_Green = 1, Issue601_Blue = 2 };
|
||||
enum Issue601_PlainEnum { Issue601_Red = 0,
|
||||
Issue601_Green = 1,
|
||||
Issue601_Blue = 2 };
|
||||
|
||||
TEST_CASE("Issue 601: add_class plain enum with ChaiScript reference directly") {
|
||||
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser());
|
||||
@ -952,7 +956,7 @@ TEST_CASE("Pair conversions") {
|
||||
const auto p = chai.eval<std::pair<std::string, std::string>>(R"cs(
|
||||
Pair("chai", "script");
|
||||
)cs");
|
||||
CHECK(p.first == std::string{ "chai" });
|
||||
CHECK(p.first == std::string{"chai"});
|
||||
CHECK(p.second == "script");
|
||||
}
|
||||
{
|
||||
@ -1532,7 +1536,8 @@ TEST_CASE("ChaiScript default has all functions") {
|
||||
TEST_CASE("Issue #421 - Switch with type_conversion does not compare destroyed objects") {
|
||||
struct MyType {
|
||||
int value;
|
||||
explicit MyType(int v) : value(v) {}
|
||||
explicit MyType(int v)
|
||||
: value(v) {}
|
||||
};
|
||||
|
||||
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser());
|
||||
@ -1755,51 +1760,52 @@ TEST_CASE("push_back on script vector with vector_conversion") {
|
||||
// Register a C++ function that accepts the converted type, so we can
|
||||
// verify that vector_conversion actually works for passing vectors
|
||||
chai.add(chaiscript::fun([](const std::vector<std::string> &v) -> std::string {
|
||||
std::string result;
|
||||
for (const auto &s : v) {
|
||||
if (!result.empty()) { result += ","; }
|
||||
result += s;
|
||||
}
|
||||
return result;
|
||||
}), "join_strings");
|
||||
std::string result;
|
||||
for (const auto &s : v) {
|
||||
if (!result.empty()) {
|
||||
result += ",";
|
||||
}
|
||||
result += s;
|
||||
}
|
||||
return result;
|
||||
}),
|
||||
"join_strings");
|
||||
|
||||
// push_back on an empty script-created vector must be visible
|
||||
CHECK(chai.eval<bool>(
|
||||
"auto x = [];"
|
||||
"x.push_back(\"Hello\");"
|
||||
"x.size() == 1"
|
||||
));
|
||||
"auto x = [];"
|
||||
"x.push_back(\"Hello\");"
|
||||
"x.size() == 1"));
|
||||
|
||||
// push_back on a vector with initial elements must grow correctly
|
||||
CHECK(chai.eval<bool>(
|
||||
"auto y = [\"a\", \"b\"];"
|
||||
"y.push_back(\"c\");"
|
||||
"y.push_back(\"d\");"
|
||||
"y.size() == 4"
|
||||
));
|
||||
"auto y = [\"a\", \"b\"];"
|
||||
"y.push_back(\"c\");"
|
||||
"y.push_back(\"d\");"
|
||||
"y.size() == 4"));
|
||||
|
||||
// Verify the actual content is preserved after push_back
|
||||
CHECK(chai.eval<std::string>(
|
||||
"auto z = [];"
|
||||
"z.push_back(\"World\");"
|
||||
"z[0]"
|
||||
) == "World");
|
||||
"auto z = [];"
|
||||
"z.push_back(\"World\");"
|
||||
"z[0]")
|
||||
== "World");
|
||||
|
||||
// Round-trip: build a vector in script, push_back elements, then pass it
|
||||
// to a C++ function via vector_conversion and verify the contents
|
||||
CHECK(chai.eval<std::string>(
|
||||
"auto v = [\"one\", \"two\"];"
|
||||
"v.push_back(\"three\");"
|
||||
"join_strings(v)"
|
||||
) == "one,two,three");
|
||||
"auto v = [\"one\", \"two\"];"
|
||||
"v.push_back(\"three\");"
|
||||
"join_strings(v)")
|
||||
== "one,two,three");
|
||||
|
||||
// Verify conversion works on a freshly created vector too
|
||||
CHECK(chai.eval<std::string>(
|
||||
"auto w = [];"
|
||||
"w.push_back(\"hello\");"
|
||||
"w.push_back(\"world\");"
|
||||
"join_strings(w)"
|
||||
) == "hello,world");
|
||||
"auto w = [];"
|
||||
"w.push_back(\"hello\");"
|
||||
"w.push_back(\"world\");"
|
||||
"join_strings(w)")
|
||||
== "hello,world");
|
||||
}
|
||||
|
||||
// Regression test for issue #607: AST_Node_Trace must be a complete type
|
||||
@ -1924,20 +1930,23 @@ TEST_CASE("Namespace block rejects non-declaration statements") {
|
||||
namespace bad {
|
||||
1 + 2
|
||||
}
|
||||
)"), chaiscript::exception::eval_error);
|
||||
)"),
|
||||
chaiscript::exception::eval_error);
|
||||
|
||||
CHECK_THROWS_AS(chai.eval(R"(
|
||||
namespace bad {
|
||||
print("hello")
|
||||
}
|
||||
)"), chaiscript::exception::eval_error);
|
||||
)"),
|
||||
chaiscript::exception::eval_error);
|
||||
|
||||
CHECK_THROWS_AS(chai.eval(R"(
|
||||
var x = 5
|
||||
namespace bad {
|
||||
x = 10
|
||||
}
|
||||
)"), chaiscript::exception::eval_error);
|
||||
)"),
|
||||
chaiscript::exception::eval_error);
|
||||
}
|
||||
|
||||
TEST_CASE("C++ runtime_error thrown from registered function is catchable in ChaiScript") {
|
||||
@ -2023,7 +2032,8 @@ TEST_CASE("Typed catch with no match propagates exception") {
|
||||
catch(string e) {
|
||||
// wrong type, should not match
|
||||
}
|
||||
)"), chaiscript::Boxed_Value);
|
||||
)"),
|
||||
chaiscript::Boxed_Value);
|
||||
}
|
||||
|
||||
TEST_CASE("Typed catch with no match still runs finally block") {
|
||||
@ -2040,7 +2050,8 @@ TEST_CASE("Typed catch with no match still runs finally block") {
|
||||
finally {
|
||||
finally_ran = true
|
||||
}
|
||||
)"), chaiscript::Boxed_Value);
|
||||
)"),
|
||||
chaiscript::Boxed_Value);
|
||||
|
||||
CHECK(chai.eval<bool>("finally_ran") == true);
|
||||
}
|
||||
@ -2049,13 +2060,18 @@ TEST_CASE("Multiple C++ exception types from registered functions") {
|
||||
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser());
|
||||
|
||||
chai.add(chaiscript::fun([](int which) -> int {
|
||||
switch (which) {
|
||||
case 0: throw std::runtime_error("runtime");
|
||||
case 1: throw std::out_of_range("range");
|
||||
case 2: throw std::logic_error("logic");
|
||||
default: return which;
|
||||
}
|
||||
}), "cpp_multi_throw");
|
||||
switch (which) {
|
||||
case 0:
|
||||
throw std::runtime_error("runtime");
|
||||
case 1:
|
||||
throw std::out_of_range("range");
|
||||
case 2:
|
||||
throw std::logic_error("logic");
|
||||
default:
|
||||
return which;
|
||||
}
|
||||
}),
|
||||
"cpp_multi_throw");
|
||||
|
||||
CHECK(chai.eval<int>(R"(
|
||||
var catch_count = 0
|
||||
@ -2083,8 +2099,9 @@ TEST_CASE("Exception from C++ binary operator is catchable in ChaiScript") {
|
||||
chai.add(chaiscript::user_type<ThrowingType>(), "ThrowingType");
|
||||
chai.add(chaiscript::constructor<ThrowingType(int)>(), "ThrowingType");
|
||||
chai.add(chaiscript::fun([](const ThrowingType &, const ThrowingType &) -> ThrowingType {
|
||||
throw std::runtime_error("cpp operator+ threw");
|
||||
}), "+");
|
||||
throw std::runtime_error("cpp operator+ threw");
|
||||
}),
|
||||
"+");
|
||||
|
||||
CHECK(chai.eval<bool>(R"(
|
||||
var caught = false
|
||||
@ -2110,9 +2127,12 @@ TEST_CASE("Exception from C++ [] operator is catchable in ChaiScript") {
|
||||
chai.add(chaiscript::user_type<IndexableType>(), "IndexableType");
|
||||
chai.add(chaiscript::constructor<IndexableType(int)>(), "IndexableType");
|
||||
chai.add(chaiscript::fun([](const IndexableType &, int idx) -> int {
|
||||
if (idx < 0) { throw std::out_of_range("negative index"); }
|
||||
return idx;
|
||||
}), "[]");
|
||||
if (idx < 0) {
|
||||
throw std::out_of_range("negative index");
|
||||
}
|
||||
return idx;
|
||||
}),
|
||||
"[]");
|
||||
|
||||
CHECK(chai.eval<int>("var obj = IndexableType(0); obj[5]") == 5);
|
||||
|
||||
|
||||
@ -9,9 +9,9 @@
|
||||
#define CHAISCRIPT_NO_DYNLOAD
|
||||
#endif
|
||||
|
||||
#include <chaiscript/chaiscript.hpp>
|
||||
#include "../emscripten/chaiscript_eval.hpp"
|
||||
#include <cassert>
|
||||
#include <chaiscript/chaiscript.hpp>
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
|
||||
@ -10,9 +10,9 @@
|
||||
#define CHAISCRIPT_NO_DYNLOAD
|
||||
#endif
|
||||
|
||||
#include <chaiscript/chaiscript.hpp>
|
||||
#include "../emscripten/chaiscript_eval.hpp"
|
||||
#include <cassert>
|
||||
#include <chaiscript/chaiscript.hpp>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
@ -5,8 +5,8 @@
|
||||
|
||||
Multi_Test_Chai::Multi_Test_Chai()
|
||||
: m_chai(new chaiscript::ChaiScript_Basic(
|
||||
chaiscript::Std_Lib::library(),
|
||||
std::make_unique<chaiscript::parser::ChaiScript_Parser<chaiscript::eval::Noop_Tracer, chaiscript::optimizer::Optimizer_Default>>())) {
|
||||
chaiscript::Std_Lib::library(),
|
||||
std::make_unique<chaiscript::parser::ChaiScript_Parser<chaiscript::eval::Noop_Tracer, chaiscript::optimizer::Optimizer_Default>>())) {
|
||||
}
|
||||
|
||||
std::shared_ptr<chaiscript::ChaiScript_Basic> Multi_Test_Chai::get_chai() {
|
||||
|
||||
@ -31,14 +31,30 @@ TEST_CASE("Type_Info objects generate expected results") {
|
||||
CHECK(ti.is_arithmetic() == t_is_arithmetic);
|
||||
};
|
||||
|
||||
SECTION("void") { test_type(chaiscript::user_type<void>(), false, false, false, true, false, false); }
|
||||
SECTION("const int") { test_type(chaiscript::user_type<const int>(), true, false, false, false, false, true); }
|
||||
SECTION("const int &") { test_type(chaiscript::user_type<const int &>(), true, false, true, false, false, true); }
|
||||
SECTION("int") { test_type(chaiscript::user_type<int>(), false, false, false, false, false, true); }
|
||||
SECTION("int *") { test_type(chaiscript::user_type<int *>(), false, true, false, false, false, false); }
|
||||
SECTION("const int *") { test_type(chaiscript::user_type<const int *>(), true, true, false, false, false, false); }
|
||||
SECTION("const bool &") { test_type(chaiscript::user_type<const bool &>(), true, false, true, false, false, false); }
|
||||
SECTION("default") { test_type(chaiscript::Type_Info(), false, false, false, false, true, false); }
|
||||
SECTION("void") {
|
||||
test_type(chaiscript::user_type<void>(), false, false, false, true, false, false);
|
||||
}
|
||||
SECTION("const int") {
|
||||
test_type(chaiscript::user_type<const int>(), true, false, false, false, false, true);
|
||||
}
|
||||
SECTION("const int &") {
|
||||
test_type(chaiscript::user_type<const int &>(), true, false, true, false, false, true);
|
||||
}
|
||||
SECTION("int") {
|
||||
test_type(chaiscript::user_type<int>(), false, false, false, false, false, true);
|
||||
}
|
||||
SECTION("int *") {
|
||||
test_type(chaiscript::user_type<int *>(), false, true, false, false, false, false);
|
||||
}
|
||||
SECTION("const int *") {
|
||||
test_type(chaiscript::user_type<const int *>(), true, true, false, false, false, false);
|
||||
}
|
||||
SECTION("const bool &") {
|
||||
test_type(chaiscript::user_type<const bool &>(), true, false, true, false, false, false);
|
||||
}
|
||||
SECTION("default") {
|
||||
test_type(chaiscript::Type_Info(), false, false, false, false, true, false);
|
||||
}
|
||||
|
||||
std::cout << "Size of Type_Info " << sizeof(chaiscript::Type_Info) << '\n';
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user