Debian Codegraph @

closure-library/closure/goog/testing/testqueue.js

raw
1 // Copyright 2007 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 /**
16 * @fileoverview Generic queue for writing unit tests.
17 */
18
19 goog.setTestOnly('goog.testing.TestQueue');
20 goog.provide('goog.testing.TestQueue');
21
22
23
24 /**
25 * Generic queue for writing unit tests
26 * @constructor
27 */
28 goog.testing.TestQueue = function() {
29 /**
30 * Events that have accumulated
31 * @type {Array<Object>}
32 * @private
33 */
34 this.events_ = [];
35 };
36
37
38 /**
39 * Adds a new event onto the queue.
40 * @param {Object} event The event to queue.
41 */
42 goog.testing.TestQueue.prototype.enqueue = function(event) {
43 this.events_.push(event);
44 };
45
46
47 /**
48 * Returns whether the queue is empty.
49 * @return {boolean} Whether the queue is empty.
50 */
51 goog.testing.TestQueue.prototype.isEmpty = function() {
52 return this.events_.length == 0;
53 };
54
55
56 /**
57 * Gets the next event from the queue. Throws an exception if the queue is
58 * empty.
59 * @param {string=} opt_comment Comment if the queue is empty.
60 * @return {Object} The next event from the queue.
61 */
62 goog.testing.TestQueue.prototype.dequeue = function(opt_comment) {
63 if (this.isEmpty()) {
64 throw new Error('Handler is empty: ' + opt_comment);
65 }
66 return this.events_.shift();
67 };