logicmatcher_test.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. goog.provide('goog.labs.testing.logicMatcherTest');
  15. goog.setTestOnly('goog.labs.testing.logicMatcherTest');
  16. /** @suppress {extraRequire} */
  17. goog.require('goog.labs.testing.AllOfMatcher');
  18. /** @suppress {extraRequire} */
  19. goog.require('goog.labs.testing.GreaterThanMatcher');
  20. goog.require('goog.labs.testing.MatcherError');
  21. goog.require('goog.labs.testing.assertThat');
  22. goog.require('goog.testing.jsunit');
  23. function testAnyOf() {
  24. goog.labs.testing.assertThat(
  25. 5, anyOf(greaterThan(4), lessThan(3)), '5 > 4 || 5 < 3');
  26. goog.labs.testing.assertThat(
  27. 2, anyOf(greaterThan(4), lessThan(3)), '2 > 4 || 2 < 3');
  28. assertMatcherError(function() {
  29. goog.labs.testing.assertThat(4, anyOf(greaterThan(5), lessThan(2)));
  30. }, 'anyOf should throw exception when it fails');
  31. }
  32. function testAllOf() {
  33. goog.labs.testing.assertThat(
  34. 5, allOf(greaterThan(4), lessThan(6)), '5 > 4 && 5 < 6');
  35. assertMatcherError(function() {
  36. goog.labs.testing.assertThat(4, allOf(lessThan(5), lessThan(3)));
  37. }, 'allOf should throw exception when it fails');
  38. }
  39. function testIsNot() {
  40. goog.labs.testing.assertThat(5, isNot(greaterThan(6)), '5 !> 6');
  41. assertMatcherError(function() {
  42. goog.labs.testing.assertThat(4, isNot(greaterThan(3)));
  43. }, 'isNot should throw exception when it fails');
  44. }
  45. function assertMatcherError(callable, errorString) {
  46. var e = assertThrows(errorString || 'callable throws exception', callable);
  47. assertTrue(e instanceof goog.labs.testing.MatcherError);
  48. }