123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- goog.provide('goog.reflectTest');
- goog.setTestOnly('goog.reflectTest');
- goog.require('goog.object');
- goog.require('goog.reflect');
- goog.require('goog.testing.jsunit');
- var doubleFn = function(key) {
- return key * 2;
- };
- var tripleFn = function(key) {
- return key * 3;
- };
- var throwsFn = function(key) {
- throw new Error("Shouldn't be called.");
- };
- var passthroughFn = function(key) {
- return key;
- };
- function testCache() {
- var cacheObj = {};
- assertEquals(2, goog.reflect.cache(cacheObj, 1, doubleFn));
- assertEquals(2, cacheObj[1]);
- assertEquals(1, goog.object.getCount(cacheObj));
-
- assertEquals(2, goog.reflect.cache(cacheObj, 1, throwsFn));
- assertEquals(2, cacheObj[1]);
- assertEquals(1, goog.object.getCount(cacheObj));
-
- assertEquals(
- 'toString', goog.reflect.cache(cacheObj, 'toString', passthroughFn));
- assertEquals('toString', goog.reflect.cache(cacheObj, 'toString', throwsFn));
-
-
- }
- function testCache_keyFn() {
- var cacheObj = {};
- assertEquals(3, goog.reflect.cache(cacheObj, 1, tripleFn, doubleFn));
- assertEquals(3, cacheObj[2]);
- assertEquals(1, goog.object.getCount(cacheObj));
-
- assertEquals(3, goog.reflect.cache(cacheObj, 1, throwsFn, doubleFn));
- assertEquals(3, cacheObj[2]);
- assertEquals(1, goog.object.getCount(cacheObj));
-
- assertEquals(2, goog.reflect.cache(cacheObj, 1, doubleFn, tripleFn));
- assertEquals(2, cacheObj[3]);
- assertEquals(2, goog.object.getCount(cacheObj));
-
- assertThrows(function() {
- goog.reflect.cache(cacheObj, 1, tripleFn, throwsFn);
- });
- }
|