<commit_before>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()
        assert.is_same(#Defaults.defaults_name, 78)
        assert.is_same(Defaults.defaults_name[29], 'DHINTCOUNT')
    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
        Defaults.changed[14] = true
        Defaults.changed[19] = true
        Defaults.changed[29] = true
        Defaults.changed[64] = true
        Defaults.changed[78] = true
        Defaults:SaveSettings()
        assert.is_same(#Defaults.defaults_name, 78)
        assert.is_same(Defaults.defaults_name[29], 'DHINTCOUNT')
        assert.is_same(Defaults.defaults_name[78], 'SEARCH_TITLE')
        assert.is_same(Defaults.defaults_name[64], 'DTAP_ZONE_MENU')
        assert.is_same(Defaults.defaults_name[19], 'DCREREADER_VIEW_MODE')
        assert.is_same(Defaults.defaults_name[14],
                       'DCREREADER_CONFIG_MARGIN_SIZES_LARGE')
        local fd = io.open(persistent_filename, "r")
        assert.Equals(
[[-- For configuration changes that persists between updates
SEARCH_TITLE = true
DCREREADER_CONFIG_MARGIN_SIZES_LARGE = {
    [1] = 20,
    [2] = 20,
    [3] = 20,
    [4] = 20
}
DCREREADER_VIEW_MODE = "page"
DHINTCOUNT = 1
DTAP_ZONE_MENU = {
    ["y"] = 0,
    ["x"] = 0.125,
    ["h"] = 0.25,
    ["w"] = 0.75
}
]],
                       fd:read("*a"))
        fd:close()

        -- in persistent
        Defaults:init()
        Defaults.changed[29] = true
        Defaults.defaults_value[29] = 2
        Defaults.changed[64] = true
        Defaults.defaults_value[64] = {
            y = 10,
            x = 10.125,
            h = 20.25,
            w = 20.75
        }
        Defaults:SaveSettings()
        fd = io.open(persistent_filename)
        assert.Equals(
[[-- For configuration changes that persists between updates
SEARCH_TITLE = true
DHINTCOUNT = 2
DTAP_ZONE_MENU = {
    ["y"] = 10,
    ["x"] = 10.125,
    ["h"] = 20.25,
    ["w"] = 20.75
}
DCREREADER_CONFIG_MARGIN_SIZES_LARGE = {
    [1] = 20,
    [2] = 20,
    [3] = 20,
    [4] = 20
}
DCREREADER_VIEW_MODE = "page"
]],
                       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
DCREREADER_CONFIG_MARGIN_SIZES_LARGE = {
    [1] = 20,
    [2] = 20,
    [3] = 20,
    [4] = 20
}
DCREREADER_VIEW_MODE = "page"
DHINTCOUNT = 2
]])
        fd:close()

        -- in persistent
        Defaults:init()
        Defaults.changed[29] = true
        Defaults.defaults_value[29] = 1
        Defaults:SaveSettings()
        fd = io.open(persistent_filename)
        assert.Equals(
[[-- For configuration changes that persists between updates
SEARCH_TITLE = true
DCREREADER_VIEW_MODE = "page"
DCREREADER_CONFIG_MARGIN_SIZES_LARGE = {
    [1] = 20,
    [2] = 20,
    [3] = 20,
    [4] = 20
}
]],
                       fd:read("*a"))
        fd:close()
        os.remove(persistent_filename)
    end)
end)<commit_msg>fix unit test of defaults since we deleted one global default I'm afraid this unit test is not maintainable, each time we change the structure of the defaults.lua we must change this spec accordingly. We probably will get rid of defaults.lua as well as the filemanagersetdefaults and this spec.<commit_after>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()
        assert.is_same(#Defaults.defaults_name, 77)
        assert.is_same(Defaults.defaults_name[28], 'DHINTCOUNT')
    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
        Defaults.changed[14] = true
        Defaults.changed[19] = true
        Defaults.changed[28] = true
        Defaults.changed[63] = true
        Defaults.changed[77] = true
        Defaults:SaveSettings()
        assert.is_same(#Defaults.defaults_name, 77)
        assert.is_same(Defaults.defaults_name[28], 'DHINTCOUNT')
        assert.is_same(Defaults.defaults_name[77], 'SEARCH_TITLE')
        assert.is_same(Defaults.defaults_name[63], 'DTAP_ZONE_MENU')
        assert.is_same(Defaults.defaults_name[19], 'DCREREADER_VIEW_MODE')
        assert.is_same(Defaults.defaults_name[14],
                       'DCREREADER_CONFIG_MARGIN_SIZES_LARGE')
        local fd = io.open(persistent_filename, "r")
        assert.Equals(
[[-- For configuration changes that persists between updates
SEARCH_TITLE = true
DCREREADER_CONFIG_MARGIN_SIZES_LARGE = {
    [1] = 20,
    [2] = 20,
    [3] = 20,
    [4] = 20
}
DCREREADER_VIEW_MODE = "page"
DHINTCOUNT = 1
DTAP_ZONE_MENU = {
    ["y"] = 0,
    ["x"] = 0.125,
    ["h"] = 0.25,
    ["w"] = 0.75
}
]],
                       fd:read("*a"))
        fd:close()

        -- in persistent
        Defaults:init()
        Defaults.changed[28] = true
        Defaults.defaults_value[28] = 2
        Defaults.changed[63] = true
        Defaults.defaults_value[63] = {
            y = 10,
            x = 10.125,
            h = 20.25,
            w = 20.75
        }
        Defaults:SaveSettings()
        fd = io.open(persistent_filename)
        assert.Equals(
[[-- For configuration changes that persists between updates
SEARCH_TITLE = true
DHINTCOUNT = 2
DTAP_ZONE_MENU = {
    ["y"] = 10,
    ["x"] = 10.125,
    ["h"] = 20.25,
    ["w"] = 20.75
}
DCREREADER_CONFIG_MARGIN_SIZES_LARGE = {
    [1] = 20,
    [2] = 20,
    [3] = 20,
    [4] = 20
}
DCREREADER_VIEW_MODE = "page"
]],
                       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
DCREREADER_CONFIG_MARGIN_SIZES_LARGE = {
    [1] = 20,
    [2] = 20,
    [3] = 20,
    [4] = 20
}
DCREREADER_VIEW_MODE = "page"
DHINTCOUNT = 2
]])
        fd:close()

        -- in persistent
        Defaults:init()
        Defaults.changed[28] = true
        Defaults.defaults_value[28] = 1
        Defaults:SaveSettings()
        fd = io.open(persistent_filename)
        assert.Equals(
[[-- For configuration changes that persists between updates
SEARCH_TITLE = true
DCREREADER_VIEW_MODE = "page"
DCREREADER_CONFIG_MARGIN_SIZES_LARGE = {
    [1] = 20,
    [2] = 20,
    [3] = 20,
    [4] = 20
}
]],
                       fd:read("*a"))
        fd:close()
        os.remove(persistent_filename)
    end)
end)
{'fraction_non_alphanumeric': 0.12304914226750935, 'fraction_numerical': 0.034051334967109506, 'mean_word_length': 2.5038409399005874, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6690189', 'n_tokens_mistral': 2778, 'n_tokens_neox': 2509, 'n_words': 533}