# lib/goog/labs/testing/assertthat.js

    1// Copyright 2012 The Closure Library Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7//      http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.1415/**16 * @fileoverview Provides main functionality of assertThat. assertThat calls the17 * matcher's matches method to test if a matcher matches assertThat's arguments.18 */192021goog.provide('goog.labs.testing.MatcherError');22goog.provide('goog.labs.testing.assertThat');2324goog.require('goog.asserts');25goog.require('goog.debug.Error');26goog.require('goog.labs.testing.Matcher');272829/**30 * Asserts that the actual value evaluated by the matcher is true.31 *32 * @param {*} actual The object to assert by the matcher.33 * @param {!goog.labs.testing.Matcher} matcher A matcher to verify values.34 * @param {string=} opt_reason Description of what is asserted.35 *36 */37goog.labs.testing.assertThat = function(actual, matcher, opt_reason) {38  if (!matcher.matches(actual)) {39    // Prefix the error description with a reason from the assert ?40    var prefix = opt_reason ? opt_reason + ': ' : '';41    var desc = prefix + matcher.describe(actual);4243    // some sort of failure here44    throw new goog.labs.testing.MatcherError(desc);45  }46};47484950/**51 * Error thrown when a Matcher fails to match the input value.52 * @param {string=} opt_message The error message.53 * @constructor54 * @extends {goog.debug.Error}55 */56goog.labs.testing.MatcherError = function(opt_message) {57  goog.base(this, opt_message);58};59goog.inherits(goog.labs.testing.MatcherError, goog.debug.Error);