Skip to content

Commit

Permalink
apply clang-format to the code
Browse files Browse the repository at this point in the history
  • Loading branch information
pmed committed Sep 26, 2021
1 parent ae35d2c commit f6fe558
Show file tree
Hide file tree
Showing 28 changed files with 283 additions and 211 deletions.
2 changes: 1 addition & 1 deletion plugins/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void log(v8::FunctionCallbackInfo<v8::Value> const& args)
{
if (i > 0) std::cout << ' ';
v8::String::Utf8Value const str(args.GetIsolate(), args[i]);
std::cout << *str;
std::cout << *str;
}
std::cout << std::endl;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class file_reader : public file_base

v8::Local<v8::Value> getline(v8::Isolate* isolate)
{
if ( stream_.good() && ! stream_.eof())
if (stream_.good() && !stream_.eof())
{
std::string line;
std::getline(stream_, line);
Expand Down
32 changes: 16 additions & 16 deletions test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ void run_tests()
void test_object();
void test_json();

std::pair<char const*, void(*)()> tests[] =
std::pair<char const*, void (*)()> tests[] =
{
{ "test_utility", test_utility },
{ "test_context", test_context },
{ "test_convert", test_convert },
{ "test_throw_ex", test_throw_ex },
{ "test_function", test_function },
{ "test_ptr_traits", test_ptr_traits },
{ "test_call_v8", test_call_v8 },
{ "test_call_from_v8", test_call_from_v8 },
{ "test_module", test_module },
{ "test_class", test_class },
{ "test_property", test_property },
{ "test_object", test_object },
{ "test_json", test_json },
{"test_utility", test_utility},
{"test_context", test_context},
{"test_convert", test_convert},
{"test_throw_ex", test_throw_ex},
{"test_function", test_function},
{"test_ptr_traits", test_ptr_traits},
{"test_call_v8", test_call_v8},
{"test_call_from_v8", test_call_from_v8},
{"test_module", test_module},
{"test_class", test_class},
{"test_property", test_property},
{"test_object", test_object},
{"test_json", test_json},
};

for (auto const& test : tests)
Expand All @@ -69,7 +69,7 @@ void run_tests()
}
}

int main(int argc, char const * argv[])
int main(int argc, char const* argv[])
{
std::vector<std::string> scripts;
std::string lib_path;
Expand Down Expand Up @@ -139,7 +139,7 @@ int main(int argc, char const * argv[])
context.run_file(script);
}
}
catch (std::exception & ex)
catch (std::exception const& ex)
{
std::cerr << ex.what() << std::endl;
result = EXIT_FAILURE;
Expand Down
2 changes: 1 addition & 1 deletion test/test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ std::ostream& operator<<(std::ostream& os, std::tuple<Ts...> const& tuple)
{
bool first = true;
os << '(';
((os << (first? (first = false, "") : ", ") << elems),...);
((os << (first ? (first = false, "") : ", ") << elems), ...);
os << ')';
}, tuple);
return os;
Expand Down
34 changes: 16 additions & 18 deletions test/test_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ struct Y : X

int Y::instance_count = 0;

struct Z {};
struct Z
{
};

template<typename Traits>
static int extern_fun(v8::FunctionCallbackInfo<v8::Value> const& args)
Expand Down Expand Up @@ -168,9 +170,9 @@ void test_class_()
.template ctor<v8::FunctionCallbackInfo<v8::Value> const&>(X_ctor)
.const_("konst", 99)
.var("var", &X::var)
//TODO: static property definition works only at the end of class_ declaration!
// .static_("my_static_var", 1)
// .static_("my_static_const_var", 42, true)
//TODO: static property definition works only at the end of class_ declaration!
//.static_("my_static_var", 1)
//.static_("my_static_const_var", 42, true)
.property("rprop", &X::get)
.property("wprop", &X::get, &X::set)
.property("wprop2", static_cast<x_prop_get>(&X::prop), static_cast<x_prop_set>(&X::prop))
Expand Down Expand Up @@ -205,15 +207,14 @@ void test_class_()
.template inherit<X>()
.template ctor<int>()
.function("useX", &Y::useX)
.function("useX_ptr", &Y::useX_ptr<Traits>)
;
.function("useX_ptr", &Y::useX_ptr<Traits>);

auto Y_class_find = v8pp::class_<Y, Traits>::extend(isolate);
Y_class_find.function("toJSON", [](const v8::FunctionCallbackInfo<v8::Value>& args)
{
bool const with_functions = true;
args.GetReturnValue().Set(v8pp::json_object(args.GetIsolate(), args.This(), with_functions));
});
{
bool const with_functions = true;
args.GetReturnValue().Set(v8pp::json_object(args.GetIsolate(), args.This(), with_functions));
});

check_ex<std::runtime_error>("already wrapped class X", [isolate]()
{
Expand Down Expand Up @@ -289,19 +290,16 @@ void test_class_()

auto y1 = Traits::template create<Y>(-1);

v8::Local<v8::Object> y1_obj =
v8pp::class_<Y, Traits>::reference_external(context.isolate(), y1);
v8::Local<v8::Object> y1_obj = v8pp::class_<Y, Traits>::reference_external(context.isolate(), y1);
check("y1", v8pp::from_v8<decltype(y1)>(isolate, y1_obj) == y1);
check("y1_obj", v8pp::to_v8(isolate, y1) == y1_obj);

auto y2 = Traits::template create<Y>(-2);
v8::Local<v8::Object> y2_obj =
v8pp::class_<Y, Traits>::import_external(context.isolate(), y2);
v8::Local<v8::Object> y2_obj = v8pp::class_<Y, Traits>::import_external(context.isolate(), y2);
check("y2", v8pp::from_v8<decltype(y2)>(isolate, y2_obj) == y2);
check("y2_obj", v8pp::to_v8(isolate, y2) == y2_obj);

v8::Local<v8::Object> y3_obj =
v8pp::class_<Y, Traits>::create_object(context.isolate(), -3);
v8::Local<v8::Object> y3_obj = v8pp::class_<Y, Traits>::create_object(context.isolate(), -3);
auto y3 = v8pp::class_<Y, Traits>::unwrap_object(isolate, y3_obj);
check("y3", v8pp::from_v8<decltype(y3)>(isolate, y3_obj) == y3);
check("y3_obj", v8pp::to_v8(isolate, y3) == y3_obj);
Expand Down Expand Up @@ -414,7 +412,6 @@ void test_multiple_inheritance()
.property("H", &C::h, &C::set_h)
;


context.class_("C", C_class);
check_eq("get attributes", run_script<int>(context, "c = new C(); c.xA + c.xB + c.xC"), 1 + 2 + 3);
check_eq("set attributes", run_script<int>(context,
Expand Down Expand Up @@ -477,7 +474,8 @@ void test_auto_wrap_objects()
X_class
.template ctor<int>()
.auto_wrap_objects(true)
.property("x", &X::get_x);
.property("x", &X::get_x)
;

auto f = [](int x) { return X(x); };

Expand Down
2 changes: 1 addition & 1 deletion test/test_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void test_context()

check_eq("run_script with explicit context", r, 42);
}

{
// Move constuctor allows to set up context inside function
// also it allows to move class with v8pp::context as a member value
Expand Down
14 changes: 7 additions & 7 deletions test/test_convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ struct convert<person>
obj->Get(isolate->GetCurrentContext(), v8pp::to_v8(isolate, "name")).ToLocalChecked());
result.age = v8pp::from_v8<int>(isolate,
obj->Get(isolate->GetCurrentContext(), v8pp::to_v8(isolate, "age")).ToLocalChecked());

/* Simpler after #include <v8pp/object.hpp>
get_option(isolate, obj, "name", result.name);
get_option(isolate, obj, "age", result.age);
Expand All @@ -135,7 +135,7 @@ struct convert<person>
}
};

} // v8pp
} // namespace v8pp

void test_convert_user_type(v8::Isolate* isolate)
{
Expand Down Expand Up @@ -253,7 +253,7 @@ void check_range(v8::Isolate* isolate)
template<typename... Ts>
void check_ranges(v8::Isolate* isolate)
{
(check_range<Ts>(isolate),...);
(check_range<Ts>(isolate), ...);
}

struct U
Expand Down Expand Up @@ -370,7 +370,7 @@ void test_convert()
test_conv(isolate, 2.2);
test_conv(isolate, true);

enum old_enum { A = 1, B = 5, C = - 1 };
enum old_enum { A = 1, B = 5, C = -1 };
test_conv(isolate, B);

enum class new_enum { X = 'a', Y = 'b', Z = 'c' };
Expand All @@ -396,9 +396,9 @@ void test_convert()
});

test_conv(isolate, std::map<char, int>{ { 'a', 1 }, { 'b', 2 }, { 'c', 3 } });
test_conv(isolate, std::multimap<int, int>{ { 1, -1 }, { 2, -2 }});
test_conv(isolate, std::unordered_map<char, std::string>{ { 'x', "1" }, { 'y', "2" }});
test_conv(isolate, std::unordered_multimap<std::string, int>{ { "a", 1 }, { "b", 2 }});
test_conv(isolate, std::multimap<int, int>{ { 1, -1 }, { 2, -2 } });
test_conv(isolate, std::unordered_map<char, std::string>{ { 'x', "1" }, { 'y', "2" } });
test_conv(isolate, std::unordered_multimap<std::string, int>{ { "a", 1 }, { "b", 2 } });

check_eq("initializer list to array",
v8pp::from_v8<std::vector<int>>(isolate, v8pp::to_v8(isolate, { 1, 2, 3 })), vector);
Expand Down
6 changes: 3 additions & 3 deletions test/test_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "test.hpp"

static int f(int const& x) { return x; }
static std::string g(char const* s) { return s? s : ""; }
static std::string g(char const* s) { return s ? s : ""; }
static int h(v8::Isolate*, int x, int y) { return x + y; }

struct X
Expand Down Expand Up @@ -42,14 +42,14 @@ void test_function()
moveonly() = default;
moveonly(moveonly const&) = delete;
moveonly& operator=(moveonly const&) = delete;
moveonly(moveonly &&) = default;
moveonly(moveonly&&) = default;
moveonly& operator=(moveonly&&) = default;
};
moveonly z;
context.function("lambda", [x, y, z = std::move(z)](int a) { return a + x + y + z.v; });
check_eq("lambda", run_script<int>(context, "lambda(3)"), 9);

auto lambda2 = [](){ return 99; };
auto lambda2 = []() { return 99; };
//TODO: static_assert(v8pp::detail::external_data::is_bitcast_allowed<decltype(lambda2)>::value);

context.function("lambda2", lambda2);
Expand Down
1 change: 1 addition & 0 deletions test/test_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void test_module()
.property("rprop", get_x)
.property("wprop", get_x, set_x)
;

context.module("module", module);

check_eq("module.consts.bool",
Expand Down
6 changes: 2 additions & 4 deletions test/test_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ void test_object()
check("obj.pi", fabs(pi - 3.1415926) < 10e-6);

v8::Local<v8::Object> sub;
check("get obj.sub", v8pp::get_option(isolate, obj, "sub", sub)
&& sub->IsObject());
check("get obj.sub", v8pp::get_option(isolate, obj, "sub", sub) && sub->IsObject());

context.run_script("test = { test : function() { return 1; } }");
obj = isolate->GetCurrentContext()->Global();
v8::Local<v8::Function> fun;
check("test.test", v8pp::get_option(isolate, obj, "test.test", fun)
&& fun->IsFunction());
check("test.test", v8pp::get_option(isolate, obj, "test.test", fun) && fun->IsFunction());
}
6 changes: 3 additions & 3 deletions test/test_property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ static_assert(is_getter<decltype(&X::get1), 0>, "getter member function");
static_assert(is_getter<decltype(&external_get1), 1>, "getter external function");

static_assert(is_setter<decltype(&set1), 0>, "setter function");
static_assert(is_setter<decltype(&X::set1), 0>, "setter member function");
static_assert(is_setter<decltype(&X::set1), 0>, "setter member function");
static_assert(is_setter<decltype(&external_set1), 1>, "setter external function");

static_assert(is_isolate_getter<decltype(&get2), 0>, "isolate getter function");
static_assert(is_isolate_getter<decltype(&X::get2), 0>, "isolate getter member function");
static_assert(is_isolate_getter<decltype(&X::get2), 0>, "isolate getter member function");
static_assert(is_isolate_getter<decltype(&external_get2), 1>, "isolate getter external function");

static_assert(is_isolate_setter<decltype(&set2), 0>, "isolate setter function");
Expand All @@ -80,7 +80,7 @@ void test_property(Get&& get, Set&& set)
check_eq("prop setter", prop.setter, set);
}

} // namespace {
} // namespace

void test_property()
{
Expand Down
6 changes: 4 additions & 2 deletions test/test_ptr_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ struct X
ctor_types |= 0x01;
}

X(int) {
X(int)
{
++ctor_count;
ctor_types |= 0x02;
}
Expand Down Expand Up @@ -54,6 +55,7 @@ class Y
public:
static Y* make(int) { return new Y; }
static void done(Y* y) { delete y; }

private:
Y() {}
~Y() {}
Expand Down Expand Up @@ -99,7 +101,7 @@ struct Y_shared_ptr_traits : v8pp::shared_ptr_traits
}
};

template<typename T, typename Traits, typename ...Args>
template<typename T, typename Traits, typename... Args>
void test_create_destroy_(Args&&... args)
{
auto obj = Traits::template create<T>(std::forward<Args>(args)...);
Expand Down
7 changes: 3 additions & 4 deletions test/test_throw_ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace {

void test(v8pp::context& context, std::string const& type,
v8::Local<v8::Value>(*exception_ctor)(v8::Local<v8::String>))
v8::Local<v8::Value> (*exception_ctor)(v8::Local<v8::String>))
{
v8::Isolate* isolate = context.isolate();

Expand All @@ -22,8 +22,7 @@ void test(v8pp::context& context, std::string const& type,
v8::Local<v8::Value> ex = v8pp::throw_ex(isolate,
"exception message", exception_ctor);
check(" has caught", try_catch.HasCaught());
check("the same stack trace", try_catch.Message()
->GetStackTrace() == v8::Exception::GetStackTrace(ex));
check("the same stack trace", try_catch.Message()->GetStackTrace() == v8::Exception::GetStackTrace(ex));
v8::String::Utf8Value const err_msg(isolate, try_catch.Message()->Get());
check_eq("message", *err_msg, "Uncaught " + type + ": exception message");
}
Expand All @@ -33,7 +32,7 @@ void test(v8pp::context& context, std::string const& type,
void test_throw_ex()
{
v8pp::context context;
test(context, "Error", v8::Exception::Error);
test(context, "Error", v8::Exception::Error);
test(context, "RangeError", v8::Exception::RangeError);
test(context, "ReferenceError", v8::Exception::ReferenceError);
test(context, "SyntaxError", v8::Exception::SyntaxError);
Expand Down
13 changes: 6 additions & 7 deletions test/test_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ void test_function_traits()
test_ret<short>(&X::zz);
test_args<std::tuple<X volatile&>>(&X::zz);

struct Y : X {};
struct Y : X
{
};

test_ret_derived<float, Y>(&Y::f);
test_args_derived<std::tuple<Y const&>, Y>(&Y::f);
Expand Down Expand Up @@ -140,12 +142,9 @@ void test_tuple_tail()
{
using v8pp::detail::tuple_tail;

static_assert(std::is_same<tuple_tail<std::tuple<int>>::type,
std::tuple<>>::value, "");
static_assert(std::is_same<tuple_tail<std::tuple<int, char>>::type,
std::tuple<char>>::value, "");
static_assert(std::is_same<tuple_tail<std::tuple<int, char, bool>>::type,
std::tuple<char, bool>>::value, "");
static_assert(std::is_same<tuple_tail<std::tuple<int>>::type, std::tuple<>>::value, "");
static_assert(std::is_same<tuple_tail<std::tuple<int, char>>::type, std::tuple<char>>::value, "");
static_assert(std::is_same<tuple_tail<std::tuple<int, char, bool>>::type, std::tuple<char, bool>>::value, "");
}

int f() { return 1; }
Expand Down
Loading

0 comments on commit f6fe558

Please sign in to comment.