Skip to content

Commit

Permalink
test(init.lua): test override functions completely
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazerbeak12345 committed Apr 5, 2024
1 parent 784fbb1 commit f8607e3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
12 changes: 10 additions & 2 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ print[[
-- See README.md for art credit

local minetest = minetest
do
sway = {}

-- This is defined as a function so I can unit-test it. Not intended for consumption. This function's specifications are
-- subject to change without notice. Please talk to your Doctor to see if sway is right for you. Known to cause cancer
-- and reproductive harm in the state of California. May explode if improperly recharged. Please stop using this
-- function if you feel like your code is bloated, if it feels sluggish, or generally behaves like systemd. Please do
-- not the cat. See CODE_LICENSE.txt and MEDIA_LICENSE.txt for information about copyright holders (when not expressly
-- mentioned near a relevant section of the code), warranty, and any terms and conditions that may or may not apply.
sway.__conqueror = function ()
-- Before we do anything, disable sfinv, unified_inventory, and i3. (code from i3 at commit bd5ea4e6). Also under MIT,
-- under Jean-Patrick-Guerrero and contributors. Modified to fit my style guidelines, and to also disable i3
if minetest.global_exists("sfinv") then
Expand All @@ -28,8 +36,8 @@ do
function i3.set_fs() end
end
end
sway.__conqueror()

local modpath = minetest.get_modpath("sway")
sway = {}
dofile(modpath .. "/api.lua")
dofile(modpath .. "/crafting.lua")
47 changes: 46 additions & 1 deletion spec/sway_inv_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ local minetest = {
register_chatcommand = nilfn,
get_translator = ident(ident),
is_singleplayer = ident(true),
global_exists = ident(false),
global_exists = function (name)
return _G[name] ~= nil
end,
log = nilfn,
_register_on_leaveplayer_calls = {},
register_on_leaveplayer = function (...)
Expand Down Expand Up @@ -851,6 +853,49 @@ describe("Lower-Layer Integration", function ()
assert.equal(ip_calls[1][1], form)
end)
end)
-- The first horseman of bloated inventory mods, the component that forces you to use it, even when others are present.
describe("__conqueror", function ()
-- It is recognised by several features:
-- It disables the one good inventory mod, whos only weakness is an affixment to the past,
-- leaving it featureless and permanantly obsolete
it("slays the simple one", function ()
_G.sfinv = {}
sway.__conqueror();
assert.equal(type(_G.sfinv.set_player_inventory_formspec), "function")
assert.same(
_G.sfinv.enabled,
false,
"Note how sfinv has already accepted its sad fate,"..
" the Internet Explorer of inventory mods,"..
" forever relegated to its solitary station as the doormat.\n" ..
"No other mod is so self-aware of its flaws than the soldier you witness here." ..
" Unlike his foes, he listens the first time when you say, 'please move,' and dutifully does so." ..
" He knows his sad fate. He will become disabled in the line of duty. That he still serves is honor."
)
end)
-- It disables the one mod everyone seems to enjoy, genuinely adding features people take for granted, but also is
-- known to be brittle
it("causes the slow and ugly one to stumble", function ()
_G.unified_inventory = {}
sway.__conqueror();
assert.equal(type(_G.unified_inventory.set_inventory_formspec), "function")
end)
-- And last, it disables the very mod that was so poorly (over)engineered, it inspired sway, a post-ironic parody of
-- all Minetest inventory mods, mostly just ones that try to recreate the average post-millenium RPG inventory
-- "experience." If I wanted to play Xenoblade Cronicles X, I would have purchased a Nintendo account by now.
it("encumberes the vain one", function ()
_G.i3 = {}
sway.__conqueror();
assert.equal(type(_G.i3.set_fs), "function")
end)
-- Perhaps it should be mentioned. There's several I haven't disabled. This is for two reasons.
--
-- 1. The mod is better than this mod.
-- 2. The mod is under a licence that would prevent me from doing so (legally).
-- 3. The mod is so unused, it's not worth the effort.
--
-- One of these reasons is a lie, and the other two tell only the truth. I refuse to clarify.
end)
end)
describe("content functions", function ()
it("insert_prepend", function ()
Expand Down

0 comments on commit f8607e3

Please sign in to comment.