Initial Release. Version 1.1.
This commit is contained in:
48
src/resources/MDK/LICENSE.lua
Normal file
48
src/resources/MDK/LICENSE.lua
Normal file
@@ -0,0 +1,48 @@
|
||||
--[===[
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020 Damian Monogue
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
--]===]
|
||||
|
||||
-- schema validation provided by schema.lua, license below
|
||||
--[[
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Sebastian Schoener
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
]]
|
91
src/resources/MDK/README.md
Normal file
91
src/resources/MDK/README.md
Normal file
@@ -0,0 +1,91 @@
|
||||
# the demonnic MDK and You
|
||||
|
||||
This is a collection of Lua 'classes' and modules I wrote for Mudlet. It is largely targeted at scripters, and comes packaged in two ways depending on how you intend to use/distribute your work. Please see [Installation](#installation) for more details
|
||||
|
||||
## Documentation
|
||||
|
||||
The [MDK wiki](https://github.com/demonnic/MDK/wiki) contains an entry for each module or class, as well as examples.
|
||||
|
||||
Starting with alpha2 of the MDK, the ldocs generated from code are included in the zipped releases. The current release's ldocs can always be viewed at <https://demonnic.github.io/mdk/current/>
|
||||
|
||||
## Installation
|
||||
|
||||
How you 'install' the MDK depends on how you intend to use it.
|
||||
|
||||
### I just want to install the MDK for my own personal use
|
||||
|
||||
You just want to get your hands on the goods, and aren't looking to use any MDK items in an exported package for sharing or anything like that.
|
||||
Well, you are who the mdk mpackage is for! Download the MDK.mpackage from your desired release on the [Releases](https://github.com/demonnic/MDK/releases) page and install it in the package manager. The examples in the [wiki](https://demonnic.github.io/mdk/current/) are written with this in mind, and you would require the items you need as `local EMCO = require("MDK.emco")`
|
||||
|
||||
### I am a package author looking to include/use one of the MDK modules or classes in my package
|
||||
|
||||
You should download the `demonnic-MDK-<version>.zip` file for your desired release on the [Releases](https://github.com/demonnic/MDK/releases) page.
|
||||
Inside are the individual .lua files for the modules and classes described in the [wiki](https://demonnic.github.io/mdk/current/) and [API docs](https://demonnic.github.io/mdk/current/).
|
||||
You can include all of them if you wish, or only the ones you actually make use of. I ask that you include the LICENSE.lua or LICENSE-MDK.lua file (depending on the release) file in addition.
|
||||
They should go in the root of your package, so that when your package is installed the files can be found at `getMudletHomeDir() .. "/<packagename>/emco.lua"`. You would then use `local EMCO = require("<mypackagename>.emco")`
|
||||
So for example if your package name is "MySuperCoolPackage" and it installs to `getMudletHomeDir() .. "/MySuperCoolPackage/"` then you use `local EMCO = require("MySuperCoolPackage.emco")` and the emco.lua file should be at `getMudletHomeDir() .. "/MySuperCoolPackage/emco.lua"`
|
||||
|
||||
## Files (Modules/Classes)
|
||||
|
||||
These files contain the modules in the MDK. You only need to include those files which you intend to use, except as noted in the descriptions below.
|
||||
If you include any of the modules from the MDK, you should also include LICENSE.lua or LICENSE-MDK.lua. It contains the licenses for my modules and for luaunit and lua-schema which are not my original works.
|
||||
You should maybe also include demontools.lua, as it notes below several other of the MDK modules make use of items within it.
|
||||
|
||||
* aliasmgr.ua
|
||||
* Object to manage tempAliases programmatically. <https://github.com/demonnic/MDK/wiki/AliasMgr>
|
||||
|
||||
* chyron.lua
|
||||
* Label which moves a message across its face from right to left, like a stock ticker or the news chyrons. Documentation at <https://github.com/demonnic/MDK/wiki/Chyron>
|
||||
|
||||
* demontools.lua
|
||||
* Collection of miscellaneous useful functions. You should include this file if you use the MDK, as several other modules make use of it. Include functions for converting c/d/hecho, html, and ansi colored strings between each other, mkdir_p, and some others. <https://github.com/demonnic/MDK/wiki/DemonTools>
|
||||
|
||||
* emco.lua
|
||||
* EMCO. Documentation at <https://github.com/demonnic/MDK/wiki/EMCO> Will make use of LoggingConsole if loggingconsole.lua and demontools.lua are included
|
||||
|
||||
* figlet.lua
|
||||
* Creates FIGlets from strings
|
||||
* Reference package with multiple fonts and color gradients at <https://github.com/demonnic/figinator>
|
||||
|
||||
* ftext.lua
|
||||
* basic fText. Documentation at <https://github.com/demonnic/MDK/wiki/fText>
|
||||
* now includes TextFormatter and TableMaker as ftext.TextFormatter and ftext.TableMaker
|
||||
|
||||
* gradientmaker.lua
|
||||
* Functions for creating color gradients for use with c/d/hecho. Documentation at <https://github.com/demonnic/MDK/wiki/GradientMaker>
|
||||
|
||||
* loggingconsole.lua
|
||||
* Self logging extension to the mini console. Works just like a Geyser.MiniConsole but adds a templated path and fileName constraint, as well as logFormat so it can log what is echod or appended to it. Requires demontools.lua in order to work.
|
||||
|
||||
* loginator.lua
|
||||
* Creates objects for logging messages to disk. <https://github.com/demonnic/MDK/wiki/Loginator>
|
||||
|
||||
* mastermindsolver.lua
|
||||
* A class which will help you solve Master Mind puzzles. <https://github.com/demonnic/MDK/wiki/MasterMindSolver>
|
||||
|
||||
* revisionator.lua
|
||||
* A class which aims to make upgrading between package versions easier by storing and running patch functions. <https://github.com/demonnic/MDK/wiki/Revisionator>
|
||||
|
||||
* sortbox.lua
|
||||
* SortBox, an alternative to H/VBox which can be either, and also provides options for sorting its contents. Overview at <https://github.com/demonnic/MDK/wiki/SortBox>
|
||||
|
||||
* spinbox.lua
|
||||
* SpinBox, a Geyser element for adjusting numbers with your mouse. Overview at <https://github.com/demonnic/MDK/wiki/SpinBox>
|
||||
|
||||
* sug.lua
|
||||
* Self Updating Gauges, will watch a set of variables and update itself on a timer based on what values those variables hold. Documentation at <https://github.com/demonnic/MDK/wiki/SelfUpdatingGauge>
|
||||
|
||||
* textgauge.lua
|
||||
* TextGauges, what it says on the tin. Documentation at <https://github.com/demonnic/MDK/wiki/TextGauge>
|
||||
|
||||
* timergauge.lua
|
||||
* TimerGauge, an extension of Geyser.Gauge which serves as an animated countdown timer. Overview at <https://github.com/demonnic/MDK/wiki/TimerGauge>
|
||||
|
||||
## Others people's work I depend upon
|
||||
|
||||
* schema.lua
|
||||
* lua-schema, for defining table schema. Documentation at <https://github.com/sschoener/lua-schema>
|
||||
* will be used by Archon for ensuring configuration tables are as they should be.
|
||||
|
||||
* LICENSE.lua
|
||||
* Contains the license information for MDK, as well as lua-schema and luaunit which have been included.
|
1697
src/resources/MDK/ftext.lua
Normal file
1697
src/resources/MDK/ftext.lua
Normal file
File diff suppressed because it is too large
Load Diff
447
src/resources/MDK/ftext_spec.lua
Normal file
447
src/resources/MDK/ftext_spec.lua
Normal file
@@ -0,0 +1,447 @@
|
||||
local ftext = require("MDK.ftext")
|
||||
|
||||
describe("ftext:", function()
|
||||
describe("ftext.fText:", function()
|
||||
local fText = ftext.fText
|
||||
|
||||
it("Should properly center text", function()
|
||||
local expected = " some text "
|
||||
local actual = fText("some text", {width = 20})
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
|
||||
it("Should properly pad left aligned text", function()
|
||||
local expected = "some text "
|
||||
local actual = fText("some text", {width = 20, alignment = "left"})
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
|
||||
it("Should properly pad right aligned text", function()
|
||||
local expected = " some text"
|
||||
local actual = fText("some text", {width = 20, alignment = "right"})
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
|
||||
it("Should wrap lines to the correct length", function()
|
||||
local str = "This is a test of the emergency broadcast system. This is only a test"
|
||||
local options = {width = 10, alignment = "centered"}
|
||||
local actual = fText(str, options)
|
||||
for _, line in ipairs(actual:split("\n")) do
|
||||
assert.equals(line:len(), 10)
|
||||
end
|
||||
options.width = 15
|
||||
actual = fText(str, options)
|
||||
for _, line in ipairs(actual:split("\n")) do
|
||||
assert.equals(line:len(), 15)
|
||||
end
|
||||
end)
|
||||
|
||||
describe("non-space spacer character:", function()
|
||||
local str = "some text"
|
||||
local options = {width = "20", alignment = "left", spacer = "="}
|
||||
it("Should work with left align", function()
|
||||
local expected = "some text =========="
|
||||
local actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
|
||||
it("Should work with right align", function()
|
||||
local expected = "========== some text"
|
||||
options.alignment = "right"
|
||||
local actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
|
||||
it("Should work with center align", function()
|
||||
local expected = ("==== some text =====")
|
||||
options.alignment = "center"
|
||||
local actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("nogap option:", function()
|
||||
local str = "some text"
|
||||
local options = {width = "20", alignment = "left", spacer = "=", nogap = true}
|
||||
|
||||
it("Should work with left align", function()
|
||||
local expected = "some text==========="
|
||||
local actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
|
||||
it("Should work with right align", function()
|
||||
local expected = "===========some text"
|
||||
options.alignment = "right"
|
||||
local actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
|
||||
it("Should work with center align", function()
|
||||
local expected = "=====some text======"
|
||||
options.alignment = "center"
|
||||
local actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("cap functionality", function()
|
||||
local str = "some text"
|
||||
local options = {width = 20, spacer = "=", cap = "|"}
|
||||
|
||||
it("Should place the spacer outside the cap by default", function()
|
||||
local expected = "===| some text |===="
|
||||
local actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
|
||||
it("Should place it inside the cap if inside option is true", function()
|
||||
local expected = "|=== some text ====|"
|
||||
options.inside = true
|
||||
local actual = fText(str, options)
|
||||
options.inside = nil
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
|
||||
it("Should mirror certain characters with their opposites", function()
|
||||
local expected = "===[ some text ]===="
|
||||
options.mirror = true
|
||||
options.cap = "["
|
||||
local actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
options.inside = true
|
||||
expected = "[=== some text ====]"
|
||||
actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
options.inside = nil
|
||||
options.cap = "<"
|
||||
expected = "===< some text >===="
|
||||
actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
options.cap = "{"
|
||||
expected = "==={ some text }===="
|
||||
actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
options.cap = "("
|
||||
expected = "===( some text )===="
|
||||
actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
options.cap = "|"
|
||||
expected = "===| some text |===="
|
||||
actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("ftext.cfText", function()
|
||||
local cfText = ftext.cfText
|
||||
local str = "some text"
|
||||
local options = {
|
||||
width = 20,
|
||||
spacer = "=",
|
||||
cap = "[",
|
||||
inside = true,
|
||||
mirror = true,
|
||||
capColor = "<purple>",
|
||||
spacerColor = "<green>",
|
||||
textColor = "<red>",
|
||||
}
|
||||
it("Should handle cecho colored text", function()
|
||||
local expectedStripped = "[=== some text ====]"
|
||||
local expected = "<purple>[<reset><green>===<reset><red> some text <reset><green>====<reset><purple>]<reset>"
|
||||
local actual = cfText(str, options)
|
||||
local actualStripped = cecho2string(actual)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(expectedStripped, actualStripped)
|
||||
assert.equals(20, actualStripped:len())
|
||||
expectedStripped = "===[ some text ]===="
|
||||
expected = "<green>===<reset><purple>[<reset><red> some text <reset><purple>]<reset><green>====<reset>"
|
||||
options.inside = false
|
||||
actual = cfText(str, options)
|
||||
actualStripped = cecho2string(actual)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(expectedStripped, actualStripped)
|
||||
assert.equals(20, actualStripped:len())
|
||||
end)
|
||||
|
||||
it("Should wrap cecho lines to the correct length", function()
|
||||
local str = "This is a test of the emergency broadcast system. This is only a test"
|
||||
local options = {width = 10, alignment = "centered"}
|
||||
local actual = cfText(str, options)
|
||||
for _, line in ipairs(actual:split("\n")) do
|
||||
assert.equals(cecho2string(line):len(), 10)
|
||||
end
|
||||
options.width = 15
|
||||
actual = cfText(str, options)
|
||||
for _, line in ipairs(actual:split("\n")) do
|
||||
assert.equals(cecho2string(line):len(), 15)
|
||||
end
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
describe("ftext.dfText", function()
|
||||
local dfText = ftext.dfText
|
||||
local str = "some text"
|
||||
local options = {
|
||||
width = 20,
|
||||
spacer = "=",
|
||||
cap = "[",
|
||||
inside = true,
|
||||
mirror = true,
|
||||
capColor = "<160,32,240>",
|
||||
spacerColor = "<0,255,0>",
|
||||
textColor = "<255,0,0>",
|
||||
}
|
||||
it("Should handle decho colored text", function()
|
||||
local expectedStripped = "[=== some text ====]"
|
||||
local expected = "<160,32,240>[<r><0,255,0>===<r><255,0,0> some text <r><0,255,0>====<r><160,32,240>]<r>"
|
||||
local actual = dfText(str, options)
|
||||
local actualStripped = decho2string(actual)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(expectedStripped, actualStripped)
|
||||
assert.equals(20, actualStripped:len())
|
||||
expectedStripped = "===[ some text ]===="
|
||||
expected = "<0,255,0>===<r><160,32,240>[<r><255,0,0> some text <r><160,32,240>]<r><0,255,0>====<r>"
|
||||
options.inside = false
|
||||
actual = dfText(str, options)
|
||||
actualStripped = decho2string(actual)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(expectedStripped, actualStripped)
|
||||
assert.equals(20, actualStripped:len())
|
||||
end)
|
||||
|
||||
it("Should wrap decho lines to the correct length", function()
|
||||
local str = "This is a test of the emergency broadcast system. This is only a test"
|
||||
local options = {width = 10, alignment = "centered"}
|
||||
local actual = dfText(str, options)
|
||||
for _, line in ipairs(actual:split("\n")) do
|
||||
assert.equals(decho2string(line):len(), 10)
|
||||
end
|
||||
options.width = 15
|
||||
actual = dfText(str, options)
|
||||
for _, line in ipairs(actual:split("\n")) do
|
||||
assert.equals(decho2string(line):len(), 15)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("ftext.hfText", function()
|
||||
local hfText = ftext.hfText
|
||||
local str = "some text"
|
||||
local options = {
|
||||
width = 20,
|
||||
spacer = "=",
|
||||
cap = "[",
|
||||
inside = true,
|
||||
mirror = true,
|
||||
capColor = "#a020f0",
|
||||
spacerColor = "#00ff00",
|
||||
textColor = "#ff0000",
|
||||
}
|
||||
it("Should handle hecho colored text", function()
|
||||
local expectedStripped = "[=== some text ====]"
|
||||
local expected = "#a020f0[#r#00ff00===#r#ff0000 some text #r#00ff00====#r#a020f0]#r"
|
||||
local actual = hfText(str, options)
|
||||
local actualStripped = hecho2string(actual)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(expectedStripped, actualStripped)
|
||||
assert.equals(20, actualStripped:len())
|
||||
expectedStripped = "===[ some text ]===="
|
||||
expected = "#00ff00===#r#a020f0[#r#ff0000 some text #r#a020f0]#r#00ff00====#r"
|
||||
options.inside = false
|
||||
actual = hfText(str, options)
|
||||
actualStripped = hecho2string(actual)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(expectedStripped, actualStripped)
|
||||
assert.equals(20, actualStripped:len())
|
||||
end)
|
||||
|
||||
it("Should wrap hecho lines to the correct length", function()
|
||||
local str = "This is a test of the emergency broadcast system. This is only a test"
|
||||
local options = {width = 10, alignment = "centered"}
|
||||
local actual = hfText(str, options)
|
||||
for _, line in ipairs(actual:split("\n")) do
|
||||
assert.equals(hecho2string(line):len(), 10)
|
||||
end
|
||||
options.width = 15
|
||||
actual = hfText(str, options)
|
||||
for _, line in ipairs(actual:split("\n")) do
|
||||
assert.equals(hecho2string(line):len(), 15)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("ftext.TextFormatter", function()
|
||||
local tf = ftext.TextFormatter
|
||||
local str = "some text"
|
||||
local formatter
|
||||
|
||||
before_each(function()
|
||||
formatter = tf:new({width = 20})
|
||||
end)
|
||||
|
||||
it("Should let you change width using :setWidth", function()
|
||||
formatter:setWidth(80)
|
||||
local expected =
|
||||
"<white><reset><white> <reset><white> some text <reset><white> <reset><white><reset>"
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(80, cecho2string(actual):len())
|
||||
end)
|
||||
|
||||
it("Should format for cecho by default", function()
|
||||
local expected = "<white><reset><white> <reset><white> some text <reset><white> <reset><white><reset>"
|
||||
local expectedStripped = " some text "
|
||||
local actual = formatter:format(str)
|
||||
local actualStripped = cecho2string(actual)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(expectedStripped, actualStripped)
|
||||
assert.equals(20, actualStripped:len())
|
||||
end)
|
||||
|
||||
it("Should produce the same line as cfText given the same options", function()
|
||||
local expected = ftext.cfText(str, formatter.options)
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("Should let you change type using :setType", function()
|
||||
formatter:setType("h")
|
||||
local expected = ftext.hfText(str, formatter.options)
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
formatter:setType("d")
|
||||
expected = ftext.dfText(str, formatter.options)
|
||||
actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
formatter:setType("")
|
||||
expected = ftext.fText(str, formatter.options)
|
||||
actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("Should default to word wrapping, and let you change it with :setWrap", function()
|
||||
formatter:setWidth(10)
|
||||
local expected =
|
||||
"<white><reset><white> <reset><white> some <reset><white> <reset><white><reset>\n<white><reset><white> <reset><white> text <reset><white> <reset><white><reset>"
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
expected = "<white><reset><white><reset><white> some text <reset><white><reset><white><reset>"
|
||||
formatter:setWrap(false)
|
||||
actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("Should allow you to change the cap using :setCap", function()
|
||||
formatter:setCap('|')
|
||||
local expected = "<white>|<reset><white> <reset><white> some text <reset><white> <reset><white>|<reset>"
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("Should allow you to change the capColor using :setCapColor", function()
|
||||
formatter:setCapColor('<red>')
|
||||
local expected = "<red><reset><white> <reset><white> some text <reset><white> <reset><red><reset>"
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("Should allow you to change the spacer color using :setSpacerColor", function()
|
||||
formatter:setSpacerColor("<red>")
|
||||
local expected = "<white><reset><red> <reset><white> some text <reset><red> <reset><white><reset>"
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("Should allow you to change the text color using :setTextColor", function()
|
||||
formatter:setTextColor("<red>")
|
||||
local expected = "<white><reset><white> <reset><red> some text <reset><white> <reset><white><reset>"
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("Should allow you to change the spacer using :setSpacer", function()
|
||||
formatter:setSpacer("=")
|
||||
-- local expected = "<white><reset><white> <reset><white> some text <reset><white> <reset><white><reset>"
|
||||
local expected = "<white><reset><white>====<reset><white> some text <reset><white>=====<reset><white><reset>"
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("Should allow you to set the alignment using :setAlignment", function()
|
||||
formatter:setAlignment("left")
|
||||
local expected = "<white><reset><white><reset><white>some text <reset><white> <reset><white><reset>"
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
formatter:setAlignment("right")
|
||||
expected = "<white><reset><white> <reset><white> some text<reset><white><reset><white><reset>"
|
||||
actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("Should allow you to change the 'inside' option using :setInside", function()
|
||||
formatter:setInside(false)
|
||||
local expected = "<white> <reset><white><reset><white> some text <reset><white><reset><white> <reset>"
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("Should allow you to change the mirror option using :setMirror", function()
|
||||
formatter:setCap('<')
|
||||
formatter:setMirror(true)
|
||||
local expected = "<white><<reset><white> <reset><white> some text <reset><white> <reset><white>><reset>"
|
||||
local actual = formatter:format(str)
|
||||
assert.equal(expected, actual)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("ftext.TableMaker", function()
|
||||
local TableMaker = ftext.TableMaker
|
||||
local tm
|
||||
before_each(function()
|
||||
tm = TableMaker:new()
|
||||
tm:addColumn({name = "col1", width = 15, textColor = "<red>"})
|
||||
tm:addColumn({name = "col2", width = 15, textColor = "<blue>"})
|
||||
tm:addColumn({name = "col3", width = 15, textColor = "<green>"})
|
||||
tm:addRow({"some text", "more text", "other text"})
|
||||
tm:addRow({"little text", "bigger text", "text"})
|
||||
end)
|
||||
|
||||
it("Should assemble a formatted table given default options", function()
|
||||
local expected = [[<white>*************************************************<reset>
|
||||
<white>*<reset><white><reset><white> <reset><red> col1 <reset><white> <reset><white><reset><white>|<reset><white><reset><white> <reset><blue> col2 <reset><white> <reset><white><reset><white>|<reset><white><reset><white> <reset><green> col3 <reset><white> <reset><white><reset><white>*<reset>
|
||||
<white>*<reset><white>---------------<reset><white>|<reset><white>---------------<reset><white>|<reset><white>---------------<reset><white>*<reset>
|
||||
<white>*<reset><white><reset><white> <reset><red> some text <reset><white> <reset><white><reset><white>|<reset><white><reset><white> <reset><blue> more text <reset><white> <reset><white><reset><white>|<reset><white><reset><white> <reset><green> other text <reset><white> <reset><white><reset><white>*<reset>
|
||||
<white>*<reset><white>---------------<reset><white>|<reset><white>---------------<reset><white>|<reset><white>---------------<reset><white>*<reset>
|
||||
<white>*<reset><white><reset><white> <reset><red> little text <reset><white> <reset><white><reset><white>|<reset><white><reset><white> <reset><blue> bigger text <reset><white> <reset><white><reset><white>|<reset><white><reset><white> <reset><green> text <reset><white> <reset><white><reset><white>*<reset>
|
||||
<white>*************************************************<reset>
|
||||
]]
|
||||
local actual = tm:assemble()
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("TableMaker:getCell should return the text and formatter for a specific cell", function()
|
||||
local expectedText = "more text"
|
||||
local expectedFormatter = tm.columns[2]
|
||||
local actualText, actualFormatter = tm:getCell(1, 2)
|
||||
assert.equals(expectedText, actualText)
|
||||
assert.equals(expectedFormatter, actualFormatter)
|
||||
local expectedFormatted = "<white><reset><white> <reset><blue> more text <reset><white> <reset><white><reset>"
|
||||
local actualFormatted = actualFormatter:format(actualText)
|
||||
assert.equals(expectedFormatted, actualFormatted)
|
||||
end)
|
||||
end)
|
||||
end)
|
1
src/resources/MDK/mdkversion.txt
Normal file
1
src/resources/MDK/mdkversion.txt
Normal file
@@ -0,0 +1 @@
|
||||
2.10.0
|
Reference in New Issue
Block a user