Loading [MathJax]/extensions/tex2jax.js
v8toolkit  0.0.1
Utility library for embedding V8 Javascript engine in a c++ program
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fixtures.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "javascript.h"
4 #include "v8toolkit.h"
5 #include "v8helpers.h"
6 #include "testing.h"
7 
9 public:
10 
12  {}
13 
15 
16  virtual void SetUp() {
17  }
18 
19 };
20 
22 public:
24 
25  }
26 };
27 
28 
30 
31 public:
36  i->add_assert();
37  }
38 
39  void create_context() {
40  c = i->create_context();
41 
42  // does a does a deep comparison between the two objects passed and if they don't match, it prints out the info
43  // and then fails a GoogleTest EXPECT_EQ match. Just using EXPECT_EQ works, but you can't print out what the
44  // comparison was
45  c->add_function("EXPECT_EQJS", [this](v8::Local<v8::Value> lhs, v8::Local<v8::Value> rhs) {
46  if (!v8toolkit::compare_contents(*i, lhs, rhs)) {
47  std::cerr << fmt::format("EXPECT_EQJS failed: {} != {}", *v8::String::Utf8Value(lhs), *v8::String::Utf8Value(rhs)) << std::endl;
48  std::cerr << fmt::format("{}", v8toolkit::stringify_value(*i, lhs)) << std::endl;
49  std::cerr << fmt::format("{}", v8toolkit::stringify_value(*i, rhs)) << std::endl;
51  }
52  });
53 
54  c->add_function("EXPECT_TRUE", [](bool expected_true_value) {
55  EXPECT_TRUE(expected_true_value);
56  });
57  }
58 
59 };
v8toolkit::IsolatePtr i
Definition: fixtures.h:32
v8toolkit::ContextPtr c
Definition: fixtures.h:33
std::string stringify_value(v8::Isolate *isolate, const v8::Local< v8::Value > &value, bool show_all_properties=false, std::vector< v8::Local< v8::Value >> &&processed_values=std::vector< v8::Local< v8::Value >>{})
Definition: v8helpers.cpp:187
bool compare_contents(v8::Isolate *isolate, const v8::Local< v8::Value > &left, const v8::Local< v8::Value > &right)
Definition: v8toolkit.cpp:732
std::shared_ptr< Isolate > IsolatePtr
Definition: javascript.h:651
static IsolatePtr create_isolate()
Definition: javascript.cpp:444
std::shared_ptr< Context > ContextPtr
Definition: javascript.h:367
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
virtual void SetUp()
Definition: fixtures.h:16
void create_context()
Definition: fixtures.h:39