1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
<!DOCTYPE html>
<html>
<!--
Copyright 2012 The Closure Library Authors. All Rights Reserved.
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<title>Closure Unit Tests - Logic matchers</title>
<script src="../../base.js"></script>
<script>
goog.require('goog.labs.testing.AllOfMatcher');
goog.require('goog.labs.testing.GreaterThanMatcher');
goog.require('goog.labs.testing.assertThat');
goog.require('goog.testing.jsunit');
</script>
</head>
<body>
<script>
function testAnyOf() {
goog.labs.testing.assertThat(5, anyOf(greaterThan(4), lessThan(3)),
'5 > 4 || 5 < 3');
goog.labs.testing.assertThat(2, anyOf(greaterThan(4), lessThan(3)),
'2 > 4 || 2 < 3');
assertMatcherError(function() {
goog.labs.testing.assertThat(4, anyOf(greaterThan(5), lessThan(2)));
}, 'anyOf should throw exception when it fails');
}
function testAllOf() {
goog.labs.testing.assertThat(5, allOf(greaterThan(4), lessThan(6)),
'5 > 4 && 5 < 6');
assertMatcherError(function() {
goog.labs.testing.assertThat(4, allOf(lessThan(5), lessThan(3)));
}, 'allOf should throw exception when it fails');
}
function testIsNot() {
goog.labs.testing.assertThat(5, isNot(greaterThan(6)), '5 !> 6');
assertMatcherError(function() {
goog.labs.testing.assertThat(4, isNot(greaterThan(3)));
}, 'isNot should throw exception when it fails');
}
function assertMatcherError(callable, errorString) {
var e = assertThrows(errorString || 'callable throws exception', callable);
assertTrue(e instanceof goog.labs.testing.MatcherError);
}
</script>
</body>
</html>
|