OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <!-- Submitted from TestTWF Paris --> | |
3 <meta charset="utf-8"> | |
4 <title>Key sort order</title> | |
5 <link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#
key-construct"> | |
6 <link rel=assert title="For purposes of comparison, all Arrays are greater than
all DOMString, Date and float values; all DOMString values are greater than all
Date and float values; and all Date values are greater than all float values. Va
lues of type float are compared to other float values numerically. Values of typ
e Date are compared to other Date values chronologically. Values of type DOMStri
ng are compared to other values of type DOMString by using the algorithm defined
by step 4 of section 11.8.5, The Abstract Relational Comparison Algorithm, of t
he ECMAScript Language Specification [ECMA-262]. Values of type Array are compar
ed to other values of type Array as follows: | |
7 | |
8 1. Let A be the first Array value and B be the second Array value. | |
9 2. Let length be the lesser of A's length and B's length. | |
10 3. Let i be 0. | |
11 4. If the ith value of A is less than the ith value of B, then A is less than B.
Skip the remaining steps. | |
12 5. If the ith value of A is greater than the ith value of B, then A is greater t
han B. Skip the remaining steps. | |
13 6. Increase i by 1. | |
14 7. If i is not equal to length, go back to step 4. Otherwise continue to next st
ep. | |
15 8. If A's length is less than B's length, then A is less than B. If A's length i
s greater than B's length, then A is greater than B. Otherwise A and B are equal
."> | |
16 <script src="../../../resources/testharness.js"></script> | |
17 <script src="../../../resources/testharnessreport.js"></script> | |
18 <script src="support.js"></script> | |
19 | |
20 <script> | |
21 var global_db = createdb_for_multiple_tests(); | |
22 | |
23 function keysort(desc, unsorted, expected) { | |
24 var db, | |
25 t = async_test("Database readback sort - " + desc, { timeout: 10000
}), | |
26 store_name = 'store-' + Date.now() + Math.random(); | |
27 | |
28 // The database test | |
29 var open_rq = global_db.setTest(t); | |
30 open_rq.onupgradeneeded = function(e) { | |
31 db = e.target.result; | |
32 var objStore = db.createObjectStore(store_name); | |
33 | |
34 for (var i = 0; i < unsorted.length; i++) | |
35 objStore.add("value", unsorted[i]); | |
36 }; | |
37 | |
38 open_rq.onsuccess = function(e) { | |
39 var actual_keys = [], | |
40 rq = db.transaction(store_name) | |
41 .objectStore(store_name) | |
42 .openCursor(); | |
43 | |
44 rq.onsuccess = t.step_func(function(e) { | |
45 var cursor = e.target.result; | |
46 | |
47 if (cursor) { | |
48 actual_keys.push(cursor.key); | |
49 cursor.continue(); | |
50 } | |
51 else { | |
52 assert_key_equals(actual_keys, expected, "keyorder array"); | |
53 assert_equals(actual_keys.length, expected.length, "array le
ngth"); | |
54 | |
55 t.done(); | |
56 } | |
57 }); | |
58 }; | |
59 | |
60 // The IDBKey.cmp test | |
61 test(function () { | |
62 var sorted = unsorted.slice(0).sort(function(a, b) { return indexedD
B.cmp(a, b)}); | |
63 assert_key_equals(sorted, expected, "sorted array"); | |
64 | |
65 }, "IDBKey.cmp sorted - " + desc); | |
66 } | |
67 | |
68 var now = new Date(), | |
69 one_sec_ago = new Date(now - 1000), | |
70 one_min_future = new Date(now.getTime() + (1000*60)); | |
71 | |
72 keysort('String < Array', | |
73 [ [0], "yo", "", [] ], | |
74 [ "", "yo", [], [0] ]); | |
75 | |
76 keysort('float < String', | |
77 [ Infinity, "yo", 0, "", 100 ], | |
78 [ 0, 100, Infinity, "", "yo" ]); | |
79 | |
80 keysort('float < Date', | |
81 [ now, 0, 9999999999999, -0.22 ], | |
82 [ -0.22, 0, 9999999999999, now ]); | |
83 | |
84 keysort('float < Date < String < Array', | |
85 [ [], "", now, [0], "-1", 0, 9999999999999, ], | |
86 [ 0, 9999999999999, now, "", "-1", [], [0] ]); | |
87 | |
88 | |
89 keysort('Date(1 sec ago) < Date(now) < Date(1 minute in future)', | |
90 [ now, one_sec_ago, one_min_future ], | |
91 [ one_sec_ago, now, one_min_future ]); | |
92 | |
93 keysort('-1.1 < 1 < 1.01337 < 1.013373 < 2', | |
94 [ 1.013373, 2, 1.01337, -1.1, 1 ], | |
95 [ -1.1, 1, 1.01337, 1.013373, 2 ]); | |
96 | |
97 keysort('-Infinity < -0.01 < 0 < Infinity', | |
98 [ 0, -0.01, -Infinity, Infinity ], | |
99 [ -Infinity, -0.01, 0, Infinity ]); | |
100 | |
101 keysort('"" < "a" < "ab" < "b" < "ba"', | |
102 [ "a", "ba", "", "b", "ab" ], | |
103 [ "", "a", "ab", "b", "ba" ]); | |
104 | |
105 keysort('Arrays', | |
106 [ [[0]], [0], [], [0, 0], [0, [0]] ], | |
107 [ [], [0], [0, 0], [0, [0]], [[0]] ]); | |
108 | |
109 var big_array = [], bigger_array = []; | |
110 for (var i=0; i < 10000; i++) { | |
111 big_array.push(i); | |
112 bigger_array.push(i); | |
113 } | |
114 bigger_array.push(0); | |
115 | |
116 keysort('Array.length: 10,000 < Array.length: 10,001', | |
117 [ bigger_array, [0, 2, 3], [0], [9], big_array ], | |
118 [ [0], big_array, bigger_array, [0, 2, 3], [9] ]); | |
119 | |
120 keysort('Infinity inside arrays', | |
121 [ [Infinity, 1], [Infinity, Infinity], [1, 1], | |
122 [1, Infinity], [1, -Infinity], [-Infinity, Infinity] ], | |
123 [ [-Infinity, Infinity], [1, -Infinity], [1, 1], | |
124 [1, Infinity], [Infinity, 1], [Infinity, Infinity] ]); | |
125 | |
126 | |
127 keysort('Test different stuff at once', | |
128 [ | |
129 now, | |
130 [0, []], | |
131 "test", | |
132 1, | |
133 ["a", [1, [-1]]], | |
134 ["b", "a"], | |
135 [ 0, 2, "c"], | |
136 ["a", [1, 2]], | |
137 [], | |
138 [0, [], 3], | |
139 ["a", "b"], | |
140 [ 1, 2 ], | |
141 ["a", "b", "c"], | |
142 one_sec_ago, | |
143 [ 0, "b", "c"], | |
144 Infinity, | |
145 -Infinity, | |
146 2.55, | |
147 [ 0, now ], | |
148 [1] | |
149 ], | |
150 [ | |
151 -Infinity, | |
152 1, | |
153 2.55, | |
154 Infinity, | |
155 one_sec_ago, | |
156 now, | |
157 "test", | |
158 [], | |
159 [0 ,2, "c"], | |
160 [0, now], | |
161 [0, "b", "c"], | |
162 [0, []], | |
163 [0, [], 3], | |
164 [1], | |
165 [1, 2], | |
166 ["a", "b"], | |
167 ["a", "b", "c"], | |
168 ["a", [1, 2]], | |
169 ["a", [1, [-1]]], | |
170 ["b", "a"] | |
171 ]); | |
172 | |
173 </script> | |
174 | |
175 <div id="log"></div> | |
OLD | NEW |