Skip to content

Commit

Permalink
squash: add test for Reference overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
danbev committed Mar 9, 2018
1 parent 651bfb2 commit 18f46e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/aliased_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class AliasedBuffer {
}

inline Reference& operator+=(const Reference& val) {
return *this->operator+=(static_cast<NativeT>(val));
return this->operator+=(static_cast<NativeT>(val));
}

template <typename T>
Expand Down
16 changes: 16 additions & 0 deletions test/cctest/test_aliased_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,19 @@ TEST_F(AliasBufferTest, OperatorOverloads) {
EXPECT_EQ(static_cast<uint32_t>(2), ab[0] -= 2);
EXPECT_EQ(static_cast<uint32_t>(-2), -ab[0]);
}

TEST_F(AliasBufferTest, OperatorOverloadsRefs) {
v8::Isolate::Scope isolate_scope(isolate_);
v8::HandleScope handle_scope(isolate_);
v8::Local<v8::Context> context = v8::Context::New(isolate_);
v8::Context::Scope context_scope(context);
AliasedBuffer<uint32_t, v8::Uint32Array> ab{isolate_, 2};
using Reference = AliasedBuffer<uint32_t, v8::Uint32Array>::Reference;
Reference ref = ab[0];
Reference ref_value = ab[1] = 2;

EXPECT_EQ(static_cast<uint32_t>(2), ref = ref_value);
EXPECT_EQ(static_cast<uint32_t>(4), ref += ref_value);
EXPECT_EQ(static_cast<uint32_t>(2), ref -= ref_value);
EXPECT_EQ(static_cast<uint32_t>(-2), -ref);
}

0 comments on commit 18f46e8

Please sign in to comment.