Debian Codegraph @

closure-library/closure/goog/storage/storagetester.js

raw
1 // Copyright 2017 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 Helper for various storage tests.
17 *
18 * @author [email protected] (John Lenz)
19 */
20
21 goog.provide('goog.storage.storageTester');
22 goog.setTestOnly();
23
24 goog.require('goog.storage.Storage');
25 goog.require('goog.structs.Map');
26 goog.require('goog.testing.asserts');
27
28 /**
29 * @param {!goog.storage.Storage} storage
30 */
31 goog.storage.storageTester.runBasicTests = function(storage) {
32 // Simple Objects.
33 storage.set('first', 'Hello world!');
34 storage.set('second', ['one', 'two', 'three']);
35 storage.set('third', {'a': 97, 'b': 98});
36 assertEquals('Hello world!', storage.get('first'));
37 assertObjectEquals(['one', 'two', 'three'], storage.get('second'));
38 assertObjectEquals({'a': 97, 'b': 98}, storage.get('third'));
39
40 // Some more complex fun with a Map.
41 var map = new goog.structs.Map();
42 map.set('Alice', 'Hello world!');
43 map.set('Bob', ['one', 'two', 'three']);
44 map.set('Cecile', {'a': 97, 'b': 98});
45 storage.set('first', map.toObject());
46 assertObjectEquals(map.toObject(), storage.get('first'));
47
48 // Setting weird values.
49 storage.set('second', null);
50 assertEquals(null, storage.get('second'));
51 storage.set('second', undefined);
52 assertEquals(undefined, storage.get('second'));
53 storage.set('second', '');
54 assertEquals('', storage.get('second'));
55
56 // Clean up.
57 storage.remove('first');
58 storage.remove('second');
59 storage.remove('third');
60 assertUndefined(storage.get('first'));
61 assertUndefined(storage.get('second'));
62 assertUndefined(storage.get('third'));
63 };