Sha256: 7bde406f41c73d6f171f5a126aaf37dc128b79982ce073e1cb0a55d38a878675

Contents?: true

Size: 1.72 KB

Versions: 2

Compression:

Stored size: 1.72 KB

Contents

//          Copyright Joakim Karlsson & Kim Gräsman 2010-2012.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)

#ifndef IGLOO_HASLENGTHCONSTRAINT_H
#define IGLOO_HASLENGTHCONSTRAINT_H

#include "./expressions/expression.h"

namespace snowhouse {

  template <typename ExpectedType>
  struct HasLengthConstraint : Expression< HasLengthConstraint<ExpectedType> >
  {
    HasLengthConstraint(const ExpectedType& expected) 
      : m_expected(expected) {}
      
    template <typename ActualType>
    bool operator()(const ActualType& actual) const
    {                                    
      typedef typename ActualType::size_type SizeType;
      SizeType expectedSize = static_cast<SizeType>(m_expected);
      return (actual.size() == expectedSize);
    } 
    
    ExpectedType m_expected;
  };              

  template< typename ExpectedType >
  inline HasLengthConstraint<ExpectedType> HasLength(const ExpectedType& expected)
  {
    return HasLengthConstraint<ExpectedType>(expected);
  }
  
  inline HasLengthConstraint<int> IsEmpty()
  {
    return HasLength<int>(0);
  }

  inline HasLengthConstraint<std::string> HasLength(const char* expected)
  {
    return HasLengthConstraint<std::string>(expected);
  }

  template< typename ExpectedType >
  struct Stringizer< HasLengthConstraint< ExpectedType > >
  {
    static std::string ToString(const HasLengthConstraint<ExpectedType>& constraint)
    {
      std::ostringstream builder;
	  builder << "of length " << snowhouse::Stringize(constraint.m_expected);

      return builder.str();
    }
  };
}      

#endif

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tree-sitter-0.1.0 ext/tree-sitter/tree-sitter/externals/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/haslengthconstraint.h
tree-sitter-0.0.1 ext/tree-sitter/tree-sitter/externals/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/haslengthconstraint.h