Repository navigation
Expand file tree
/
Copy pathtest.js
More file actions
264 lines (247 loc) · 8.22 KB
/
Copy pathtest.js
File metadata and controls
264 lines (247 loc) · 8.22 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
register_roundtrip_modifier("SpreadsheetTable",function(our_diary,roundtripped_diary,other_format) {
switch ( other_format.name ) {
case "ActivityLog":
case "SleepChart1":
case "PleesTracker":
case "Fitbit":
[our_diary,roundtripped_diary].forEach(function(diary) {
diary["records"].forEach( function(record) {
/*
* Sleep As Android requires exactly one string comment.
* PleesTracker does not support comments.
* Therefore, roundtripping necessarily breaks comments.
*/
["comments"].forEach(function(key) {
delete record[key];
});
});
});
}
});
describe("SpreadsheetTable format", () => {
var empty_diary = "start,end\n";
var empty_member_map = { "start": [ "start", 0 ], "end": [ "end", 1 ] };
var non_empty_diary = "SleepStart,SleepEnd,sTaTe,comments,NOTES\n123456789,123456789,slept\n2020-01-01 01:01-0100,2020-02-02 02:02+0200,awoke,comment 1,comment 2\n";
var non_empty_member_map = {
"start": [ "SleepStart", 0 ],
"end": [ "SleepEnd", 1 ],
"status": [ "sTaTe", 2 ],
"comments": [ "comments", 3, [ "comments", "NOTES" ] ]
};
test_parse({
file_format: "SpreadsheetTable",
name: "empty diary",
input: empty_diary,
expected: {
"records": [],
"member_map": empty_member_map,
}
});
test_parse({
file_format: "SpreadsheetTable",
name: "simple SpreadsheetTable with one row",
input: "start,end\n123456789,123456789\n",
expected: {
"records": [
{
"start" : 1234567890000,
"end" : 1234567890000,
"status": "asleep",
},
],
"member_map": empty_member_map,
}
});
test_parse({
file_format: "SpreadsheetTable",
name: "Simple SpreadsheetTable with two rows",
input: "Sleep,Wake\n123456789,123456789\n2020-01-01 01:01-0100,2020-02-02 02:02+0200\n",
expected: {
"records": [
{
"Sleep" : 1234567890000,
"Wake" : 1234567890000,
"status": "asleep",
},
{
"Sleep" : 1577844060000,
"Wake" : 1580601720000,
"status": "asleep",
},
],
"member_map": { "start": [ "Sleep", 0 ], "end": [ "Wake", 1 ] },
}
});
test_parse({
file_format: "SpreadsheetTable",
name: "Complex SpreadsheetTable",
input: "SleepStart,SleepEnd,sTaTe,comments,NOTES\n123456789,123456789,slept\n2020-01-01 01:01-0100,2020-02-02 02:02+0200,awoke,comment 1,\"this is a single field containing one comma (,) one newline (\n) and one double quote (\"\")\",ignored comment\n",
expected: {
"records": [
{
"SleepStart" : 1234567890000,
"SleepEnd" : 1234567890000,
"sTaTe": "asleep",
"comments": [],
},
{
"SleepStart" : 1577844060000,
"SleepEnd" : 1580601720000,
"sTaTe": "awake",
"comments": [ "comment 1", "this is a single field containing one comma (,) one newline (\n) and one double quote (\")" ],
},
],
"member_map": non_empty_member_map,
}
});
test_to({
name: "output test",
format: "output",
input: non_empty_diary,
expected: "SleepStart,SleepEnd,sTaTe,comments,NOTES\n1234567890000,1234567890000,asleep\n1577844060000,1580601720000,awake,comment 1,comment 2\n",
});
test_to({
name: "standard format test",
format: "Standard",
input: non_empty_diary,
expected: [
{
"status": "asleep",
"start": 1234567890000,
"end": 1234567890000,
"duration": 0,
"start_of_new_day": true,
"day_number": 2,
"missing_record_after": false,
"is_primary_sleep": true,
},
{
"status": "awake",
"start": 1577844060000,
"end": 1580601720000,
"comments": [ 'comment 1', 'comment 2' ],
"duration": 2757660000,
"start_of_new_day": false,
"day_number": 2,
},
],
});
/*
* This format can't be meaningfully initialised from Standard format,
* because the record layout is specific to the headers in each input file.
*/
/*
test_from_standard({
name: "standard format test",
format: "SpreadsheetTable",
input: [
...
],
expected: ...,
});
*/
test_merge({
name: "two empty diaries",
left: empty_diary,
right: empty_diary,
expected: {
"records": [],
"member_map": empty_member_map,
},
});
test_merge({
name: "left empty, right non-empty",
left: empty_diary,
right: non_empty_diary,
expected: {
"records": [
{
"start": 1234567890000,
"end": 1234567890000,
},
{
"start": 1577844060000,
"end": 1580601720000,
},
],
"member_map": empty_member_map,
},
});
test_merge({
name: "left non-empty, right empty",
left: non_empty_diary,
right: empty_diary,
expected: {
"records": [
{
"SleepStart": 1234567890000,
"SleepEnd": 1234567890000,
"sTaTe": "asleep",
"comments": [],
},
{
"SleepStart": 1577844060000,
"SleepEnd": 1580601720000,
"sTaTe": "awake",
"comments": [ "comment 1", "comment 2" ],
},
],
"member_map": non_empty_member_map,
},
});
test_merge({
name: "two identical diaries",
left: non_empty_diary,
right: non_empty_diary,
expected: {
"records": [
{
"SleepStart": 1234567890000,
"SleepEnd": 1234567890000,
"sTaTe": "asleep",
"comments": [],
},
{
"SleepStart": 1577844060000,
"SleepEnd": 1580601720000,
"sTaTe": "awake",
"comments": [ "comment 1", "comment 2" ],
},
],
"member_map": non_empty_member_map,
},
});
test_merge({
name: "two different diaries",
left: non_empty_diary,
right: "SleepStart,SleepEnd,sTaTe,comments,NOTES\n12346,12346,slept\n2020-01-01 01:02-0100,2020-02-02 02:03+0200,awoke,comment 1,comment 2\n",
expected: {
"records": [
{
"SleepStart": 1234567890000,
"SleepEnd": 1234567890000,
"sTaTe": "asleep",
"comments": [],
},
{
"SleepStart": 1577844060000,
"SleepEnd": 1580601720000,
"sTaTe": "awake",
"comments": [ "comment 1", "comment 2" ],
},
{
"SleepStart": 1234600000000,
"SleepEnd": 1234600000000,
"sTaTe": "asleep",
},
{
"SleepStart": 1577844120000,
"SleepEnd": 1580601780000,
"sTaTe": "awake",
"comments": [ "comment 1", "comment 2" ],
},
],
"member_map": non_empty_member_map,
},
});
});