Debian Codegraph @

closure-library/closure/goog/labs/testing/logicmatcher_test.js

raw
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 at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // 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 and
13 // limitations under the License.
14
15 goog.provide('goog.labs.testing.logicMatcherTest');
16 goog.setTestOnly('goog.labs.testing.logicMatcherTest');
17
18 /** @suppress {extraRequire} */
19 goog.require('goog.labs.testing.AllOfMatcher');
20 /** @suppress {extraRequire} */
21 goog.require('goog.labs.testing.GreaterThanMatcher');
22 goog.require('goog.labs.testing.MatcherError');
23 goog.require('goog.labs.testing.assertThat');
24 goog.require('goog.testing.jsunit');
25
26 function testAnyOf() {
27 goog.labs.testing.assertThat(
28 5, anyOf(greaterThan(4), lessThan(3)), '5 > 4 || 5 < 3');
29 goog.labs.testing.assertThat(
30 2, anyOf(greaterThan(4), lessThan(3)), '2 > 4 || 2 < 3');
31
32 assertMatcherError(function() {
33 goog.labs.testing.assertThat(4, anyOf(greaterThan(5), lessThan(2)));
34 }, 'anyOf should throw exception when it fails');
35 }
36
37 function testAllOf() {
38 goog.labs.testing.assertThat(
39 5, allOf(greaterThan(4), lessThan(6)), '5 > 4 && 5 < 6');
40
41 assertMatcherError(function() {
42 goog.labs.testing.assertThat(4, allOf(lessThan(5), lessThan(3)));
43 }, 'allOf should throw exception when it fails');
44 }
45
46 function testIsNot() {
47 goog.labs.testing.assertThat(5, isNot(greaterThan(6)), '5 !> 6');
48
49 assertMatcherError(function() {
50 goog.labs.testing.assertThat(4, isNot(greaterThan(3)));
51 }, 'isNot should throw exception when it fails');
52 }
53
54 function assertMatcherError(callable, errorString) {
55 var e = assertThrows(errorString || 'callable throws exception', callable);
56 assertTrue(e instanceof goog.labs.testing.MatcherError);
57 }