123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- goog.provide('goog.labs.testing.HasEntriesMatcher');
- goog.provide('goog.labs.testing.HasEntryMatcher');
- goog.provide('goog.labs.testing.HasKeyMatcher');
- goog.provide('goog.labs.testing.HasValueMatcher');
- goog.require('goog.asserts');
- goog.require('goog.labs.testing.Matcher');
- goog.require('goog.object');
- goog.labs.testing.HasEntriesMatcher = function(entries) {
-
- this.entries_ = entries;
- };
- goog.labs.testing.HasEntriesMatcher.prototype.matches = function(actualObject) {
- goog.asserts.assertObject(actualObject, 'Expected an Object');
- var object = (actualObject);
- return goog.object.every(this.entries_, function(value, key) {
- return goog.object.containsKey(object, key) && object[key] === value;
- });
- };
- goog.labs.testing.HasEntriesMatcher.prototype.describe = function(
- actualObject) {
- goog.asserts.assertObject(actualObject, 'Expected an Object');
- var object = (actualObject);
- var errorString = 'Input object did not contain the following entries:\n';
- goog.object.forEach(this.entries_, function(value, key) {
- if (!goog.object.containsKey(object, key) || object[key] !== value) {
- errorString += key + ': ' + value + '\n';
- }
- });
- return errorString;
- };
- goog.labs.testing.HasEntryMatcher = function(key, value) {
-
- this.key_ = key;
-
- this.value_ = value;
- };
- goog.labs.testing.HasEntryMatcher.prototype.matches = function(actualObject) {
- goog.asserts.assertObject(actualObject);
- return goog.object.containsKey(actualObject, this.key_) &&
- actualObject[this.key_] === this.value_;
- };
- goog.labs.testing.HasEntryMatcher.prototype.describe = function(actualObject) {
- goog.asserts.assertObject(actualObject);
- var errorMsg;
- if (goog.object.containsKey(actualObject, this.key_)) {
- errorMsg = 'Input object did not contain key: ' + this.key_;
- } else {
- errorMsg = 'Value for key did not match value: ' + this.value_;
- }
- return errorMsg;
- };
- goog.labs.testing.HasKeyMatcher = function(key) {
-
- this.key_ = key;
- };
- goog.labs.testing.HasKeyMatcher.prototype.matches = function(actualObject) {
- goog.asserts.assertObject(actualObject);
- return goog.object.containsKey(actualObject, this.key_);
- };
- goog.labs.testing.HasKeyMatcher.prototype.describe = function(actualObject) {
- goog.asserts.assertObject(actualObject);
- return 'Input object did not contain the key: ' + this.key_;
- };
- goog.labs.testing.HasValueMatcher = function(value) {
-
- this.value_ = value;
- };
- goog.labs.testing.HasValueMatcher.prototype.matches = function(actualObject) {
- goog.asserts.assertObject(actualObject, 'Expected an Object');
- var object = (actualObject);
- return goog.object.containsValue(object, this.value_);
- };
- goog.labs.testing.HasValueMatcher.prototype.describe = function(actualObject) {
- return 'Input object did not contain the value: ' + this.value_;
- };
- function hasEntries(entries) {
- return new goog.labs.testing.HasEntriesMatcher(entries);
- }
- function hasEntry(key, value) {
- return new goog.labs.testing.HasEntryMatcher(key, value);
- }
- function hasKey(key) {
- return new goog.labs.testing.HasKeyMatcher(key);
- }
- function hasValue(value) {
- return new goog.labs.testing.HasValueMatcher(value);
- }
|