Path: blob/trunk/third_party/closure/goog/labs/testing/assertthat.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 main functionality of assertThat. assertThat calls the16* matcher's matches method to test if a matcher matches assertThat's arguments.17*/181920goog.provide('goog.labs.testing.MatcherError');21goog.provide('goog.labs.testing.assertThat');2223goog.require('goog.debug.Error');242526/**27* Asserts that the actual value evaluated by the matcher is true.28*29* @param {*} actual The object to assert by the matcher.30* @param {!goog.labs.testing.Matcher} matcher A matcher to verify values.31* @param {string=} opt_reason Description of what is asserted.32*33*/34goog.labs.testing.assertThat = function(actual, matcher, opt_reason) {35if (!matcher.matches(actual)) {36// Prefix the error description with a reason from the assert ?37var prefix = opt_reason ? opt_reason + ': ' : '';38var desc = prefix + matcher.describe(actual);3940// some sort of failure here41throw new goog.labs.testing.MatcherError(desc);42}43};44454647/**48* Error thrown when a Matcher fails to match the input value.49* @param {string=} opt_message The error message.50* @constructor51* @extends {goog.debug.Error}52* @final53*/54goog.labs.testing.MatcherError = function(opt_message) {55goog.labs.testing.MatcherError.base(this, 'constructor', opt_message);56};57goog.inherits(goog.labs.testing.MatcherError, goog.debug.Error);585960