mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
47 lines
1.2 KiB
JavaScript
47 lines
1.2 KiB
JavaScript
_("Make sure json saves and loads from disk");
|
|
Cu.import("resource://weave/util.js");
|
|
|
|
function run_test() {
|
|
_("Do a simple write of an array to json and read");
|
|
let foo;
|
|
Utils.jsonSave("foo", {}, ["v1", "v2"]);
|
|
Utils.jsonLoad("foo", {}, function(val) {
|
|
foo = val;
|
|
});
|
|
do_check_eq(typeof foo, "object");
|
|
do_check_eq(foo.length, 2);
|
|
do_check_eq(foo[0], "v1");
|
|
do_check_eq(foo[1], "v2");
|
|
|
|
_("Use the function callback version of jsonSave");
|
|
let bar;
|
|
Utils.jsonSave("bar", {}, function() ["v1", "v2"]);
|
|
Utils.jsonLoad("bar", {}, function(val) {
|
|
bar = val;
|
|
});
|
|
do_check_eq(typeof bar, "object");
|
|
do_check_eq(bar.length, 2);
|
|
do_check_eq(bar[0], "v1");
|
|
do_check_eq(bar[1], "v2");
|
|
|
|
_("Try saving simple strings");
|
|
let str;
|
|
Utils.jsonSave("str", {}, "hi");
|
|
Utils.jsonLoad("str", {}, function(val) {
|
|
str = val;
|
|
});
|
|
do_check_eq(typeof str, "string");
|
|
do_check_eq(str.length, 2);
|
|
do_check_eq(str[0], "h");
|
|
do_check_eq(str[1], "i");
|
|
|
|
_("Try saving a number");
|
|
let num;
|
|
Utils.jsonSave("num", {}, function() 42);
|
|
Utils.jsonLoad("num", {}, function(val) {
|
|
num = val;
|
|
});
|
|
do_check_eq(typeof num, "number");
|
|
do_check_eq(num, 42);
|
|
}
|