2016-05-02 02:39:31 +00:00
|
|
|
describe("defaults module", function()
|
|
|
|
local Defaults, DataStorage
|
|
|
|
setup(function()
|
|
|
|
require("commonrequire")
|
|
|
|
Defaults = require("apps/filemanager/filemanagersetdefaults")
|
|
|
|
DataStorage = require("datastorage")
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("should load all defaults from defaults.lua", function()
|
|
|
|
Defaults:init()
|
2019-05-01 00:09:01 +00:00
|
|
|
assert.is_same(113, #Defaults.defaults_name)
|
|
|
|
assert.is_same("DFULL_SCREEN", Defaults.defaults_name[57])
|
2016-05-02 02:39:31 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
it("should save changes to defaults.persistent.lua", function()
|
|
|
|
local persistent_filename = DataStorage:getDataDir() .. "/defaults.persistent.lua"
|
|
|
|
os.remove(persistent_filename)
|
|
|
|
|
|
|
|
-- not in persistent but checked in defaults
|
2019-03-14 23:34:46 +00:00
|
|
|
Defaults.changed[21] = true
|
2019-05-01 00:09:01 +00:00
|
|
|
Defaults.changed[48] = true
|
|
|
|
Defaults.changed[57] = true
|
|
|
|
Defaults.changed[92] = true
|
|
|
|
Defaults.changed[108] = true
|
2016-07-17 05:46:17 +00:00
|
|
|
Defaults:saveSettings()
|
2019-05-01 00:09:01 +00:00
|
|
|
assert.is_same(113, #Defaults.defaults_name)
|
|
|
|
assert.is_same("DFULL_SCREEN", Defaults.defaults_name[57])
|
|
|
|
assert.is_same("SEARCH_LIBRARY_PATH", Defaults.defaults_name[108])
|
|
|
|
assert.is_same("DTAP_ZONE_BACKWARD", Defaults.defaults_name[92])
|
|
|
|
assert.is_same("DCREREADER_CONFIG_WORD_GAP_LARGE", Defaults.defaults_name[48])
|
|
|
|
assert.is_same("DCREREADER_CONFIG_H_MARGIN_SIZES_XXX_LARGE", Defaults.defaults_name[21])
|
2016-05-02 02:39:31 +00:00
|
|
|
local fd = io.open(persistent_filename, "r")
|
|
|
|
assert.Equals(
|
|
|
|
[[-- For configuration changes that persists between updates
|
2019-03-01 14:17:46 +00:00
|
|
|
SEARCH_LIBRARY_PATH = ""
|
|
|
|
DTAP_ZONE_BACKWARD = {
|
2016-05-02 02:39:31 +00:00
|
|
|
["y"] = 0,
|
2019-03-01 14:17:46 +00:00
|
|
|
["x"] = 0,
|
|
|
|
["h"] = 1,
|
|
|
|
["w"] = 0.25
|
|
|
|
}
|
|
|
|
DCREREADER_CONFIG_WORD_GAP_LARGE = 100
|
2019-05-01 00:09:01 +00:00
|
|
|
DCREREADER_CONFIG_H_MARGIN_SIZES_XXX_LARGE = {
|
|
|
|
[1] = 50,
|
|
|
|
[2] = 50
|
2016-05-02 02:39:31 +00:00
|
|
|
}
|
2019-05-01 00:09:01 +00:00
|
|
|
DFULL_SCREEN = 1
|
2016-05-02 02:39:31 +00:00
|
|
|
]],
|
|
|
|
fd:read("*a"))
|
|
|
|
fd:close()
|
|
|
|
|
|
|
|
-- in persistent
|
|
|
|
Defaults:init()
|
2019-05-01 00:09:01 +00:00
|
|
|
Defaults.changed[57] = true
|
|
|
|
Defaults.defaults_value[57] = 2
|
|
|
|
Defaults.changed[92] = true
|
|
|
|
Defaults.defaults_value[92] = {
|
2016-05-02 02:39:31 +00:00
|
|
|
y = 10,
|
|
|
|
x = 10.125,
|
|
|
|
h = 20.25,
|
|
|
|
w = 20.75
|
|
|
|
}
|
2016-07-17 05:46:17 +00:00
|
|
|
Defaults:saveSettings()
|
2016-05-02 02:39:31 +00:00
|
|
|
fd = io.open(persistent_filename)
|
|
|
|
assert.Equals(
|
|
|
|
[[-- For configuration changes that persists between updates
|
2019-03-01 14:17:46 +00:00
|
|
|
SEARCH_LIBRARY_PATH = ""
|
|
|
|
DTAP_ZONE_BACKWARD = {
|
2016-05-02 02:39:31 +00:00
|
|
|
["y"] = 10,
|
|
|
|
["x"] = 10.125,
|
|
|
|
["h"] = 20.25,
|
|
|
|
["w"] = 20.75
|
|
|
|
}
|
2019-03-01 14:17:46 +00:00
|
|
|
DCREREADER_CONFIG_WORD_GAP_LARGE = 100
|
2019-05-01 00:09:01 +00:00
|
|
|
DCREREADER_CONFIG_H_MARGIN_SIZES_XXX_LARGE = {
|
|
|
|
[2] = 50,
|
|
|
|
[1] = 50
|
2016-05-02 02:39:31 +00:00
|
|
|
}
|
2019-05-01 00:09:01 +00:00
|
|
|
DFULL_SCREEN = 2
|
2016-05-26 07:44:42 +00:00
|
|
|
]],
|
|
|
|
fd:read("*a"))
|
|
|
|
fd:close()
|
|
|
|
os.remove(persistent_filename)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("should delete entry from defaults.persistent.lua if value is reverted back to default", function()
|
|
|
|
local persistent_filename = DataStorage:getDataDir() .. "/defaults.persistent.lua"
|
|
|
|
local fd = io.open(persistent_filename, "w")
|
|
|
|
fd:write(
|
|
|
|
[[-- For configuration changes that persists between updates
|
|
|
|
SEARCH_TITLE = true
|
2019-05-01 00:09:01 +00:00
|
|
|
DCREREADER_CONFIG_H_MARGIN_SIZES_LARGE = {
|
|
|
|
[1] = 15,
|
|
|
|
[2] = 15
|
2016-05-26 07:44:42 +00:00
|
|
|
}
|
|
|
|
DCREREADER_VIEW_MODE = "page"
|
|
|
|
DHINTCOUNT = 2
|
|
|
|
]])
|
|
|
|
fd:close()
|
|
|
|
|
|
|
|
-- in persistent
|
|
|
|
Defaults:init()
|
2019-05-01 00:09:01 +00:00
|
|
|
Defaults.changed[57] = true
|
|
|
|
Defaults.defaults_value[57] = 1
|
2016-07-17 05:46:17 +00:00
|
|
|
Defaults:saveSettings()
|
2016-05-26 07:44:42 +00:00
|
|
|
fd = io.open(persistent_filename)
|
|
|
|
assert.Equals(
|
|
|
|
[[-- For configuration changes that persists between updates
|
|
|
|
SEARCH_TITLE = true
|
2019-05-01 00:09:01 +00:00
|
|
|
DCREREADER_CONFIG_H_MARGIN_SIZES_LARGE = {
|
|
|
|
[2] = 15,
|
|
|
|
[1] = 15
|
2016-05-26 07:44:42 +00:00
|
|
|
}
|
2019-05-01 00:09:01 +00:00
|
|
|
DHINTCOUNT = 2
|
2019-03-01 14:17:46 +00:00
|
|
|
DFULL_SCREEN = 1
|
|
|
|
DCREREADER_VIEW_MODE = "page"
|
2016-05-02 02:39:31 +00:00
|
|
|
]],
|
|
|
|
fd:read("*a"))
|
|
|
|
fd:close()
|
|
|
|
os.remove(persistent_filename)
|
|
|
|
end)
|
|
|
|
end)
|