Skip to content

Commit e544ba7

Browse files
committed
UnitTestSuite: use more descriptive and generic parameter names in some places
1 parent fe8c581 commit e544ba7

1 file changed

Lines changed: 27 additions & 25 deletions

File tree

modules/DependencyControl/UnitTestSuite.moon

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
Logger = require "l0.DependencyControl.Logger"
23
re = require "aegisub.re"
34
-- make sure tests can be loaded from the test directory
@@ -207,29 +208,30 @@ class UnitTest
207208
-- @tparam[opt=false] bool ignoreExtraAItems Enable this option to make the comparison one-sided,
208209
-- ignoring additional items present in a but not in b.
209210
-- @tparam[opt=false] bool requireIdenticalItems Enable this option if you require table items to be identical,
210-
--
211-
itemsEqual: (actual, expected, onlyNumKeys = true, allowAdditionalItems, requireIdenticalItems) ->
212-
seen, actualTables, seenCnt, actualTablesCnt, expectedCnt = {}, {}, 0, 0, 0
213-
214-
findEqualTable = (expectedTbl) ->
215-
for i, actualTbl in ipairs actualTables
216-
if UnitTest.equals tbl, v
217-
table.remove actualTables, i
218-
seen[tbl] = nil
211+
-- i.e. compared by reference, rather than by equality.
212+
itemsEqual: (a, b, onlyNumKeys = true, ignoreExtraAItems, requireIdenticalItems) ->
213+
seen, aTbls = {}, {}
214+
aCnt, aTblCnt, bCnt = 0, 0, 0
215+
216+
findEqualTable = (bTbl) ->
217+
for i, aTbl in ipairs aTbls
218+
if UnitTest.equals aTbl, bTbl
219+
table.remove aTbls, i
220+
seen[aTbl] = nil
219221
return true
220222
return false
221223

222224
if onlyNumKeys
223-
seenCnt, expectedCnt = #actual, #expected
224-
return false if not allowAdditionalItems and seenCnt != expectedCnt
225+
aCnt, bCnt = #a, #b
226+
return false if not ignoreExtraAItems and aCnt != bCnt
225227

226-
for v in *actual
228+
for v in *a
227229
seen[v] = true
228230
if "table" == type v
229-
actualTablesCnt += 1
230-
actualTables[actualTablesCnt] = v
231+
aTblCnt += 1
232+
aTbls[aTblCnt] = v
231233

232-
for v in *expected
234+
for v in *b
233235
-- identical values
234236
if seen[v]
235237
seen[v] = nil
@@ -241,15 +243,15 @@ class UnitTest
241243

242244

243245
else
244-
for _, v in pairs actual
245-
seenCnt += 1
246-
seen[b] = true
246+
for _, v in pairs a
247+
aCnt += 1
248+
seen[v] = true
247249
if "table" == type v
248-
actualTablesCnt += 1
249-
actualTables[actualTablesCnt] = v
250+
aTblCnt += 1
251+
aTbls[aTblCnt] = v
250252

251-
for _, v in pairs expected
252-
expectedCnt += 1
253+
for _, v in pairs b
254+
bCnt += 1
253255
-- identical values
254256
if seen[v]
255257
seen[v] = nil
@@ -259,7 +261,7 @@ class UnitTest
259261
if type(v) != "table" or requireIdenticalItems or not findEqualTable v
260262
return false
261263

262-
return false if not allowAdditionalItems and seenCnt != expectedCnt
264+
return false if not ignoreExtraAItems and aCnt != bCnt
263265

264266
return true
265267

@@ -268,10 +270,10 @@ class UnitTest
268270
-- @param condition passing in a falsy value causes the assertion to fail
269271
-- @tparam string message error message (may contain format string templates)
270272
-- @param[opt] args any arguments required for formatting the message
271-
assert: (cond, ...) =>
273+
assert: (condition, ...) =>
272274
args = table.pack ...
273275
msg = table.remove args, 1
274-
unless cond
276+
unless condition
275277
@assertFailed = true
276278
@logger\logEx 1, msg, nil, nil, 0, unpack args
277279

0 commit comments

Comments
 (0)