Path: blob/trunk/third_party/closure/goog/labs/testing/matcher.js
2868 views
// Copyright 2012 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Provides the base Matcher interface. User code should use the16* matchers through assertThat statements and not directly.17*/181920goog.provide('goog.labs.testing.Matcher');21222324/**25* A matcher object to be used in assertThat statements.26* @interface27*/28goog.labs.testing.Matcher = function() {};293031/**32* Determines whether a value matches the constraints of the match.33*34* @param {*} value The object to match.35* @return {boolean} Whether the input value matches this matcher.36*/37goog.labs.testing.Matcher.prototype.matches = function(value) {};383940/**41* Describes why the matcher failed.42*43* @param {*} value The value that didn't match.44* @param {string=} opt_description A partial description to which the reason45* will be appended.46*47* @return {string} Description of why the matcher failed.48*/49goog.labs.testing.Matcher.prototype.describe = function(50value, opt_description) {};515253/**54* Generates a Matcher from the ‘matches’ and ‘describe’ functions passed in.55*56* @param {!Function} matchesFunction The ‘matches’ function.57* @param {Function=} opt_describeFunction The ‘describe’ function.58* @return {!Function} The custom matcher.59*/60goog.labs.testing.Matcher.makeMatcher = function(61matchesFunction, opt_describeFunction) {6263/**64* @constructor65* @implements {goog.labs.testing.Matcher}66* @final67*/68var matcherConstructor = function() {};6970/** @override */71matcherConstructor.prototype.matches = matchesFunction;7273if (opt_describeFunction) {74/** @override */75matcherConstructor.prototype.describe = opt_describeFunction;76}7778return matcherConstructor;79};808182