Skip to content

Commit

Permalink
Formatted Files
Browse files Browse the repository at this point in the history
Co-authored-by: Josh <[email protected]>
  • Loading branch information
ChristophLHR and ColdIV committed Dec 7, 2023
1 parent 39a8553 commit f49b5f6
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 55 deletions.
6 changes: 1 addition & 5 deletions libs/scm/config.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@


---@class SCMConfig
local Config = {}
SCM.Config = Config
do


---@class SCMConfigData
Config.config = {
-- Git Settings (In this case on GitHub, not tested with others)
Expand Down Expand Up @@ -57,7 +53,7 @@ do
---@param config SCMConfigData | nil
function Config:saveConfig(config)
config = config or self.config

local file = fs.open(config["configDirectory"] .. config["configFile"], "w")
if not file then
os.execute("mkdir " .. config["configDirectory"])
Expand Down
11 changes: 0 additions & 11 deletions libs/scm/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@
local UI = {}
SCM.UI = UI
do
--Redundant
function UI:printUsage()
print("Usage: scm <command> [args]")
print("Commands:")
print(" add <name> [src]")
print(" update [name] [src]")
print(" remove <name>")
print(" list")
print(" config <name> [value]")
end

function UI:listScripts()
local scripts = SCM.ScriptManager.scripts
print("name", "type")
Expand Down
1 change: 0 additions & 1 deletion scmInstaller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ function SCMInstaller:deleteFiles(files)
end
end

-- download the files
function SCMInstaller:downloadFiles(source, files)
for index, value in ipairs(files) do
print('Downloading ' .. index .. ' of ' .. #files .. ' files: ' .. value)
Expand Down
16 changes: 8 additions & 8 deletions tests/Suite/fs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fs.progPath = "tmpProg/"
do
fs.open = function(path, mode)
assert("string" == type(path), tostring(path) .. "path must be a string")
assert("string" == type(mode), tostring(mode) .." mode must be a string")
assert("string" == type(mode), tostring(mode) .. " mode must be a string")
local file = io.open(path, mode)
if not file then
-- find all occurences of / in the path
Expand All @@ -27,13 +27,13 @@ do
file = io.open(path, mode)
end
if mode == "w" then
assert(file, "file could not be opened in : "..path.. " Mode : "..mode)
assert(file, "file could not be opened in : " .. path .. " Mode : " .. mode)
end
if not file then
return nil
end
local file2 = {}
setmetatable(file2, {__index = file})
setmetatable(file2, { __index = file })
file2.base = file
file2.readAll = function()
return file2.base:read("*a")
Expand Down Expand Up @@ -68,7 +68,7 @@ do
assert("string" == type(dest), "dest must be a string")
local file = io.open(src, "r")
if not file then
print("file "..src.." not found")
print("file " .. src .. " not found")
return false
end
local content = file:read("*a")
Expand All @@ -93,7 +93,7 @@ do
end
file = io.open(dest, "w")
if not file then
print("file"..dest.." not found")
print("file" .. dest .. " not found")
return false
end
end
Expand Down Expand Up @@ -125,13 +125,13 @@ do
end
end

fs.delete = function (path)
fs.delete = function(path)
assert("string" == type(path), "path must be a string")
if fs.exists(path) then
os.execute("rm -rf " .. path)
end
end
fs.readAll = function (path)
fs.readAll = function(path)
assert("string" == type(path), "path must be a string")
local file = io.open(path, "r")
if not file then
Expand All @@ -142,4 +142,4 @@ do
return content
end
end
return fs
return fs
4 changes: 2 additions & 2 deletions tests/Suite/helperFunctions.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function table.copy(t)
local u = { }
local u = {}
for k, v in pairs(t) do u[k] = v end
return setmetatable(u, getmetatable(t))
end
end
34 changes: 17 additions & 17 deletions tests/Suite/json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ local function kind_of(obj)
end

local function escape_str(s)
local in_char = {'\\', '"', '/', '\b', '\f', '\n', '\r', '\t'}
local out_char = {'\\', '"', '/', 'b', 'f', 'n', 'r', 't'}
local in_char = { '\\', '"', '/', '\b', '\f', '\n', '\r', '\t' }
local out_char = { '\\', '"', '/', 'b', 'f', 'n', 'r', 't' }
for i, c in ipairs(in_char) do
s = s:gsub(c, '\\' .. out_char[i])
end
Expand Down Expand Up @@ -80,10 +80,10 @@ local function parse_str_val(str, pos, val)
local early_end_error = 'End of input found while parsing string.'
if pos > #str then error(early_end_error) end
local c = str:sub(pos, pos)
if c == '"' then return val, pos + 1 end
if c == '"' then return val, pos + 1 end
if c ~= '\\' then return parse_str_val(str, pos + 1, val .. c) end
-- We must have a \ character.
local esc_map = {b = '\b', f = '\f', n = '\n', r = '\r', t = '\t'}
local esc_map = { b = '\b', f = '\f', n = '\n', r = '\r', t = '\t' }
local nextc = str:sub(pos + 1, pos + 1)
if not nextc then error(early_end_error) end
return parse_str_val(str, pos + 2, val .. (esc_map[nextc] or nextc))
Expand All @@ -101,8 +101,8 @@ end
-- Public values and functions.

function json.stringify(obj, as_key)
local s = {} -- We'll build the string as an array of strings to be concatenated.
local kind = kind_of(obj) -- This is 'array' if it's an array or type(obj) otherwise.
local s = {} -- We'll build the string as an array of strings to be concatenated.
local kind = kind_of(obj) -- This is 'array' if it's an array or type(obj) otherwise.
if kind == 'array' then
if as_key then error('Can\'t encode array as key.') end
s[#s + 1] = '['
Expand Down Expand Up @@ -136,25 +136,25 @@ function json.stringify(obj, as_key)
return table.concat(s)
end

json.null = {} -- This is a one-off table to represent the null value.
json.null = {} -- This is a one-off table to represent the null value.

function json.parse(str, pos, end_delim)
pos = pos or 1
if pos > #str then error('Reached unexpected end of input.') end
local pos = pos + #str:match('^%s*', pos) -- Skip whitespace.
local pos = pos + #str:match('^%s*', pos) -- Skip whitespace.
local first = str:sub(pos, pos)
if first == '{' then -- Parse an object.
if first == '{' then -- Parse an object.
local obj, key, delim_found = {}, true, true
pos = pos + 1
while true do
key, pos = json.parse(str, pos, '}')
if key == nil then return obj, pos end
if not delim_found then error('Comma missing between object items.') end
pos = skip_delim(str, pos, ':', true) -- true -> error if missing.
pos = skip_delim(str, pos, ':', true) -- true -> error if missing.
obj[key], pos = json.parse(str, pos)
pos, delim_found = skip_delim(str, pos, ',')
end
elseif first == '[' then -- Parse an array.
elseif first == '[' then -- Parse an array.
local arr, val, delim_found = {}, true, true
pos = pos + 1
while true do
Expand All @@ -164,14 +164,14 @@ function json.parse(str, pos, end_delim)
arr[#arr + 1] = val
pos, delim_found = skip_delim(str, pos, ',')
end
elseif first == '"' then -- Parse a string.
elseif first == '"' then -- Parse a string.
return parse_str_val(str, pos + 1)
elseif first == '-' or first:match('%d') then -- Parse a number.
elseif first == '-' or first:match('%d') then -- Parse a number.
return parse_num_val(str, pos)
elseif first == end_delim then -- End of an object or array.
elseif first == end_delim then -- End of an object or array.
return nil, pos + 1
else -- Parse true, false, or null.
local literals = {['true'] = true, ['false'] = false, ['null'] = json.null}
else -- Parse true, false, or null.
local literals = { ['true'] = true, ['false'] = false, ['null'] = json.null }
for lit_str, lit_val in pairs(literals) do
local lit_end = pos + #lit_str - 1
if str:sub(pos, lit_end) == lit_str then return lit_val, lit_end + 1 end
Expand All @@ -181,4 +181,4 @@ function json.parse(str, pos, end_delim)
end
end

return json
return json
2 changes: 1 addition & 1 deletion tests/testSuite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ _G.http = {
_G.shell = {
-- TODO: implement shell - CompleteFunction
["setCompletionFunction"] = function(...) return end,
["run"] = function (...) return end
["run"] = function(...) return end
}

-- Just any day, does not matter as of now
Expand Down
22 changes: 12 additions & 10 deletions tests/test_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ end
describe("Testing everything about SCM:", function()
--only neccessary for local testing
describe("Copy Files", function()

assert.is_true(fs.copy("./scm.lua", "tmpFiles/scm.lua"), "Could not copy scm.lua")
assert.is_true(fs.copy("./libs/scm/config.lua", "tmpFiles/config.lua"), "Could not copy config.lua")
assert.is_true(fs.copy("./libs/scm/net.lua", "tmpFiles/net.lua"), "Could not copy net.lua")
assert.is_true(fs.copy("./libs/scm/log.lua", "tmpFiles/log.lua"), "Could not copy log.lua")
assert.is_true(fs.copy("./libs/scm/scriptManager.lua", "tmpFiles/scriptManager.lua"), "Could not copy scriptManager.lua")
assert.is_true(fs.copy("./libs/scm/autocomplete.lua", "tmpFiles/autocomplete.lua"), "Could not copy autocomplete.lua")
assert.is_true(fs.copy("./libs/scm/scriptManager.lua", "tmpFiles/scriptManager.lua"),
"Could not copy scriptManager.lua")
assert.is_true(fs.copy("./libs/scm/autocomplete.lua", "tmpFiles/autocomplete.lua"),
"Could not copy autocomplete.lua")
assert.is_true(fs.copy("./libs/scm/ui.lua", "tmpFiles/ui.lua"), "Could not copy ui.lua")
end)

Expand Down Expand Up @@ -163,10 +164,10 @@ describe("Testing everything about SCM:", function()
end
)
end)
describe("Load Remote", function ()
describe("Load Remote", function()
it("Get TestLib", function()
runTests(
---@param scm SCM
---@param scm SCM
function(scm)
local testScript = scm:load("scmTest")
local scriptManager = scm.ScriptManager
Expand All @@ -179,14 +180,13 @@ describe("Testing everything about SCM:", function()
describe("Update SCM", function()
it("Update SCM", function()
runTests(
---@param scm SCM
---@param scm SCM
function(scm)
-- TODO: implement
end
)
end)
end)

end)

-- only neccessary for local testing
Expand All @@ -195,9 +195,11 @@ describe("Testing everything about SCM:", function()
assert.is_true(fs.copy("tmpFiles/config.lua", "./libs/scm/config.lua"), "Could not restore config.lua")
assert.is_true(fs.copy("tmpFiles/net.lua", "./libs/scm/net.lua"), "Could not restore net.lua")
assert.is_true(fs.copy("tmpFiles/log.lua", "./libs/scm/log.lua"), "Could not restore log.lua")
assert.is_true(fs.copy("tmpFiles/scriptManager.lua", "./libs/scm/scriptManager.lua"), "Could not restore scriptManager.lua")
assert.is_true(fs.copy("tmpFiles/autocomplete.lua", "./libs/scm/autocomplete.lua"), "Could not restore autocomplete.lua")
assert.is_true(fs.copy("tmpFiles/scriptManager.lua", "./libs/scm/scriptManager.lua"),
"Could not restore scriptManager.lua")
assert.is_true(fs.copy("tmpFiles/autocomplete.lua", "./libs/scm/autocomplete.lua"),
"Could not restore autocomplete.lua")
assert.is_true(fs.copy("tmpFiles/ui.lua", "./libs/scm/ui.lua"), "Could not restore ui.lua")
os.execute("rm --recursive ./tmpFiles")
end)
end)
end)

0 comments on commit f49b5f6

Please sign in to comment.