2 package
.loaded
["core.configmanager"] = {};
3 package
.loaded
["core.statsmanager"] = {};
4 package
.loaded
["net.server"] = {};
6 local set
= require
"util.set";
8 _G
.prosody
= { hosts
= {}, core_post_stanza
= true };
10 local api
= require
"core.moduleapi";
12 local module
= setmetatable({}, {__index
= api
});
14 function module
:log() end
15 function module
:get_option(name
)
23 function test_option_value(value
, returns
)
25 assert(module
:get_option_number("opt") == returns
.number, "number doesn't match");
26 assert(module
:get_option_string("opt") == returns
.string, "string doesn't match");
27 assert(module
:get_option_boolean("opt") == returns
.boolean
, "boolean doesn't match");
29 if type(returns
.array
) == "table" then
30 local target_array
, returned_array
= returns
.array
, module
:get_option_array("opt");
31 assert(#target_array
== #returned_array
, "array length doesn't match");
32 for i
=1,#target_array
do
33 assert(target_array
[i
] == returned_array
[i
], "array item doesn't match");
36 assert(module
:get_option_array("opt") == returns
.array
, "array is returned (not nil)");
39 if type(returns
.set
) == "table" then
40 local target_items
, returned_items
= set
.new(returns
.set
), module
:get_option_set("opt");
41 assert(target_items
== returned_items
, "set doesn't match");
43 assert(module
:get_option_set("opt") == returns
.set
, "set is returned (not nil)");
47 describe("core.moduleapi", function()
48 describe("#get_option_*()", function()
49 it("should handle missing options", function()
50 test_option_value(nil, {});
53 it("should return correctly handle boolean options", function()
54 test_option_value(true, { boolean
= true, string = "true", array
= {true}, set
= {true} });
55 test_option_value(false, { boolean
= false, string = "false", array
= {false}, set
= {false} });
56 test_option_value("true", { boolean
= true, string = "true", array
= {"true"}, set
= {"true"} });
57 test_option_value("false", { boolean
= false, string = "false", array
= {"false"}, set
= {"false"} });
58 test_option_value(1, { boolean
= true, string = "1", array
= {1}, set
= {1}, number = 1 });
59 test_option_value(0, { boolean
= false, string = "0", array
= {0}, set
= {0}, number = 0 });
62 it("should return handle strings", function()
63 test_option_value("hello world", { string = "hello world", array
= {"hello world"}, set
= {"hello world"} });
66 it("should return handle numbers", function()
67 test_option_value(1234, { string = "1234", number = 1234, array
= {1234}, set
= {1234} });
70 it("should return handle arrays", function()
71 test_option_value({1, 2, 3}, { boolean
= true, string = "1", number = 1, array
= {1, 2, 3}, set
= {1, 2, 3} });
72 test_option_value({1, 2, 3, 3, 4}, {boolean
= true, string = "1", number = 1, array
= {1, 2, 3, 3, 4}, set
= {1, 2, 3, 4} });
73 test_option_value({0, 1, 2, 3}, { boolean
= false, string = "0", number = 0, array
= {0, 1, 2, 3}, set
= {0, 1, 2, 3} });