chromium/v8/testing/gmock-support.h

// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_TESTING_GMOCK_SUPPORT_H_
#define V8_TESTING_GMOCK_SUPPORT_H_

#include <cmath>
#include <cstring>
#include <string>

#include "include/v8-isolate.h"
#include "testing/gmock/include/gmock/gmock.h"

namespace testing {

template <typename T>
class Capture {};


namespace internal {

template <typename T>
class CaptureEqMatcher : public MatcherInterface<T> {};

}  // namespace internal


// Creates a polymorphic matcher that matches anything whose bit representation
// is equal to that of {x}.
MATCHER_P(BitEq, x, std::string(negation ? "isn't" : "is") +
                        " bitwise equal to " + PrintToString(x)) {}

// Creates a polymorphic matcher that matches JSValue to Int32.
MATCHER_P(IsInt32, expected,
          std::string(negation ? "isn't" : "is") + " Int32 " +
              PrintToString(expected)) {}

// Creates a polymorphic matcher that matches JSValue to String.
MATCHER_P(IsString, expected,
          std::string(negation ? "isn't" : "is") + " String " +
              PrintToString(expected)) {}

// Creates a polymorphic matcher that matches JSValue to Undefined.
MATCHER(IsUndefined, std::string(negation ? "isn't" : "is") + " Undefined") {}

// CaptureEq(capture) captures the value passed in during matching as long as it
// is unset, and once set, compares the value for equality with the argument.
template <typename T>
inline Matcher<T> CaptureEq(Capture<T>* capture) {}


// Creates a polymorphic matcher that matches any floating point NaN value.
MATCHER(IsNaN, std::string(negation ? "isn't" : "is") + " not a number") {}

}  // namespace testing

#endif  // V8_TESTING_GMOCK_SUPPORT_H_