Software /
code /
prosody
Annotate
tests/modulemanager_option_conversion.lua @ 7507:11e8c605a591
tests: Adapt test for util.queue to the test framework
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 20 Jul 2016 17:24:49 +0200 |
parent | 5776:bd0ff8ae98a8 |
rev | line source |
---|---|
2152
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 package.path = "../?.lua;"..package.path; |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local api = require "core.modulemanager".api; |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local module = setmetatable({}, {__index = api}); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local opt = nil; |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 function module:log() end |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 function module:get_option(name) |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 if name == "opt" then |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 return opt; |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 else |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 return nil; |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 end |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 end |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 function test_value(value, returns) |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 opt = value; |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 assert(module:get_option_number("opt") == returns.number, "number doesn't match"); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 assert(module:get_option_string("opt") == returns.string, "string doesn't match"); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 assert(module:get_option_boolean("opt") == returns.boolean, "boolean doesn't match"); |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
2152
diff
changeset
|
21 |
2152
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 if type(returns.array) == "table" then |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 local target_array, returned_array = returns.array, module:get_option_array("opt"); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 assert(#target_array == #returned_array, "array length doesn't match"); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 for i=1,#target_array do |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 assert(target_array[i] == returned_array[i], "array item doesn't match"); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 end |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 else |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 assert(module:get_option_array("opt") == returns.array, "array is returned (not nil)"); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
2152
diff
changeset
|
31 |
2152
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 if type(returns.set) == "table" then |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 local target_items, returned_items = set.new(returns.set), module:get_option_set("opt"); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 assert(target_items == returned_items, "set doesn't match"); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 else |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 assert(module:get_option_set("opt") == returns.set, "set is returned (not nil)"); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 end |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 end |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 test_value(nil, {}); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 test_value(true, { boolean = true, string = "true", array = {true}, set = {true} }); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 test_value(false, { boolean = false, string = "false", array = {false}, set = {false} }); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 test_value("true", { boolean = true, string = "true", array = {"true"}, set = {"true"} }); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 test_value("false", { boolean = false, string = "false", array = {"false"}, set = {"false"} }); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 test_value(1, { boolean = true, string = "1", array = {1}, set = {1}, number = 1 }); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 test_value(0, { boolean = false, string = "0", array = {0}, set = {0}, number = 0 }); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 test_value("hello world", { string = "hello world", array = {"hello world"}, set = {"hello world"} }); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 test_value(1234, { string = "1234", number = 1234, array = {1234}, set = {1234} }); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 test_value({1, 2, 3}, { boolean = true, string = "1", number = 1, array = {1, 2, 3}, set = {1, 2, 3} }); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 test_value({1, 2, 3, 3, 4}, {boolean = true, string = "1", number = 1, array = {1, 2, 3, 3, 4}, set = {1, 2, 3, 4} }); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 test_value({0, 1, 2, 3}, { boolean = false, string = "0", number = 0, array = {0, 1, 2, 3}, set = {0, 1, 2, 3} }); |
871c847dcf77
tests/modulemanager_option_conversion.lua: Add standalone test script for the new modulemanager config option API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 |