1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-10-25 10:57:57 +00:00

Some changes to Lua machines and string loading

- Share the ILuaContext across all method calls, as well as shifting it
   into an anonymous class.
 - Move the load/loadstring prefixing into bios.lua
 - Be less militant in prefixing chunk names:
   - load will no longer do any auto-prefixing.
   - loadstring will not prefix when there no chunk name is supplied.
     Before we would do `"=" .. supplied_program`, which made no sense.
This commit is contained in:
SquidDev
2019-03-10 12:24:55 +00:00
parent 7b5a918941
commit 5b942ff9c1
6 changed files with 216 additions and 202 deletions

View File

@@ -137,7 +137,7 @@ function expect_mt:type(exp_type)
return self
end
local function are_same(eq, left, right)
local function matches(eq, exact, left, right)
if left == right then return true end
local ty = type(left)
@@ -150,12 +150,14 @@ local function are_same(eq, left, right)
-- Verify all pairs in left are equal to those in right
for k, v in pairs(left) do
if not are_same(eq, v, right[k]) then return false end
if not matches(eq, exact, v, right[k]) then return false end
end
-- And verify all pairs in right are present in left
for k in pairs(right) do
if left[k] == nil then return false end
if exact then
-- And verify all pairs in right are present in left
for k in pairs(right) do
if left[k] == nil then return false end
end
end
return true
@@ -167,13 +169,26 @@ end
-- @param value The value to check for structural equivalence
-- @raises If they are not equivalent
function expect_mt:same(value)
if not are_same({}, self.value, value) then
if not matches({}, true, self.value, value) then
fail(("Expected %s\n but got %s"):format(format(value), format(self.value)))
end
return self
end
--- Assert that this expectation contains all fields mentioned
-- in the provided object.
--
-- @param value The value to check against
-- @raises If this does not match the provided value
function expect_mt:matches(value)
if not matches({}, false, value, self.value) then
fail(("Expected %s\nto match %s"):format(format(self.value), format(value)))
end
return self
end
--- Construct a new expectation from the provided value
--
-- @param value The value to apply assertions to