зеркало из https://github.com/mozilla/gecko-dev.git
Add tests for Utils.jsonSave and Utils.jsonLoad.
This commit is contained in:
Родитель
b88a69b137
Коммит
668a13002f
|
@ -0,0 +1,46 @@
|
|||
_("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);
|
||||
}
|
Загрузка…
Ссылка в новой задаче