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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
<!DOCTYPE html>
<html>
<!--
Copyright 2011 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>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Closure Unit Tests - goog.testing.MockStorage</title>
<script src="../base.js"></script>
<script>
goog.require('goog.testing.MockStorage');
goog.require('goog.testing.jsunit');
</script>
</head>
<body>
<script>
var instance;
function setUp() {
instance = new goog.testing.MockStorage();
}
/**
* Tests the MockStorage interface.
*/
function testMockStorage() {
assertEquals(0, instance.length);
instance.setItem('foo', 'bar');
assertEquals(1, instance.length);
assertEquals('bar', instance.getItem('foo'));
assertEquals('foo', instance.key(0));
instance.setItem('foo', 'baz');
assertEquals('baz', instance.getItem('foo'));
instance.setItem('goo', 'gl');
assertEquals(2, instance.length);
assertEquals('gl', instance.getItem('goo'));
assertEquals('goo', instance.key(1));
assertNull(instance.getItem('poogle'));
instance.removeItem('foo');
assertEquals(1, instance.length);
assertEquals('goo', instance.key(0));
instance.setItem('a', 12);
assertEquals('12', instance.getItem('a'));
instance.setItem('b', false);
assertEquals('false', instance.getItem('b'));
instance.setItem('c', {a: 1, b: 12});
assertEquals('[object Object]', instance.getItem('c'));
instance.clear();
assertEquals(0, instance.length);
// Test some special cases.
instance.setItem('emptyString', '');
assertEquals('', instance.getItem('emptyString'));
instance.setItem('isNull', null);
assertEquals('null', instance.getItem('isNull'))
instance.setItem('isUndefined', undefined);
assertEquals('undefined', instance.getItem('isUndefined'))
instance.setItem('', 'empty key');
assertEquals('empty key', instance.getItem(''));
assertEquals(4, instance.length);
}
</script>
</body>
</html>
|