Skip to content

Commit

Permalink
More tests (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
demonnic committed Aug 12, 2022
1 parent a8017ce commit 4293382
Show file tree
Hide file tree
Showing 3 changed files with 281 additions and 33 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches: [ main ]
pull_request:
branches: [ main ]

workflow_dispatch:

jobs:
Expand All @@ -14,16 +14,16 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Muddle
uses: demonnic/build-with-muddler@v1.3

- name: Upload MPackage
uses: actions/upload-artifact@v2
with:
name: MDK-package
path: build/tmp/

- name: Run Busted tests
uses: demonnic/test-in-mudlet@v1.1
with:
Expand Down
68 changes: 64 additions & 4 deletions src/resources/ftext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
-- @author Damian Monogue <demonnic@gmail.com>
-- @copyright 2020 Damian Monogue
-- @copyright 2021 Damian Monogue
-- @copyright 2022 Damian Monogue
-- @license MIT, see LICENSE.lua
local ftext = {}
local dec = {"d", "decimal", "dec"}
Expand Down Expand Up @@ -477,7 +478,7 @@ end
-- @license MIT, see LICENSE.lua

local TextFormatter = {}
TextFormatter.validFormatTypes = {'d', 'dec', 'decimal', 'h', 'hex', 'hexidecimal', 'c', 'color', 'colour', 'col', 'name'}
TextFormatter.validFormatTypes = {'d', 'dec', 'decimal', 'h', 'hex', 'hexidecimal', 'c', 'color', 'colour', 'col', 'name', 'none', 'e', 'plain', ''}

--- Set's the formatting type whether it's for cecho, decho, or hecho
-- @tparam string typeToSet What type of formatter is this? Valid options are { 'd', 'dec', 'decimal', 'h', 'hex', 'hexidecimal', 'c', 'color', 'colour', 'col', 'name'}
Expand Down Expand Up @@ -626,6 +627,17 @@ function TextFormatter:setMirror(shouldMirror)
self.options.mirror = shouldMirror
end

--- Set whether we should remove the gap spaces between the text and spacer characters. "===some text===" if set to true, "== some text ==" if set to false
-- @tparam boolean noGap
function TextFormatter:setNoGap(noGap)
local argumentType = type(noGap)
noGap = self:toBoolean(noGap)
if noGap == nil then
error("TextFormatter:setNoGap(noGap): Argument error, boolean expected, got " .. argumentType)
end
self.options.noGap = noGap
end

--- Format a string based on the stored options
-- @tparam string str The string to format
function TextFormatter:format(str)
Expand Down Expand Up @@ -778,6 +790,14 @@ function TableMaker:insert(tbl, pos, item)
end
end

--- Get the TextFormatter which defines the format of a specific column
-- @tparam number position The position of the column you're getting, counting from the left. If not provided will return the last column.
function TableMaker:getColumn(position)
position = position or #self.columns
position = self:checkPosition(position, "TableMaker:getColumn(position)")
return self.columns[position]
end

--- Adds a column definition for the table.
-- @tparam table options Table of options suitable for a TextFormatter object. See https://github.com/demonnic/fText/wiki/fText
-- @tparam number position The position of the column you're adding, counting from the left. If not provided will add it as the last column
Expand Down Expand Up @@ -834,6 +854,15 @@ function TableMaker:replaceColumn(options, position)
self.columns[position] = formatter
end

--- Gets the row of output at a specific position
-- @tparam number position The position of the row you want to get, coutning from the top down. If not provided defaults to the last row in the table
-- @return table of entries in the specified row
function TableMaker:getRow(position)
position = position or #self.rows
position = self:checkPosition(position, "TableMaker:getRow(position)")
return self.rows[position]
end

--- Adds a row of output to the table
-- @tparam table columnEntries This indexed table contains an entry for each column in the table. Entries in the table must be strings, a table of options for insertPopup or insertLink, or a function which returns one of these things
-- @tparam number position position for the row you want to add, counting from the top down. If not provided defaults to the last line in the table.
Expand Down Expand Up @@ -926,6 +955,38 @@ function TableMaker:checkNumber(num)
return tonumber(num)
end

--- Get the contents and formatter for a specific cell
-- @tparam number row the row number of the cell, counted top down.
-- @tparam number column the column number of the cell, counted from the left.
-- @return the base text and TextFormatter for the cell at the specific row and column number
function TableMaker:getCell(row, column)
local rowType = type(row)
local columnType = type(column)
local maxRow = #self.rows
local maxColumn = #self.columns
local ae = "TableMaker:getCell(row, column): Argument error:"
row = self:checkNumber(row)
column = self:checkNumber(column)
if row == 0 then
if rowType ~= "number" then
printError(f"{ae} row as number expected, got {rowType}", true, true)
else
printError(f"{ae} rows start at 1, and you asked for row 0", true, true)
end
elseif column == 0 then
if columnType ~= "number" then
printError(f"{ae} column as number expected, got {columnType}", true, true)
else
printError(f"{ae} columns start at 1, and you asked for column 0", true, true)
end
elseif row > maxRow then
printError(f"{ae} row exceeds number of rows in table ({maxRow})")
elseif column > maxColumn then
printError(f"{ae} column exceeds number of columns in table ({maxColumn})", true, true)
end
return self.rows[row][column], self.columns[column]
end

--- Sets a specific cell's display information
-- @tparam number row the row number of the cell, counted from the top down
-- @tparam number column the column number of the cell, counted from the left
Expand All @@ -951,11 +1012,10 @@ function TableMaker:setCell(row, column, entry)
local entryType = type(entry)
entry = self:checkEntry(entry)
if entry == 0 then
if type(entry) == "function" then
if entryType == "function" then
error(ae .. " entry was provided as a function, but does not return a string. We need a string in the end")
else
error("TableMaker:setCell(row, column, entry): Argument Error: entry must be a string, or a function which returns a string. You provided a " ..
entryType)
error("TableMaker:setCell(row, column, entry): Argument Error: entry must be a string, or a function which returns a string. You provided a " .. entryType)
end
end
self.rows[row][column] = entry
Expand Down
Loading

0 comments on commit 4293382

Please sign in to comment.