blob: 429ac6492cd4908cec18ddf5051a6590c1c1bba4 (
plain)
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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
Cu.import("resource://services-common/utils.js");
Cu.import("resource://gre/modules/osfile.jsm");
function run_test() {
initTestLogging();
run_next_test();
}
add_test(function test_writeJSON_readJSON() {
_("Round-trip some JSON through the promise-based JSON writer.");
let contents = {
"a": 12345.67,
"b": {
"c": "héllö",
},
"d": undefined,
"e": null,
};
function checkJSON(json) {
do_check_eq(contents.a, json.a);
do_check_eq(contents.b.c, json.b.c);
do_check_eq(contents.d, json.d);
do_check_eq(contents.e, json.e);
run_next_test();
};
function doRead() {
CommonUtils.readJSON(path)
.then(checkJSON, do_throw);
}
let path = OS.Path.join(OS.Constants.Path.profileDir, "bar.json");
CommonUtils.writeJSON(contents, path)
.then(doRead, do_throw);
});
|