Use tab indenting consistently

Change-Id: I7387882d8ece9bb7f2eac8891c010a2fcb0a57b0
This commit is contained in:
Reedy 2020-10-23 16:39:12 +01:00
parent 6a999fb6aa
commit 664c866980
13 changed files with 1494 additions and 1494 deletions

View file

@ -220,177 +220,177 @@ end
return testframework.getTestProvider( {
{ name = 'clone', func = test.clone1,
expect = { true },
expect = { true },
},
{ name = 'clone table', func = test.clone2,
expect = { true },
expect = { true },
},
{ name = 'clone table then modify', func = test.clone2b,
expect = { false, { 2 }, nil, 'b' },
expect = { false, { 2 }, nil, 'b' },
},
{ name = 'clone table with metatable', func = test.clone3,
expect = { true },
expect = { true },
},
{ name = 'clone recursive table', func = test.clone4,
expect = { true },
expect = { true },
},
{ name = 'setfenv global', func = test.setfenv1,
expect = "'setfenv' cannot set the global environment, it is protected",
expect = "'setfenv' cannot set the global environment, it is protected",
},
{ name = 'setfenv invalid level', func = test.setfenv2,
expect = "'setfenv' cannot set an environment at a level greater than 10",
expect = "'setfenv' cannot set an environment at a level greater than 10",
},
{ name = 'setfenv invalid environment', func = test.setfenv3,
expect = "'setfenv' cannot set the requested environment, it is protected",
expect = "'setfenv' cannot set the requested environment, it is protected",
},
{ name = 'setfenv on unprotected past protected', func = test.setfenv4,
expect = { 'ok' },
expect = { 'ok' },
},
{ name = 'setfenv from inside protected', func = test.setfenv5,
expect = { 'ok' },
expect = { 'ok' },
},
{ name = 'setfenv protected function', func = test.setfenv6,
expect = "'setfenv' cannot be called on a protected function",
expect = "'setfenv' cannot be called on a protected function",
},
{ name = 'setfenv on a non-function', func = test.setfenv7,
expect = "'setfenv' can only be called with a function or integer as the first argument",
expect = "'setfenv' can only be called with a function or integer as the first argument",
},
{ name = 'getfenv(1)', func = test.getfenv1,
expect = { 'ok' },
expect = { 'ok' },
},
{ name = 'getfenv(0)', func = test.getfenv2,
expect = "'getfenv' cannot get the global environment",
expect = "'getfenv' cannot get the global environment",
},
{ name = 'getfenv with tail call', func = test.getfenv3,
expect = "no function environment for tail call",
expect = "no function environment for tail call",
},
{ name = 'Not quite too many expensive function calls',
func = test.executeExpensiveCalls, args = { 10 },
expect = { 'Did not error out' }
func = test.executeExpensiveCalls, args = { 10 },
expect = { 'Did not error out' }
},
{ name = 'Too many expensive function calls',
func = test.executeExpensiveCalls, args = { 11 },
expect = 'too many expensive function calls'
func = test.executeExpensiveCalls, args = { 11 },
expect = 'too many expensive function calls'
},
{ name = 'string metatable is hidden', func = test.stringMetatableHidden1,
expect = { nil }
expect = { nil }
},
{ name = 'string is not string metatable', func = test.stringMetatableHidden2,
expect = { nil }
expect = { nil }
},
{ name = 'pairs with __pairs',
func = pairs, args = { pairs_test_table },
expect = { 1, 2, 3 },
func = pairs, args = { pairs_test_table },
expect = { 1, 2, 3 },
},
{ name = 'ipairs with __ipairs',
func = ipairs, args = { pairs_test_table },
expect = { 4, 5, 6 },
func = ipairs, args = { pairs_test_table },
expect = { 4, 5, 6 },
},
{ name = 'package.loaded does not leak references to out-of-environment objects',
func = test.noLeaksViaPackageLoaded,
expect = { 'ok' },
func = test.noLeaksViaPackageLoaded,
expect = { 'ok' },
},
{ name = 'mw.loadData, returning non-table',
func = mw.loadData, args = { 'Module:CommonTests-data-fail1' },
expect = "Module:CommonTests-data-fail1 returned string, table expected",
func = mw.loadData, args = { 'Module:CommonTests-data-fail1' },
expect = "Module:CommonTests-data-fail1 returned string, table expected",
},
{ name = 'mw.loadData, containing function',
func = mw.loadData, args = { 'Module:CommonTests-data-fail2' },
expect = "data for mw.loadData contains unsupported data type 'function'",
func = mw.loadData, args = { 'Module:CommonTests-data-fail2' },
expect = "data for mw.loadData contains unsupported data type 'function'",
},
{ name = 'mw.loadData, containing table-with-metatable',
func = mw.loadData, args = { 'Module:CommonTests-data-fail3' },
expect = "data for mw.loadData contains a table with a metatable",
func = mw.loadData, args = { 'Module:CommonTests-data-fail3' },
expect = "data for mw.loadData contains a table with a metatable",
},
{ name = 'mw.loadData, containing function as key',
func = mw.loadData, args = { 'Module:CommonTests-data-fail4' },
expect = "data for mw.loadData contains unsupported data type 'function'",
func = mw.loadData, args = { 'Module:CommonTests-data-fail4' },
expect = "data for mw.loadData contains unsupported data type 'function'",
},
{ name = 'mw.loadData, containing table-with-metatable as key',
func = mw.loadData, args = { 'Module:CommonTests-data-fail5' },
expect = "data for mw.loadData contains a table as a key",
func = mw.loadData, args = { 'Module:CommonTests-data-fail5' },
expect = "data for mw.loadData contains a table as a key",
},
{ name = 'mw.loadData, getter (true)',
func = test.loadData.get, args = { 'true' },
expect = { true }
func = test.loadData.get, args = { 'true' },
expect = { true }
},
{ name = 'mw.loadData, getter (false)',
func = test.loadData.get, args = { 'false' },
expect = { false }
func = test.loadData.get, args = { 'false' },
expect = { false }
},
{ name = 'mw.loadData, getter (NaN)',
func = test.loadData.get, args = { 'NaN' },
expect = { 0/0 }
func = test.loadData.get, args = { 'NaN' },
expect = { 0/0 }
},
{ name = 'mw.loadData, getter (inf)',
func = test.loadData.get, args = { 'inf' },
expect = { 1/0 }
func = test.loadData.get, args = { 'inf' },
expect = { 1/0 }
},
{ name = 'mw.loadData, getter (num)',
func = test.loadData.get, args = { 'num' },
expect = { 12.5 }
func = test.loadData.get, args = { 'num' },
expect = { 12.5 }
},
{ name = 'mw.loadData, getter (str)',
func = test.loadData.get, args = { 'str' },
expect = { 'foo bar' }
func = test.loadData.get, args = { 'str' },
expect = { 'foo bar' }
},
{ name = 'mw.loadData, getter (table.2)',
func = test.loadData.get, args = { 'table', 2 },
expect = { 'two' }
func = test.loadData.get, args = { 'table', 2 },
expect = { 'two' }
},
{ name = 'mw.loadData, getter (t.t.t.t.str)',
func = test.loadData.get, args = { 't', 't', 't', 't', 'str' },
expect = { 'foo bar' }
func = test.loadData.get, args = { 't', 't', 't', 't', 'str' },
expect = { 'foo bar' }
},
{ name = 'mw.loadData, getter recursion',
func = test.loadData.recursion,
expect = { true, true, true },
func = test.loadData.recursion,
expect = { true, true, true },
},
{ name = 'mw.loadData, pairs',
func = test.loadData.iterate, args = { pairs },
expect = { { 'one', 'two', 'three', foo = 'bar' } },
func = test.loadData.iterate, args = { pairs },
expect = { { 'one', 'two', 'three', foo = 'bar' } },
},
{ name = 'mw.loadData, ipairs',
func = test.loadData.iterate, args = { ipairs },
expect = { { 'one', 'two', 'three' } },
func = test.loadData.iterate, args = { ipairs },
expect = { { 'one', 'two', 'three' } },
},
{ name = 'mw.loadData, setmetatable',
func = test.loadData.setmetatable,
expect = "cannot change a protected metatable"
func = test.loadData.setmetatable,
expect = "cannot change a protected metatable"
},
{ name = 'mw.loadData, setter (1)',
func = test.loadData.set, args = { 'ugh', 'str' },
expect = "table from mw.loadData is read-only",
func = test.loadData.set, args = { 'ugh', 'str' },
expect = "table from mw.loadData is read-only",
},
{ name = 'mw.loadData, setter (2)',
func = test.loadData.set, args = { 'ugh', 'table', 2 },
expect = "table from mw.loadData is read-only",
func = test.loadData.set, args = { 'ugh', 'table', 2 },
expect = "table from mw.loadData is read-only",
},
{ name = 'mw.loadData, setter (3)',
func = test.loadData.set, args = { 'ugh', 't' },
expect = "table from mw.loadData is read-only",
func = test.loadData.set, args = { 'ugh', 't' },
expect = "table from mw.loadData is read-only",
},
{ name = 'mw.loadData, rawset',
func = test.loadData.rawset,
expect = { 'ugh', 'foo bar', 'foo bar' },
func = test.loadData.rawset,
expect = { 'ugh', 'foo bar', 'foo bar' },
},
{ name = 'mw.addWarning',
func = mw.addWarning, args = { 'warn' },
expect = {},
func = mw.addWarning, args = { 'warn' },
expect = {},
},
{ name = 'mw.addWarning, bad type',
func = mw.addWarning, args = { true },
expect = "bad argument #1 to 'addWarning' (string expected)",
func = mw.addWarning, args = { true },
expect = "bad argument #1 to 'addWarning' (string expected)",
},
} )

View file

@ -26,27 +26,27 @@ end
-- Tests
local tests = {
{ name = 'mw.hash.listAlgorithms', func = testListAlgorithms,
expect = { true }
expect = { true }
},
{ name = 'mw.hash.hashValue sha1', func = mw.hash.hashValue,
args = { 'sha1', 'abc' },
expect = { 'a9993e364706816aba3e25717850c26c9cd0d89d' }
args = { 'sha1', 'abc' },
expect = { 'a9993e364706816aba3e25717850c26c9cd0d89d' }
},
{ name = 'mw.hash.hashValue md5', func = mw.hash.hashValue,
args = { 'md5', 'abc' },
expect = { '900150983cd24fb0d6963f7d28e17f72' }
args = { 'md5', 'abc' },
expect = { '900150983cd24fb0d6963f7d28e17f72' }
},
{ name = 'mw.hash.hashValue bad argument type #1', func = mw.hash.hashValue,
args = { nil, 'a-string' },
expect = "bad argument #1 to 'hashValue' (string expected, got nil)"
args = { nil, 'a-string' },
expect = "bad argument #1 to 'hashValue' (string expected, got nil)"
},
{ name = 'mw.hash.hashValue bad argument type #2', func = mw.hash.hashValue,
args = { 'abc', 2 },
expect = "bad argument #2 to 'hashValue' (string expected, got number)"
args = { 'abc', 2 },
expect = "bad argument #2 to 'hashValue' (string expected, got number)"
},
{ name = 'mw.hash.hashValue bad algorithm', func = mw.hash.hashValue,
args = { 'not-a-hashing-algorithm', 'abc' },
expect = "Unknown hashing algorithm: not-a-hashing-algorithm"
args = { 'not-a-hashing-algorithm', 'abc' },
expect = "Unknown hashing algorithm: not-a-hashing-algorithm"
}
}

View file

@ -114,245 +114,245 @@ end
local tests = {
-- Simple (inline) tests
{ name = 'mw.html.create', func = mw.html.create, type='ToString',
args = { 'table' },
expect = { '<table></table>' }
args = { 'table' },
expect = { '<table></table>' }
},
{ name = 'mw.html.create (self closing)', func = mw.html.create, type='ToString',
args = { 'br' },
expect = { '<br />' }
args = { 'br' },
expect = { '<br />' }
},
{ name = 'mw.html.create (self closing - forced)', func = mw.html.create, type='ToString',
args = { 'div', { selfClosing = true } },
expect = { '<div />' }
args = { 'div', { selfClosing = true } },
expect = { '<div />' }
},
{ name = 'mw.html.create (invalid tag 1)', func = mw.html.create, type='ToString',
args = { '$$$$' },
expect = "invalid tag name '$$$$'"
args = { '$$$$' },
expect = "invalid tag name '$$$$'"
},
{ name = 'mw.html.create (invalid tag 2)', func = mw.html.create, type='ToString',
args = { {} },
expect = "bad argument #1 to 'mw.html.create' (string expected, got table)"
args = { {} },
expect = "bad argument #1 to 'mw.html.create' (string expected, got table)"
},
{ name = 'mw.html.wikitext', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'wikitext', 'Plain text' },
expect = { '<div>Plain text</div>' }
args = { getEmptyTestDiv(), 'wikitext', 'Plain text' },
expect = { '<div>Plain text</div>' }
},
{ name = 'mw.html.wikitext (invalid input)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'wikitext', 'Plain text', {} },
expect = "bad argument #2 to 'wikitext' (string or number expected, got table)"
args = { getEmptyTestDiv(), 'wikitext', 'Plain text', {} },
expect = "bad argument #2 to 'wikitext' (string or number expected, got table)"
},
{ name = 'mw.html.newline', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'newline' },
expect = { '<div>\n</div>' }
args = { getEmptyTestDiv(), 'newline' },
expect = { '<div>\n</div>' }
},
{ name = 'mw.html.tag', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'tag', 'span' },
-- tag is only supposed to return the new (inner) node
expect = { '<span></span>' }
args = { getEmptyTestDiv(), 'tag', 'span' },
-- tag is only supposed to return the new (inner) node
expect = { '<span></span>' }
},
{ name = 'mw.html.attr', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'attr', 'foo', 'bar' },
expect = { '<div foo="bar"></div>' }
args = { getEmptyTestDiv(), 'attr', 'foo', 'bar' },
expect = { '<div foo="bar"></div>' }
},
{ name = 'mw.html.attr (nil noop)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'attr', 'foo', nil },
expect = { '<div></div>' }
args = { getEmptyTestDiv(), 'attr', 'foo', nil },
expect = { '<div></div>' }
},
{ name = 'mw.html.attr (table 1)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'attr', { foo = 'bar' } },
expect = { '<div foo="bar"></div>' }
args = { getEmptyTestDiv(), 'attr', { foo = 'bar' } },
expect = { '<div foo="bar"></div>' }
},
{ name = 'mw.html.attr (table 2)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'attr', testAttrs },
expect = { '<div ab="cd" foo="bar"></div>' }
args = { getEmptyTestDiv(), 'attr', testAttrs },
expect = { '<div ab="cd" foo="bar"></div>' }
},
{ name = 'mw.html.attr (invalid name 1)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'attr', 123, 'bar' },
expect = "bad argument #1 to 'attr' (string expected, got number)"
args = { getEmptyTestDiv(), 'attr', 123, 'bar' },
expect = "bad argument #1 to 'attr' (string expected, got number)"
},
{ name = 'mw.html.attr (invalid name 2)', func = testHelper,
args = { getEmptyTestDiv(), 'attr', '§§§§', 'foo' },
expect = "bad argument #1 to 'attr' (invalid attribute name '§§§§')"
args = { getEmptyTestDiv(), 'attr', '§§§§', 'foo' },
expect = "bad argument #1 to 'attr' (invalid attribute name '§§§§')"
},
{ name = 'mw.html.attr (table no value)', func = testHelper,
args = { getEmptyTestDiv(), 'attr', { foo = 'bar' }, 'foo' },
expect = "bad argument #2 to 'attr' (if argument #1 is a table, argument #2 must be left empty)"
args = { getEmptyTestDiv(), 'attr', { foo = 'bar' }, 'foo' },
expect = "bad argument #2 to 'attr' (if argument #1 is a table, argument #2 must be left empty)"
},
{ name = 'mw.html.attr (invalid value)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'attr', 'foo', true },
expect = "bad argument #2 to 'attr' (string, number or nil expected, got boolean)"
args = { getEmptyTestDiv(), 'attr', 'foo', true },
expect = "bad argument #2 to 'attr' (string, number or nil expected, got boolean)"
},
{ name = 'mw.html.attr (invalid table 1)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'attr', { foo = {} } },
expect = "bad argument #1 to 'attr' " ..
'(table keys must be strings, and values must be strings or numbers)'
args = { getEmptyTestDiv(), 'attr', { foo = {} } },
expect = "bad argument #1 to 'attr' " ..
'(table keys must be strings, and values must be strings or numbers)'
},
{ name = 'mw.html.attr (invalid table 2)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'attr', { 1, 2 ,3 } },
expect = "bad argument #1 to 'attr' " ..
'(table keys must be strings, and values must be strings or numbers)'
args = { getEmptyTestDiv(), 'attr', { 1, 2 ,3 } },
expect = "bad argument #1 to 'attr' " ..
'(table keys must be strings, and values must be strings or numbers)'
},
{ name = 'mw.html.attr (invalid table 3)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'attr', { foo = 'bar', blah = true } },
expect = "bad argument #1 to 'attr' " ..
'(table keys must be strings, and values must be strings or numbers)'
args = { getEmptyTestDiv(), 'attr', { foo = 'bar', blah = true } },
expect = "bad argument #1 to 'attr' " ..
'(table keys must be strings, and values must be strings or numbers)'
},
{ name = 'mw.html.attr (invalid table 4)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'attr', { [{}] = 'foo' } },
expect = "bad argument #1 to 'attr' " ..
'(table keys must be strings, and values must be strings or numbers)'
args = { getEmptyTestDiv(), 'attr', { [{}] = 'foo' } },
expect = "bad argument #1 to 'attr' " ..
'(table keys must be strings, and values must be strings or numbers)'
},
{ name = 'mw.html.getAttr (nil)', func = testHelper,
args = { getEmptyTestDiv(), 'getAttr', 'foo' },
expect = { nil }
args = { getEmptyTestDiv(), 'getAttr', 'foo' },
expect = { nil }
},
{ name = 'mw.html.getAttr (invalid name)', func = testHelper,
args = { getEmptyTestDiv(), 'getAttr', 123 },
expect = "bad argument #1 to 'getAttr' (string expected, got number)"
args = { getEmptyTestDiv(), 'getAttr', 123 },
expect = "bad argument #1 to 'getAttr' (string expected, got number)"
},
{ name = 'mw.html.addClass', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'addClass', 'foo' },
expect = { '<div class="foo"></div>' }
args = { getEmptyTestDiv(), 'addClass', 'foo' },
expect = { '<div class="foo"></div>' }
},
{ name = 'mw.html.addClass (numeric argument)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'addClass', 123 },
expect = { '<div class="123"></div>' }
args = { getEmptyTestDiv(), 'addClass', 123 },
expect = { '<div class="123"></div>' }
},
{ name = 'mw.html.addClass (invalid value)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'addClass', {} },
expect = "bad argument #1 to 'addClass' (string, number or nil expected, got table)"
args = { getEmptyTestDiv(), 'addClass', {} },
expect = "bad argument #1 to 'addClass' (string, number or nil expected, got table)"
},
{ name = 'mw.html.css', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'css', 'foo', 'bar' },
expect = { '<div style="foo:bar"></div>' }
args = { getEmptyTestDiv(), 'css', 'foo', 'bar' },
expect = { '<div style="foo:bar"></div>' }
},
{ name = 'mw.html.css (numeric arguments)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'css', 123, 456 },
expect = { '<div style="123:456"></div>' }
args = { getEmptyTestDiv(), 'css', 123, 456 },
expect = { '<div style="123:456"></div>' }
},
{ name = 'mw.html.css (nil noop)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'css', 'foo', nil },
expect = { '<div></div>' }
args = { getEmptyTestDiv(), 'css', 'foo', nil },
expect = { '<div></div>' }
},
{ name = 'mw.html.css (invalid name 1)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'css', function() end, 'bar' },
expect = "bad argument #1 to 'css' (string or number expected, got function)"
args = { getEmptyTestDiv(), 'css', function() end, 'bar' },
expect = "bad argument #1 to 'css' (string or number expected, got function)"
},
{ name = 'mw.html.css (table no value)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'css', {}, 'bar' },
expect = "bad argument #2 to 'css' (if argument #1 is a table, argument #2 must be left empty)"
args = { getEmptyTestDiv(), 'css', {}, 'bar' },
expect = "bad argument #2 to 'css' (if argument #1 is a table, argument #2 must be left empty)"
},
{ name = 'mw.html.css (invalid value)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'css', 'foo', {} },
expect = "bad argument #2 to 'css' (string, number or nil expected, got table)"
args = { getEmptyTestDiv(), 'css', 'foo', {} },
expect = "bad argument #2 to 'css' (string, number or nil expected, got table)"
},
{ name = 'mw.html.css (table)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'css', testAttrs },
expect = { '<div style="ab:cd;foo:bar"></div>' }
args = { getEmptyTestDiv(), 'css', testAttrs },
expect = { '<div style="ab:cd;foo:bar"></div>' }
},
{ name = 'mw.html.css (invalid table)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'css', { foo = 'bar', ab = true } },
expect = "bad argument #1 to 'css' " ..
'(table keys and values must be strings or numbers)'
args = { getEmptyTestDiv(), 'css', { foo = 'bar', ab = true } },
expect = "bad argument #1 to 'css' " ..
'(table keys and values must be strings or numbers)'
},
{ name = 'mw.html.cssText', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'cssText', 'Unit tests, ftw' },
expect = { '<div style="Unit tests, ftw"></div>' }
args = { getEmptyTestDiv(), 'cssText', 'Unit tests, ftw' },
expect = { '<div style="Unit tests, ftw"></div>' }
},
{ name = 'mw.html.cssText (numeric argument)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'cssText', 123 },
expect = { '<div style="123"></div>' }
args = { getEmptyTestDiv(), 'cssText', 123 },
expect = { '<div style="123"></div>' }
},
{ name = 'mw.html.cssText (invalid value)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'cssText', {} },
expect = "bad argument #1 to 'cssText' (string, number or nil expected, got table)"
args = { getEmptyTestDiv(), 'cssText', {} },
expect = "bad argument #1 to 'cssText' (string, number or nil expected, got table)"
},
{ name = 'mw.html attribute escaping (value with double quotes)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'attr', 'foo', 'ble"rgh' },
expect = { '<div foo="ble&quot;rgh"></div>' }
args = { getEmptyTestDiv(), 'attr', 'foo', 'ble"rgh' },
expect = { '<div foo="ble&quot;rgh"></div>' }
},
{ name = 'mw.html attribute escaping 1', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'attr', 'foo', 'ble<rgh' },
expect = { '<div foo="ble&lt;rgh"></div>' }
args = { getEmptyTestDiv(), 'attr', 'foo', 'ble<rgh' },
expect = { '<div foo="ble&lt;rgh"></div>' }
},
{ name = 'mw.html attribute escaping 2', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'attr', 'foo', '<ble"&rgh>' },
expect = { '<div foo="&lt;ble&quot;&amp;rgh&gt;"></div>' }
args = { getEmptyTestDiv(), 'attr', 'foo', '<ble"&rgh>' },
expect = { '<div foo="&lt;ble&quot;&amp;rgh&gt;"></div>' }
},
{ name = 'mw.html attribute escaping (CSS)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'css', 'mu"ha', 'ha"ha' },
expect = { '<div style="mu&quot;ha:ha&quot;ha"></div>' }
args = { getEmptyTestDiv(), 'css', 'mu"ha', 'ha"ha' },
expect = { '<div style="mu&quot;ha:ha&quot;ha"></div>' }
},
{ name = 'mw.html attribute escaping (CSS raw)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'cssText', 'mu"ha:-ha"ha' },
expect = { '<div style="mu&quot;ha:-ha&quot;ha"></div>' }
args = { getEmptyTestDiv(), 'cssText', 'mu"ha:-ha"ha' },
expect = { '<div style="mu&quot;ha:-ha&quot;ha"></div>' }
},
{ name = 'mw.html.addClass (nil)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'addClass' },
expect = { '<div></div>' }
args = { getEmptyTestDiv(), 'addClass' },
expect = { '<div></div>' }
},
{ name = 'mw.html.cssText (nil)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'cssText' },
expect = { '<div></div>' }
args = { getEmptyTestDiv(), 'cssText' },
expect = { '<div></div>' }
},
-- Tests defined above
{ name = 'mw.html.addClass (twice) ', func = testMultiAddClass, type='ToString',
expect = { '<div class="foo bar"></div>' }
expect = { '<div class="foo bar"></div>' }
},
{ name = 'mw.html.css.cssText.css', func = testCssAndCssText, type='ToString',
expect = { '<div style="foo:bar;abc:def;g:h"></div>' }
expect = { '<div style="foo:bar;abc:def;g:h"></div>' }
},
{ name = 'mw.html.tag (using done)', func = testTagDone, type='ToString',
expect = { '<div><span></span></div>' }
expect = { '<div><span></span></div>' }
},
{ name = 'mw.html.node (using done)', func = testNodeDone, type='ToString',
expect = { '<div><div></div></div>' }
expect = { '<div><div></div></div>' }
},
{ name = 'mw.html.node (self closing, using done)', func = testNodeSelfClosingDone, type='ToString',
expect = { '<div><br /></div>' }
expect = { '<div><br /></div>' }
},
{ name = 'mw.html.node (append to self closing)', func = testNodeAppendToSelfClosing, type='ToString',
expect = "self-closing tags can't have child nodes"
expect = "self-closing tags can't have child nodes"
},
{ name = 'mw.html.wikitext (append to self closing)', func = testWikitextAppendToSelfClosing, type='ToString',
expect = "self-closing tags can't have child nodes"
expect = "self-closing tags can't have child nodes"
},
{ name = 'mw.html.tag.node (using allDone)', func = testTagNodeAllDone, type='ToString',
expect = { '<div><p><div></div></p></div>' }
expect = { '<div><p><div></div></p></div>' }
},
{ name = 'mw.html.attr (overrides)', func = testAttributeOverride, type='ToString',
expect = { '<div good="Wikibase"></div>' }
expect = { '<div good="Wikibase"></div>' }
},
{ name = 'mw.html.attr (removal)', func = testAttributeRemoval, type='ToString',
expect = { '<div></div>' }
expect = { '<div></div>' }
},
{ name = 'mw.html.getAttr', func = testGetAttribute, type='ToString',
expect = { 'Berlin' }
expect = { 'Berlin' }
},
{ name = 'mw.html.getAttr (escaping)', func = testGetAttributeEscaping, type='ToString',
expect = { '<ble"&rgh>' }
expect = { '<ble"&rgh>' }
},
{ name = 'mw.html.create (empty string)', func = testCreateWithValue, type='ToString',
args = {''},
expect = { 'foo<div a="b"></div>' }
args = {''},
expect = { 'foo<div a="b"></div>' }
},
{ name = 'mw.html.create (nil)', func = testCreateWithValue, type='ToString',
args = {nil},
expect = { 'foo<div a="b"></div>' }
args = {nil},
expect = { 'foo<div a="b"></div>' }
},
{ name = 'mw.html.css (removal)', func = testCssRemoval, type='ToString',
expect = { '<div></div>' }
expect = { '<div></div>' }
},
{ name = 'mw.html complex test', func = testComplex, type='ToString',
expect = {
expect = {
'<div class="firstClass" what="ever"><meh whynot="Русский"><hr a="b" /></meh>' ..
'<hr /><div abc="def" style="width:-1px"></div></div>'
}
}
},
{ name = 'mw.html strip marker test', func = testStripMarker, type='ToString',
expect = { 'ok' }
expect = { 'ok' }
},
}

View file

@ -92,344 +92,344 @@ end
return testframework.getTestProvider( {
{ name = 'fetchLanguageName (en)', func = mw.language.fetchLanguageName,
args = { 'en' },
expect = { 'English' }
args = { 'en' },
expect = { 'English' }
},
{ name = 'fetchLanguageName (ru)', func = mw.language.fetchLanguageName,
args = { 'ru' },
expect = { 'русский' }
args = { 'ru' },
expect = { 'русский' }
},
{ name = 'fetchLanguageName (en,ru)', func = mw.language.fetchLanguageName,
args = { 'en', 'ru' },
expect = { 'английский' }
args = { 'en', 'ru' },
expect = { 'английский' }
},
{ name = 'fetchLanguageName (ru,en)', func = mw.language.fetchLanguageName,
args = { 'ru', 'en' },
expect = { 'Russian' }
args = { 'ru', 'en' },
expect = { 'Russian' }
},
{ name = 'fetchLanguageName ([[bogus]])', func = mw.language.fetchLanguageName,
args = { '[[bogus]]' },
expect = { '' }
args = { '[[bogus]]' },
expect = { '' }
},
{ name = 'fetchLanguageName (en,[[bogus]])', func = mw.language.fetchLanguageName,
args = { 'en', '[[bogus]]' },
expect = { 'English' }
args = { 'en', '[[bogus]]' },
expect = { 'English' }
},
{ name = 'fetchLanguageNames ()', func = test_fetchLanguageNames,
args = {},
expect = { { en = 'English', ru = 'русский' } }
args = {},
expect = { { en = 'English', ru = 'русский' } }
},
{ name = 'fetchLanguageNames (de)', func = test_fetchLanguageNames,
args = { 'de' },
expect = { { en = 'Englisch', ru = 'Russisch' } }
args = { 'de' },
expect = { { en = 'Englisch', ru = 'Russisch' } }
},
{ name = 'fetchLanguageNames ([[bogus]])', func = test_fetchLanguageNames,
args = { '[[bogus]]' },
expect = { { en = 'English', ru = 'Russian' } }
args = { '[[bogus]]' },
expect = { { en = 'English', ru = 'Russian' } }
},
{ name = 'getFallbacksFor', func = test_multi,
args = { mw.language.getFallbacksFor, 'en', 'de', 'arz', '[[bogus]]' },
expect = { {}, { 'en' }, { 'ar', 'en' }, {} }
args = { mw.language.getFallbacksFor, 'en', 'de', 'arz', '[[bogus]]' },
expect = { {}, { 'en' }, { 'ar', 'en' }, {} }
},
{ name = 'isKnownLanguageTag', func = test_multi,
args = { mw.language.isKnownLanguageTag, 'en', 'not-a-real-code', 'extension code', '[[bogus]]' },
expect = { true, false, false, false }
args = { mw.language.isKnownLanguageTag, 'en', 'not-a-real-code', 'extension code', '[[bogus]]' },
expect = { true, false, false, false }
},
{ name = 'isSupportedLanguage', func = test_multi,
args = { mw.language.isSupportedLanguage, 'en', 'not-a-real-code', 'extension code', '[[bogus]]' },
expect = { true, false, false, false }
args = { mw.language.isSupportedLanguage, 'en', 'not-a-real-code', 'extension code', '[[bogus]]' },
expect = { true, false, false, false }
},
{ name = 'isValidBuiltInCode', func = test_multi,
args = { mw.language.isValidBuiltInCode, 'en', 'not-a-real-code', 'extension code', '[[bogus]]' },
expect = { true, true, false, false }
args = { mw.language.isValidBuiltInCode, 'en', 'not-a-real-code', 'extension code', '[[bogus]]' },
expect = { true, true, false, false }
},
{ name = 'isValidCode', func = test_multi,
args = { mw.language.isValidCode, 'en', 'not-a-real-code', 'extension code', '[[bogus]]' },
expect = { true, true, true, false }
args = { mw.language.isValidCode, 'en', 'not-a-real-code', 'extension code', '[[bogus]]' },
expect = { true, true, true, false }
},
{ name = 'mw.language.new', func = test_multi, type = 'ToString',
args = { mw.language.new, 'en', 'ru', '[[bogus]]' },
expect = { 'table', 'table', 'table' }
args = { mw.language.new, 'en', 'ru', '[[bogus]]' },
expect = { 'table', 'table', 'table' }
},
{ name = 'lang:getCode', func = test_method,
args = { 'getCode' },
expect = {
{ 'en' },
{ 'kaa' },
{ 'fa' },
{ '[[bogus]]' },
}
args = { 'getCode' },
expect = {
{ 'en' },
{ 'kaa' },
{ 'fa' },
{ '[[bogus]]' },
}
},
{ name = 'lang:getFallbackLanguages', func = test_method,
args = { 'getFallbackLanguages' },
expect = {
{ {} },
{ { 'kk-latn', 'kk-cyrl', 'en' } },
{ { 'en' } },
{ {} },
}
args = { 'getFallbackLanguages' },
expect = {
{ {} },
{ { 'kk-latn', 'kk-cyrl', 'en' } },
{ { 'en' } },
{ {} },
}
},
{ name = 'lang:isRTL', func = test_method,
args = { 'isRTL' },
expect = {
{ false },
{ false },
{ true },
"language code '[[bogus]]' is invalid",
}
args = { 'isRTL' },
expect = {
{ false },
{ false },
{ true },
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:lc', func = test_method,
args = { 'lc', 'IX' },
expect = {
{ 'ix' },
{ 'ix' }, -- Probably not actually right, but it's what LanguageKaa returns
{ 'ix' },
"language code '[[bogus]]' is invalid",
}
args = { 'lc', 'IX' },
expect = {
{ 'ix' },
{ 'ix' }, -- Probably not actually right, but it's what LanguageKaa returns
{ 'ix' },
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:lcfirst', func = test_method,
args = { 'lcfirst', 'IX' },
expect = {
{ 'iX' },
{ 'ıX' },
{ 'iX' },
"language code '[[bogus]]' is invalid",
}
args = { 'lcfirst', 'IX' },
expect = {
{ 'iX' },
{ 'ıX' },
{ 'iX' },
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:uc', func = test_method,
args = { 'uc', 'ix' },
expect = {
{ 'IX' },
{ 'IX' }, -- Probably not actually right, but it's what LanguageKaa returns
{ 'IX' },
"language code '[[bogus]]' is invalid",
}
args = { 'uc', 'ix' },
expect = {
{ 'IX' },
{ 'IX' }, -- Probably not actually right, but it's what LanguageKaa returns
{ 'IX' },
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:ucfirst', func = test_method,
args = { 'ucfirst', 'ix' },
expect = {
{ 'Ix' },
{ 'İx' },
{ 'Ix' },
"language code '[[bogus]]' is invalid",
}
args = { 'ucfirst', 'ix' },
expect = {
{ 'Ix' },
{ 'İx' },
{ 'Ix' },
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:caseFold', func = test_method,
args = { 'caseFold', 'ix' },
expect = {
{ 'IX' },
{ 'IX' }, -- Probably not actually right, but it's what LanguageKaa returns
{ 'IX' },
"language code '[[bogus]]' is invalid",
}
args = { 'caseFold', 'ix' },
expect = {
{ 'IX' },
{ 'IX' }, -- Probably not actually right, but it's what LanguageKaa returns
{ 'IX' },
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:formatNum', func = test_method,
args = { 'formatNum', 123456.78901 },
expect = {
{ '123,456.78901' },
{ "123\194\160456,78901" },
{ '۱۲۳٬۴۵۶٫۷۸۹۰۱' },
"language code '[[bogus]]' is invalid",
}
args = { 'formatNum', 123456.78901 },
expect = {
{ '123,456.78901' },
{ "123\194\160456,78901" },
{ '۱۲۳٬۴۵۶٫۷۸۹۰۱' },
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:formatDate', func = test_method,
args = { 'formatDate', 'Y-F-d H:i:s', '20140305123456' },
expect = {
{ '2014-March-05 12:34:56' },
{ '2014-Mart-05 12:34:56' },
{ '۲۰۱۴-مارس-۰۵ ۱۲:۳۴:۵۶' },
"language code '[[bogus]]' is invalid",
}
args = { 'formatDate', 'Y-F-d H:i:s', '20140305123456' },
expect = {
{ '2014-March-05 12:34:56' },
{ '2014-Mart-05 12:34:56' },
{ '۲۰۱۴-مارس-۰۵ ۱۲:۳۴:۵۶' },
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:formatDuration', func = test_method,
args = { 'formatDuration', 86461 },
expect = {
{ "1 day, 1 minute and 1 second" },
{ "1 күн, 1 минут ha&#039;m 1 секунд" },
{ "۱ روز، ۱ دقیقه و ۱ ثانیه" },
"language code '[[bogus]]' is invalid",
}
args = { 'formatDuration', 86461 },
expect = {
{ "1 day, 1 minute and 1 second" },
{ "1 күн, 1 минут ha&#039;m 1 секунд" },
{ "۱ روز، ۱ دقیقه و ۱ ثانیه" },
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:formatDuration (hours and minutes)', func = test_method,
args = { 'formatDuration', 86461, { 'hours', 'minutes' } },
expect = {
{ "24 hours and 1 minute" },
{ "24 сағат ha&#039;m 1 минут" },
{ "۲۴ ساعت و ۱ دقیقه" },
"language code '[[bogus]]' is invalid",
}
args = { 'formatDuration', 86461, { 'hours', 'minutes' } },
expect = {
{ "24 hours and 1 minute" },
{ "24 сағат ha&#039;m 1 минут" },
{ "۲۴ ساعت و ۱ دقیقه" },
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:parseFormattedNumber', func = test_parseFormattedNumber,
args = {},
expect = {
{ 123456.78901 },
{ 123456.78901 },
{ 123456.78901 },
"language code '[[bogus]]' is invalid",
}
args = {},
expect = {
{ 123456.78901 },
{ 123456.78901 },
{ 123456.78901 },
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:convertPlural (en)', func = test_plural,
args = { 'en' },
expect = { 'babbbbbbbbbbbbbbbbbbbbbbbbbbbb' }
args = { 'en' },
expect = { 'babbbbbbbbbbbbbbbbbbbbbbbbbbbb' }
},
{ name = 'lang:convertPlural (pl)', func = test_plural,
args = { 'pl' },
expect = { 'cabbbcccccccccccccccccbbbccccc' }
args = { 'pl' },
expect = { 'cabbbcccccccccccccccccbbbccccc' }
},
{ name = 'lang:convertPlural (bogus)', func = test_plural,
args = { '[[bogus]]' },
expect = "language code '[[bogus]]' is invalid",
args = { '[[bogus]]' },
expect = "language code '[[bogus]]' is invalid",
},
{ name = 'lang:convertGrammar (ru)', func = test_method_lang,
args = { 'ru', 'convertGrammar', '**ия', 'genitive' },
expect = { '**ии' }
args = { 'ru', 'convertGrammar', '**ия', 'genitive' },
expect = { '**ии' }
},
{ name = 'lang:convertGrammar (bogus)', func = test_method_lang,
args = { '[[bogus]]', 'convertGrammar', '**ия', 'genitive' },
expect = "language code '[[bogus]]' is invalid",
args = { '[[bogus]]', 'convertGrammar', '**ия', 'genitive' },
expect = "language code '[[bogus]]' is invalid",
},
{ name = 'lang:grammar (ru)', func = test_method_lang,
args = { 'ru', 'grammar', 'genitive', '**ия' },
expect = { '**ии' }
args = { 'ru', 'grammar', 'genitive', '**ия' },
expect = { '**ии' }
},
{ name = 'lang:grammar (bogus)', func = test_method_lang,
args = { '[[bogus]]', 'grammar', 'genitive', '**ия' },
expect = "language code '[[bogus]]' is invalid",
args = { '[[bogus]]', 'grammar', 'genitive', '**ия' },
expect = "language code '[[bogus]]' is invalid",
},
{ name = 'lang:gender (male)', func = test_method,
args = { 'gender', 'male', 'masculine', 'feminine', 'neutral' },
expect = {
{ 'masculine' },
{ 'masculine' },
{ 'masculine' },
"language code '[[bogus]]' is invalid",
}
args = { 'gender', 'male', 'masculine', 'feminine', 'neutral' },
expect = {
{ 'masculine' },
{ 'masculine' },
{ 'masculine' },
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:gender (female)', func = test_method,
args = { 'gender', 'female', 'masculine', 'feminine', 'neutral' },
expect = {
{ 'feminine' },
{ 'feminine' },
{ 'feminine' },
"language code '[[bogus]]' is invalid",
}
args = { 'gender', 'female', 'masculine', 'feminine', 'neutral' },
expect = {
{ 'feminine' },
{ 'feminine' },
{ 'feminine' },
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:gender (male, with sequence)', func = test_method,
args = { 'gender', 'male', { 'masculine', 'feminine', 'neutral' } },
expect = {
{ 'masculine' },
{ 'masculine' },
{ 'masculine' },
"language code '[[bogus]]' is invalid",
}
args = { 'gender', 'male', { 'masculine', 'feminine', 'neutral' } },
expect = {
{ 'masculine' },
{ 'masculine' },
{ 'masculine' },
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:getArrow (forward)', func = test_method,
args = { 'getArrow', 'forwards' },
expect = {
{ "" },
{ "" },
{ "" },
"language code '[[bogus]]' is invalid",
}
args = { 'getArrow', 'forwards' },
expect = {
{ "" },
{ "" },
{ "" },
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:getArrow (right)', func = test_method,
args = { 'getArrow', 'right' },
expect = {
{ "" },
{ "" },
{ "" },
{ "" },
}
args = { 'getArrow', 'right' },
expect = {
{ "" },
{ "" },
{ "" },
{ "" },
}
},
{ name = 'lang:getDir', func = test_method,
args = { 'getDir' },
expect = {
{ "ltr" },
{ "ltr" },
{ "rtl" },
"language code '[[bogus]]' is invalid",
}
args = { 'getDir' },
expect = {
{ "ltr" },
{ "ltr" },
{ "rtl" },
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:getDirMark', func = test_method,
args = { 'getDirMark' },
expect = {
{ "\226\128\142" },
{ "\226\128\142" },
{ "\226\128\143" },
"language code '[[bogus]]' is invalid",
}
args = { 'getDirMark' },
expect = {
{ "\226\128\142" },
{ "\226\128\142" },
{ "\226\128\143" },
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:getDirMark opposite', func = test_method,
args = { 'getDirMark', true },
expect = {
{ "\226\128\143" },
{ "\226\128\143" },
{ "\226\128\142" },
"language code '[[bogus]]' is invalid",
}
args = { 'getDirMark', true },
expect = {
{ "\226\128\143" },
{ "\226\128\143" },
{ "\226\128\142" },
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:getDirMarkEntity', func = test_method,
args = { 'getDirMarkEntity' },
expect = {
{ "&lrm;" },
{ "&lrm;" },
{ "&rlm;" },
"language code '[[bogus]]' is invalid",
}
args = { 'getDirMarkEntity' },
expect = {
{ "&lrm;" },
{ "&lrm;" },
{ "&rlm;" },
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:getDirMarkEntity opposite', func = test_method,
args = { 'getDirMarkEntity', true },
expect = {
{ "&rlm;" },
{ "&rlm;" },
{ "&lrm;" },
"language code '[[bogus]]' is invalid",
}
args = { 'getDirMarkEntity', true },
expect = {
{ "&rlm;" },
{ "&rlm;" },
{ "&lrm;" },
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:getDurationIntervals', func = test_method,
args = { 'getDurationIntervals', 86461 },
expect = {
{ { days = 1, minutes = 1, seconds = 1 } },
{ { days = 1, minutes = 1, seconds = 1 } },
{ { days = 1, minutes = 1, seconds = 1 } },
"language code '[[bogus]]' is invalid",
}
args = { 'getDurationIntervals', 86461 },
expect = {
{ { days = 1, minutes = 1, seconds = 1 } },
{ { days = 1, minutes = 1, seconds = 1 } },
{ { days = 1, minutes = 1, seconds = 1 } },
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:getDurationIntervals (hours and minutes)', func = test_method,
args = { 'getDurationIntervals', 86461, { 'hours', 'minutes' } },
expect = {
{ { hours = 24, minutes = 1 } },
{ { hours = 24, minutes = 1 } },
{ { hours = 24, minutes = 1 } },
"language code '[[bogus]]' is invalid",
}
args = { 'getDurationIntervals', 86461, { 'hours', 'minutes' } },
expect = {
{ { hours = 24, minutes = 1 } },
{ { hours = 24, minutes = 1 } },
{ { hours = 24, minutes = 1 } },
"language code '[[bogus]]' is invalid",
}
},
} )

View file

@ -30,189 +30,189 @@ local testObject = {}
local tests = {
-- checkType
{ name = 'checkType, valid', func = checkType, type='ToString',
args = { 'myFunc', 1, 'foo', 'string' },
expect = { nil }
args = { 'myFunc', 1, 'foo', 'string' },
expect = { nil }
},
{ name = 'checkType, invalid', func = checkType, type='ToString',
args = { 'myFunc', 1, 9, 'string' },
expect = "bad argument #1 to 'myFunc' (string expected, got number)"
args = { 'myFunc', 1, 9, 'string' },
expect = "bad argument #1 to 'myFunc' (string expected, got number)"
},
{ name = 'checkType, nil valid', func = checkType, type='ToString',
args = { 'myFunc', 1, nil, 'string', true },
expect = { nil }
args = { 'myFunc', 1, nil, 'string', true },
expect = { nil }
},
{ name = 'checkType, nil invalid', func = checkType, type='ToString',
args = { 'myFunc', 1, nil, 'string', false },
expect = "bad argument #1 to 'myFunc' (string expected, got nil)"
args = { 'myFunc', 1, nil, 'string', false },
expect = "bad argument #1 to 'myFunc' (string expected, got nil)"
},
{ name = 'checkType, boolean', func = checkType, type='ToString',
args = { 'myFunc', 1, true, 'boolean' },
expect = { nil }
args = { 'myFunc', 1, true, 'boolean' },
expect = { nil }
},
{ name = 'checkType, table', func = checkType, type='ToString',
args = { 'myFunc', 1, {}, 'table' },
expect = { nil }
args = { 'myFunc', 1, {}, 'table' },
expect = { nil }
},
{ name = 'checkType, function', func = checkType, type='ToString',
args = { 'myFunc', 1, function () return end, 'function' },
expect = { nil }
args = { 'myFunc', 1, function () return end, 'function' },
expect = { nil }
},
{ name = 'checkType, argument #2', func = checkType, type='ToString',
args = { 'myFunc', 2, 9, 'string' },
expect = "bad argument #2 to 'myFunc' (string expected, got number)"
args = { 'myFunc', 2, 9, 'string' },
expect = "bad argument #2 to 'myFunc' (string expected, got number)"
},
{ name = 'checkType, name', func = checkType, type='ToString',
args = { 'otherFunc', 1, 9, 'string' },
expect = "bad argument #1 to 'otherFunc' (string expected, got number)"
args = { 'otherFunc', 1, 9, 'string' },
expect = "bad argument #1 to 'otherFunc' (string expected, got number)"
},
-- checkTypeMulti
{ name = 'checkTypeMulti, single valid', func = checkTypeMulti, type='ToString',
args = { 'myFunc', 1, 'foo', { 'string' } },
expect = { nil }
args = { 'myFunc', 1, 'foo', { 'string' } },
expect = { nil }
},
{ name = 'checkTypeMulti, single type invalid (1)', func = checkTypeMulti, type='ToString',
args = { 'myFunc', 1, 9, { 'string' } },
expect = "bad argument #1 to 'myFunc' (string expected, got number)"
args = { 'myFunc', 1, 9, { 'string' } },
expect = "bad argument #1 to 'myFunc' (string expected, got number)"
},
{ name = 'checkTypeMulti, single type invalid (2)', func = checkTypeMulti, type='ToString',
args = { 'myFunc', 1, nil, { 'string' } },
expect = "bad argument #1 to 'myFunc' (string expected, got nil)"
args = { 'myFunc', 1, nil, { 'string' } },
expect = "bad argument #1 to 'myFunc' (string expected, got nil)"
},
{ name = 'checkTypeMulti, multiple types valid (1)', func = checkTypeMulti, type='ToString',
args = { 'myFunc', 1, 'foo', { 'string', 'number', 'table' } },
expect = { nil }
args = { 'myFunc', 1, 'foo', { 'string', 'number', 'table' } },
expect = { nil }
},
{ name = 'checkTypeMulti, multiple types valid (2)', func = checkTypeMulti, type='ToString',
args = { 'myFunc', 1, 9, { 'string', 'number', 'table' } },
expect = { nil }
args = { 'myFunc', 1, 9, { 'string', 'number', 'table' } },
expect = { nil }
},
{ name = 'checkTypeMulti, multiple types valid (3)', func = checkTypeMulti, type='ToString',
args = { 'myFunc', 1, {}, { 'string', 'number', 'table' } },
expect = { nil }
args = { 'myFunc', 1, {}, { 'string', 'number', 'table' } },
expect = { nil }
},
{ name = 'checkTypeMulti, multiple types invalid (1)', func = checkTypeMulti, type='ToString',
args = { 'myFunc', 1, true, { 'string', 'number', 'table' } },
expect = "bad argument #1 to 'myFunc' (string, number or table expected, got boolean)"
args = { 'myFunc', 1, true, { 'string', 'number', 'table' } },
expect = "bad argument #1 to 'myFunc' (string, number or table expected, got boolean)"
},
{ name = 'checkTypeMulti, multiple types invalid (2)', func = checkTypeMulti, type='ToString',
args = { 'myFunc', 1, nil, { 'string', 'number', 'table' } },
expect = "bad argument #1 to 'myFunc' (string, number or table expected, got nil)"
args = { 'myFunc', 1, nil, { 'string', 'number', 'table' } },
expect = "bad argument #1 to 'myFunc' (string, number or table expected, got nil)"
},
{ name = 'checkTypeMulti, multiple types invalid (3)', func = checkTypeMulti, type='ToString',
args = { 'myFunc', 1, function () return end, { 'string', 'number', 'table' } },
expect = "bad argument #1 to 'myFunc' (string, number or table expected, got function)"
args = { 'myFunc', 1, function () return end, { 'string', 'number', 'table' } },
expect = "bad argument #1 to 'myFunc' (string, number or table expected, got function)"
},
{ name = 'checkTypeMulti, two types invalid', func = checkTypeMulti, type='ToString',
args = { 'myFunc', 1, {}, { 'string', 'number' } },
expect = "bad argument #1 to 'myFunc' (string or number expected, got table)"
args = { 'myFunc', 1, {}, { 'string', 'number' } },
expect = "bad argument #1 to 'myFunc' (string or number expected, got table)"
},
{ name = 'checkTypeMulti, type order', func = checkTypeMulti, type='ToString',
args = { 'myFunc', 1, true, { 'table', 'number', 'string' } },
expect = "bad argument #1 to 'myFunc' (table, number or string expected, got boolean)"
args = { 'myFunc', 1, true, { 'table', 'number', 'string' } },
expect = "bad argument #1 to 'myFunc' (table, number or string expected, got boolean)"
},
{ name = 'checkTypeMulti, argument #2', func = checkTypeMulti, type='ToString',
args = { 'myFunc', 2, 9, { 'string' } },
expect = "bad argument #2 to 'myFunc' (string expected, got number)"
args = { 'myFunc', 2, 9, { 'string' } },
expect = "bad argument #2 to 'myFunc' (string expected, got number)"
},
{ name = 'checkTypeMulti, other name', func = checkTypeMulti, type='ToString',
args = { 'otherFunc', 1, 9, { 'string' } },
expect = "bad argument #1 to 'otherFunc' (string expected, got number)"
args = { 'otherFunc', 1, 9, { 'string' } },
expect = "bad argument #1 to 'otherFunc' (string expected, got number)"
},
{ name = 'checkTypeMulti, expectTypes not altered (1)', func = testExpectTypes, type='ToString',
args = { 'foo', { 'string', 'number', 'table' } },
expect = { 'string', 'number', 'table' }
args = { 'foo', { 'string', 'number', 'table' } },
expect = { 'string', 'number', 'table' }
},
{ name = 'checkTypeMulti, expectTypes not altered (2)', func = testExpectTypes, type='ToString',
args = { true, { 'string', 'number', 'table' } },
expect = { 'string', 'number', 'table' }
args = { true, { 'string', 'number', 'table' } },
expect = { 'string', 'number', 'table' }
},
{ name = 'checkTypeMulti, expectTypes not altered (3)', func = testExpectTypes, type='ToString',
args = { 'foo', { 'string' } },
expect = { 'string' }
args = { 'foo', { 'string' } },
expect = { 'string' }
},
{ name = 'checkTypeMulti, expectTypes not altered (4)', func = testExpectTypes, type='ToString',
args = { true, { 'string' } },
expect = { 'string' }
args = { true, { 'string' } },
expect = { 'string' }
},
-- checkTypeForIndex
{ name = 'checkTypeForIndex, valid', func = checkTypeForIndex, type='ToString',
args = { 'foo', 'bar', 'string' },
expect = { nil }
args = { 'foo', 'bar', 'string' },
expect = { nil }
},
{ name = 'checkTypeForIndex, invalid (1)', func = checkTypeForIndex, type='ToString',
args = { 'foo', 9, 'string' },
expect = "value for index 'foo' must be string, number given"
args = { 'foo', 9, 'string' },
expect = "value for index 'foo' must be string, number given"
},
{ name = 'checkTypeForIndex, invalid (2)', func = checkTypeForIndex, type='ToString',
args = { 'foo', 9, 'string' },
expect = "value for index 'foo' must be string, number given"
args = { 'foo', 9, 'string' },
expect = "value for index 'foo' must be string, number given"
},
{ name = 'checkTypeForIndex, other index', func = checkTypeForIndex, type='ToString',
args = { 'bar', 9, 'string' },
expect = "value for index 'bar' must be string, number given"
args = { 'bar', 9, 'string' },
expect = "value for index 'bar' must be string, number given"
},
-- checkTypeForNamedArg
{ name = 'checkTypeForNamedArg, valid', func = checkTypeForNamedArg, type='ToString',
args = { 'myFunc', 'myArg', 'foo', 'string' },
expect = { nil }
args = { 'myFunc', 'myArg', 'foo', 'string' },
expect = { nil }
},
{ name = 'checkTypeForNamedArg, invalid', func = checkTypeForNamedArg, type='ToString',
args = { 'myFunc', 'myArg', 9, 'string' },
expect = "bad named argument myArg to 'myFunc' (string expected, got number)"
args = { 'myFunc', 'myArg', 9, 'string' },
expect = "bad named argument myArg to 'myFunc' (string expected, got number)"
},
{ name = 'checkTypeForNamedArg, nil valid', func = checkTypeForNamedArg, type='ToString',
args = { 'myFunc', 'myArg', nil, 'string', true },
expect = { nil }
args = { 'myFunc', 'myArg', nil, 'string', true },
expect = { nil }
},
{ name = 'checkTypeForNamedArg, nil invalid', func = checkTypeForNamedArg, type='ToString',
args = { 'myFunc', 'myArg', nil, 'string', false },
expect = "bad named argument myArg to 'myFunc' (string expected, got nil)"
args = { 'myFunc', 'myArg', nil, 'string', false },
expect = "bad named argument myArg to 'myFunc' (string expected, got nil)"
},
{ name = 'checkTypeForNamedArg, other function', func = checkTypeForNamedArg, type='ToString',
args = { 'otherFunc', 'myArg', 9, 'string' },
expect = "bad named argument myArg to 'otherFunc' (string expected, got number)"
args = { 'otherFunc', 'myArg', 9, 'string' },
expect = "bad named argument myArg to 'otherFunc' (string expected, got number)"
},
{ name = 'checkTypeForNamedArg, other argument', func = checkTypeForNamedArg, type='ToString',
args = { 'myFunc', 'otherArg', 9, 'string' },
expect = "bad named argument otherArg to 'myFunc' (string expected, got number)"
args = { 'myFunc', 'otherArg', 9, 'string' },
expect = "bad named argument otherArg to 'myFunc' (string expected, got number)"
},
-- makeCheckSelfFunction
{ name = 'makeCheckSelfFunction, valid', func = testCheckSelf, type='ToString',
args = { testObject, 'myMethod', 'myLibrary', 'myObject', testObject, 'test object' },
expect = { nil }
args = { testObject, 'myMethod', 'myLibrary', 'myObject', testObject, 'test object' },
expect = { nil }
},
{ name = 'makeCheckSelfFunction, invalid (1)', func = testCheckSelf, type='ToString',
args = { {}, 'myMethod', 'myLibrary', 'myObject', testObject, 'test object' },
expect = 'myLibrary: invalid test object. Did you call myMethod with a dot instead ' ..
args = { {}, 'myMethod', 'myLibrary', 'myObject', testObject, 'test object' },
expect = 'myLibrary: invalid test object. Did you call myMethod with a dot instead ' ..
'of a colon, i.e. myObject.myMethod() instead of myObject:myMethod()?'
},
{ name = 'makeCheckSelfFunction, invalid (2)', func = testCheckSelf, type='ToString',
args = { 'foo', 'myMethod', 'myLibrary', 'myObject', testObject, 'test object' },
expect = 'myLibrary: invalid test object. Did you call myMethod with a dot instead ' ..
args = { 'foo', 'myMethod', 'myLibrary', 'myObject', testObject, 'test object' },
expect = 'myLibrary: invalid test object. Did you call myMethod with a dot instead ' ..
'of a colon, i.e. myObject.myMethod() instead of myObject:myMethod()?'
},
{ name = 'makeCheckSelfFunction, other method', func = testCheckSelf, type='ToString',
args = { {}, 'otherMethod', 'myLibrary', 'myObject', testObject, 'test object' },
expect = 'myLibrary: invalid test object. Did you call otherMethod with a dot instead ' ..
args = { {}, 'otherMethod', 'myLibrary', 'myObject', testObject, 'test object' },
expect = 'myLibrary: invalid test object. Did you call otherMethod with a dot instead ' ..
'of a colon, i.e. myObject.otherMethod() instead of myObject:otherMethod()?'
},
{ name = 'makeCheckSelfFunction, other library', func = testCheckSelf, type='ToString',
args = { {}, 'myMethod', 'otherLibrary', 'myObject', testObject, 'test object' },
expect = 'otherLibrary: invalid test object. Did you call myMethod with a dot instead ' ..
args = { {}, 'myMethod', 'otherLibrary', 'myObject', testObject, 'test object' },
expect = 'otherLibrary: invalid test object. Did you call myMethod with a dot instead ' ..
'of a colon, i.e. myObject.myMethod() instead of myObject:myMethod()?'
},
{ name = 'makeCheckSelfFunction, other object', func = testCheckSelf, type='ToString',
args = { {}, 'myMethod', 'otherLibrary', 'otherObject', testObject, 'test object' },
expect = 'otherLibrary: invalid test object. Did you call myMethod with a dot instead ' ..
args = { {}, 'myMethod', 'otherLibrary', 'otherObject', testObject, 'test object' },
expect = 'otherLibrary: invalid test object. Did you call myMethod with a dot instead ' ..
'of a colon, i.e. otherObject.myMethod() instead of otherObject:myMethod()?'
},
{ name = 'makeCheckSelfFunction, other description', func = testCheckSelf, type='ToString',
args = { {}, 'myMethod', 'myLibrary', 'myObject', testObject, 'test object' },
expect = 'myLibrary: invalid test object. Did you call myMethod with a dot instead ' ..
args = { {}, 'myMethod', 'myLibrary', 'myObject', testObject, 'test object' },
expect = 'myLibrary: invalid test object. Did you call myMethod with a dot instead ' ..
'of a colon, i.e. myObject.myMethod() instead of myObject:myMethod()?'
},
}

View file

@ -27,44 +27,44 @@ end
return testframework.getTestProvider( {
{ name = 'exists (1)', func = test_exists,
args = { 'mainpage' },
expect = { true }
args = { 'mainpage' },
expect = { true }
},
{ name = 'exists (2)', func = test_exists,
args = { 'i-dont-exist-evar' },
expect = { false }
args = { 'i-dont-exist-evar' },
expect = { false }
},
{ name = 'inLanguage', func = test_language,
expect = { 'Main Page', 'Заглавная страница', 'Заглавная страница' }
expect = { 'Main Page', 'Заглавная страница', 'Заглавная страница' }
},
{ name = 'plain param', func = test_params,
args = { '($1 $2)', 'params', "'''foo'''", 123456 },
expect = { "('''foo''' 123456)" }
args = { '($1 $2)', 'params', "'''foo'''", 123456 },
expect = { "('''foo''' 123456)" }
},
{ name = 'raw param', func = test_params,
args = { '($1 $2)', 'rawParams', "'''foo'''", 123456 },
expect = { "('''foo''' 123456)" }
args = { '($1 $2)', 'rawParams', "'''foo'''", 123456 },
expect = { "('''foo''' 123456)" }
},
{ name = 'num param', func = test_params,
args = { '($1 $2)', 'numParams', "-1.23", 123456 },
expect = { "(-1.23 123,456)" }
args = { '($1 $2)', 'numParams', "-1.23", 123456 },
expect = { "(-1.23 123,456)" }
},
{ name = 'mixed params', func = test_params,
args = { '($1 $2 $3)', 'params',
args = { '($1 $2 $3)', 'params',
"'''foo'''", mw.message.rawParam( "'''foo'''" ), mw.message.numParam( 123456 )
},
expect = { "('''foo''' '''foo''' 123,456)" }
},
expect = { "('''foo''' '''foo''' 123,456)" }
},
{ name = 'message as param', func = test_params,
args = { '($1)', 'params', mw.message.newRawMessage( 'bar' ) },
expect = { "(bar)" }
args = { '($1)', 'params', mw.message.newRawMessage( 'bar' ) },
expect = { "(bar)" }
},
{ name = 'different title', func = test_params,
args = { '($1)', 'params', mw.message.newRawMessage( 'bar' ) },
expect = { "(bar)" }
args = { '($1)', 'params', mw.message.newRawMessage( 'bar' ) },
expect = { "(bar)" }
},
} )

View file

@ -53,130 +53,130 @@ end
return testframework.getTestProvider( {
{ name = 'parameter: siteName',
func = type, args = { mw.site.siteName },
expect = { 'string' }
func = type, args = { mw.site.siteName },
expect = { 'string' }
},
{ name = 'parameter: server',
func = type, args = { mw.site.server },
expect = { 'string' }
func = type, args = { mw.site.server },
expect = { 'string' }
},
{ name = 'parameter set: scriptPath',
func = type, args = { mw.site.scriptPath },
expect = { 'string' }
func = type, args = { mw.site.scriptPath },
expect = { 'string' }
},
{ name = 'parameter set: stats.pages',
func = type, args = { mw.site.stats.pages },
expect = { 'number' }
func = type, args = { mw.site.stats.pages },
expect = { 'number' }
},
{ name = 'pagesInCategory',
func = type, args = { mw.site.stats.pagesInCategory( "Example" ) },
expect = { 'number' }
func = type, args = { mw.site.stats.pagesInCategory( "Example" ) },
expect = { 'number' }
},
{ name = 'pagesInNamespace',
func = type, args = { mw.site.stats.pagesInNamespace( 0 ) },
expect = { 'number' }
func = type, args = { mw.site.stats.pagesInNamespace( 0 ) },
expect = { 'number' }
},
{ name = 'usersInGroup',
func = type, args = { mw.site.stats.usersInGroup( 'sysop' ) },
expect = { 'number' }
func = type, args = { mw.site.stats.usersInGroup( 'sysop' ) },
expect = { 'number' }
},
{ name = 'Project namespace by number',
func = nsTest, args = { 4, 'canonicalName' },
expect = { 'Project' }
func = nsTest, args = { 4, 'canonicalName' },
expect = { 'Project' }
},
{ name = 'Project namespace by name',
func = nsTest, args = { 'Project', 'id' },
expect = { 4 }
func = nsTest, args = { 'Project', 'id' },
expect = { 4 }
},
{ name = 'Project namespace by name (2)',
func = nsTest, args = { 'PrOjEcT', 'canonicalName' },
expect = { 'Project' }
func = nsTest, args = { 'PrOjEcT', 'canonicalName' },
expect = { 'Project' }
},
{ name = 'Project namespace subject is itself',
func = nsTest, args = { 'Project', 'subject', 'canonicalName' },
expect = { 'Project' }
func = nsTest, args = { 'Project', 'subject', 'canonicalName' },
expect = { 'Project' }
},
{ name = 'Project talk namespace via Project',
func = nsTest, args = { 'Project', 'talk', 'canonicalName' },
expect = { 'Project talk' }
func = nsTest, args = { 'Project', 'talk', 'canonicalName' },
expect = { 'Project talk' }
},
{ name = 'Project namespace via Project talk',
func = nsTest, args = { 'Project_talk', 'subject', 'canonicalName' },
expect = { 'Project' }
func = nsTest, args = { 'Project_talk', 'subject', 'canonicalName' },
expect = { 'Project' }
},
{ name = 'Project talk namespace via Project (associated)',
func = nsTest, args = { 'Project', 'associated', 'canonicalName' },
expect = { 'Project talk' }
func = nsTest, args = { 'Project', 'associated', 'canonicalName' },
expect = { 'Project talk' }
},
{ name = 'Project talk namespace by name (standard caps, no underscores)',
func = nsTest, args = { 'Project talk', 'id' },
expect = { 5 }
func = nsTest, args = { 'Project talk', 'id' },
expect = { 5 }
},
{ name = 'Project talk namespace by name (standard caps, underscores)',
func = nsTest, args = { 'Project_talk', 'id' },
expect = { 5 }
func = nsTest, args = { 'Project_talk', 'id' },
expect = { 5 }
},
{ name = 'Project talk namespace by name (odd caps, no underscores)',
func = nsTest, args = { 'pRoJeCt tAlK', 'id' },
expect = { 5 }
func = nsTest, args = { 'pRoJeCt tAlK', 'id' },
expect = { 5 }
},
{ name = 'Project talk namespace by name (odd caps, underscores)',
func = nsTest, args = { 'pRoJeCt_tAlK', 'id' },
expect = { 5 }
func = nsTest, args = { 'pRoJeCt_tAlK', 'id' },
expect = { 5 }
},
{ name = 'Project talk namespace by name (extraneous spaces and underscores)',
func = nsTest, args = { '_ _ _Project_ _talk_ _ _', 'id' },
expect = { 5 }
func = nsTest, args = { '_ _ _Project_ _talk_ _ _', 'id' },
expect = { 5 }
},
{ name = 'interwikiMap (all prefixes)',
func = isValidInterwikiMap, args = { mw.site.interwikiMap() },
expect = { true }
func = isValidInterwikiMap, args = { mw.site.interwikiMap() },
expect = { true }
},
{ name = 'interwikiMap (local prefixes)',
func = isValidInterwikiMap, args = { mw.site.interwikiMap( 'local' ) },
expect = { true }
func = isValidInterwikiMap, args = { mw.site.interwikiMap( 'local' ) },
expect = { true }
},
{ name = 'interwikiMap (non-local prefixes)',
func = isValidInterwikiMap, args = { mw.site.interwikiMap( '!local' ) },
expect = { true }
func = isValidInterwikiMap, args = { mw.site.interwikiMap( '!local' ) },
expect = { true }
},
{ name = 'interwikiMap (type error 1)',
func = mw.site.interwikiMap, args = { 123 },
expect = "bad argument #1 to 'interwikiMap' (string expected, got number)"
func = mw.site.interwikiMap, args = { 123 },
expect = "bad argument #1 to 'interwikiMap' (string expected, got number)"
},
{ name = 'interwikiMap (type error 2)',
func = mw.site.interwikiMap, args = { false },
expect = "bad argument #1 to 'interwikiMap' (string expected, got boolean)"
func = mw.site.interwikiMap, args = { false },
expect = "bad argument #1 to 'interwikiMap' (string expected, got boolean)"
},
{ name = 'interwikiMap (unknown filter 1)',
func = mw.site.interwikiMap, args = { '' },
expect = "bad argument #1 to 'interwikiMap' (unknown filter '')"
func = mw.site.interwikiMap, args = { '' },
expect = "bad argument #1 to 'interwikiMap' (unknown filter '')"
},
{ name = 'interwikiMap (unknown filter 2)',
func = mw.site.interwikiMap, args = { 'foo' },
expect = "bad argument #1 to 'interwikiMap' (unknown filter 'foo')"
func = mw.site.interwikiMap, args = { 'foo' },
expect = "bad argument #1 to 'interwikiMap' (unknown filter 'foo')"
},
} )

View file

@ -38,372 +38,372 @@ recursiveTable.recursiveTable = recursiveTable
-- Tests
local tests = {
{ name = 'trim',
func = mw.text.trim, args = { ' foo bar ' },
expect = { 'foo bar' }
func = mw.text.trim, args = { ' foo bar ' },
expect = { 'foo bar' }
},
{ name = 'trim right',
func = mw.text.trim, args = { 'foo bar ' },
expect = { 'foo bar' }
func = mw.text.trim, args = { 'foo bar ' },
expect = { 'foo bar' }
},
{ name = 'trim left',
func = mw.text.trim, args = { ' foo bar' },
expect = { 'foo bar' }
func = mw.text.trim, args = { ' foo bar' },
expect = { 'foo bar' }
},
{ name = 'trim none',
func = mw.text.trim, args = { 'foo bar' },
expect = { 'foo bar' }
func = mw.text.trim, args = { 'foo bar' },
expect = { 'foo bar' }
},
{ name = 'trim charset',
func = mw.text.trim, args = { 'xxx foo bar xxx', 'x' },
expect = { ' foo bar ' }
func = mw.text.trim, args = { 'xxx foo bar xxx', 'x' },
expect = { ' foo bar ' }
},
{ name = 'encode',
func = mw.text.encode, args = { '<b>foo\194\160"bar"</b> & \'baz\'' },
expect = { '&lt;b&gt;foo&nbsp;&quot;bar&quot;&lt;/b&gt; &amp; &#039;baz&#039;' }
func = mw.text.encode, args = { '<b>foo\194\160"bar"</b> & \'baz\'' },
expect = { '&lt;b&gt;foo&nbsp;&quot;bar&quot;&lt;/b&gt; &amp; &#039;baz&#039;' }
},
{ name = 'encode charset',
func = mw.text.encode, args = { '<b>foo\194\160"bar"</b> & \'baz\'', 'aeiou' },
expect = { '<b>f&#111;&#111;\194\160"b&#97;r"</b> & \'b&#97;z\'' }
func = mw.text.encode, args = { '<b>foo\194\160"bar"</b> & \'baz\'', 'aeiou' },
expect = { '<b>f&#111;&#111;\194\160"b&#97;r"</b> & \'b&#97;z\'' }
},
{ name = 'decode',
func = mw.text.decode,
args = { '&lt;&gt;&amp;&quot; &#102;&#111;&#x6f; &#x0066;&#00111;&#x6F; &hearts; &amp;quot;' },
expect = { '<>&" foo foo &hearts; &quot;' }
func = mw.text.decode,
args = { '&lt;&gt;&amp;&quot; &#102;&#111;&#x6f; &#x0066;&#00111;&#x6F; &hearts; &amp;quot;' },
expect = { '<>&" foo foo &hearts; &quot;' }
},
{ name = 'decode named',
func = mw.text.decode,
args = { '&lt;&gt;&amp;&quot; &#102;&#111;&#x6f; &#x0066;&#00111;&#x6F; &hearts; &amp;quot;', true },
expect = { '<>&" foo foo ♥ &quot;' }
func = mw.text.decode,
args = { '&lt;&gt;&amp;&quot; &#102;&#111;&#x6f; &#x0066;&#00111;&#x6F; &hearts; &amp;quot;', true },
expect = { '<>&" foo foo ♥ &quot;' }
},
{ name = 'nowiki',
func = mw.text.nowiki,
args = { '*"&\'<=>[]{|}#*:;\n*\n#\n:\n;\nhttp://example.com:80/\nRFC 123, ISBN 456' },
expect = {
'&#42;&#34;&#38;&#39;&#60;&#61;&#62;&#91;&#93;&#123;&#124;&#125;#*:;' ..
'\n&#42;\n&#35;\n&#58;\n&#59;\nhttp&#58;//example.com:80/' ..
'\nRFC&#32;123, ISBN&#32;456'
}
func = mw.text.nowiki,
args = { '*"&\'<=>[]{|}#*:;\n*\n#\n:\n;\nhttp://example.com:80/\nRFC 123, ISBN 456' },
expect = {
'&#42;&#34;&#38;&#39;&#60;&#61;&#62;&#91;&#93;&#123;&#124;&#125;#*:;' ..
'\n&#42;\n&#35;\n&#58;\n&#59;\nhttp&#58;//example.com:80/' ..
'\nRFC&#32;123, ISBN&#32;456'
}
},
{ name = 'tag, simple',
func = mw.text.tag,
args = { { name = 'b' } },
expect = { '<b>' }
func = mw.text.tag,
args = { { name = 'b' } },
expect = { '<b>' }
},
{ name = 'tag, simple with content',
func = mw.text.tag,
args = { { name = 'b', content = 'foo' } },
expect = { '<b>foo</b>' }
func = mw.text.tag,
args = { { name = 'b', content = 'foo' } },
expect = { '<b>foo</b>' }
},
{ name = 'tag, simple self-closing',
func = mw.text.tag,
args = { { name = 'br', content = false } },
expect = { '<br />' }
func = mw.text.tag,
args = { { name = 'br', content = false } },
expect = { '<br />' }
},
{ name = 'tag, args',
func = mw.text.tag,
args = { { name = 'b', attrs = tagattrs } },
expect = { '<b present key="value" n="42">' }
func = mw.text.tag,
args = { { name = 'b', attrs = tagattrs } },
expect = { '<b present key="value" n="42">' }
},
{ name = 'tag, args with content',
func = mw.text.tag,
args = { { name = 'b', attrs = tagattrs, content = 'foo' } },
expect = { '<b present key="value" n="42">foo</b>' }
func = mw.text.tag,
args = { { name = 'b', attrs = tagattrs, content = 'foo' } },
expect = { '<b present key="value" n="42">foo</b>' }
},
{ name = 'tag, args self-closing',
func = mw.text.tag,
args = { { name = 'br', attrs = tagattrs, content = false } },
expect = { '<br present key="value" n="42" />' }
func = mw.text.tag,
args = { { name = 'br', attrs = tagattrs, content = false } },
expect = { '<br present key="value" n="42" />' }
},
{ name = 'tag, args, positional params',
func = mw.text.tag,
args = { 'b', tagattrs },
expect = { '<b present key="value" n="42">' }
func = mw.text.tag,
args = { 'b', tagattrs },
expect = { '<b present key="value" n="42">' }
},
{ name = 'tag, args with content, positional params',
func = mw.text.tag,
args = { 'b', tagattrs, 'foo' },
expect = { '<b present key="value" n="42">foo</b>' }
func = mw.text.tag,
args = { 'b', tagattrs, 'foo' },
expect = { '<b present key="value" n="42">foo</b>' }
},
{ name = 'unstrip (nowiki)',
func = stripTest,
args = { mw.text.unstrip, mw.text.stripTest.nowiki },
expect = { 'NoWiki' }
func = stripTest,
args = { mw.text.unstrip, mw.text.stripTest.nowiki },
expect = { 'NoWiki' }
},
{ name = 'unstrip (general)',
func = stripTest,
args = { mw.text.unstrip, mw.text.stripTest.general },
expect = { '' }
func = stripTest,
args = { mw.text.unstrip, mw.text.stripTest.general },
expect = { '' }
},
{ name = 'unstripNoWiki (nowiki)',
func = stripTest,
args = { mw.text.unstripNoWiki, mw.text.stripTest.nowiki },
expect = { 'NoWiki' }
func = stripTest,
args = { mw.text.unstripNoWiki, mw.text.stripTest.nowiki },
expect = { 'NoWiki' }
},
{ name = 'unstripNoWiki (general)',
func = stripTest,
args = { mw.text.unstripNoWiki, mw.text.stripTest.general },
expect = { 'strip-marker' }
func = stripTest,
args = { mw.text.unstripNoWiki, mw.text.stripTest.general },
expect = { 'strip-marker' }
},
{ name = 'killMarkers',
func = mw.text.killMarkers,
args = { 'a' .. mw.text.stripTest.nowiki .. 'b' .. mw.text.stripTest.general .. 'c' },
expect = { 'abc' }
func = mw.text.killMarkers,
args = { 'a' .. mw.text.stripTest.nowiki .. 'b' .. mw.text.stripTest.general .. 'c' },
expect = { 'abc' }
},
{ name = 'split, simple',
func = mw.text.split, args = { 'a,b,c,d', ',' },
expect = { { 'a', 'b', 'c', 'd' } }
func = mw.text.split, args = { 'a,b,c,d', ',' },
expect = { { 'a', 'b', 'c', 'd' } }
},
{ name = 'split, no separator',
func = mw.text.split, args = { 'xxx', ',' },
expect = { { 'xxx' } }
func = mw.text.split, args = { 'xxx', ',' },
expect = { { 'xxx' } }
},
{ name = 'split, empty string',
func = mw.text.split, args = { '', ',' },
expect = { { '' } }
func = mw.text.split, args = { '', ',' },
expect = { { '' } }
},
{ name = 'split, with empty items',
func = mw.text.split, args = { ',,', ',' },
expect = { { '', '', '' } }
func = mw.text.split, args = { ',,', ',' },
expect = { { '', '', '' } }
},
{ name = 'split, with empty items (1)',
func = mw.text.split, args = { 'x,,', ',' },
expect = { { 'x', '', '' } }
func = mw.text.split, args = { 'x,,', ',' },
expect = { { 'x', '', '' } }
},
{ name = 'split, with empty items (2)',
func = mw.text.split, args = { ',x,', ',' },
expect = { { '', 'x', '' } }
func = mw.text.split, args = { ',x,', ',' },
expect = { { '', 'x', '' } }
},
{ name = 'split, with empty items (3)',
func = mw.text.split, args = { ',,x', ',' },
expect = { { '', '', 'x' } }
func = mw.text.split, args = { ',,x', ',' },
expect = { { '', '', 'x' } }
},
{ name = 'split, with empty items (4)',
func = mw.text.split, args = { ',x,x', ',' },
expect = { { '', 'x', 'x' } }
func = mw.text.split, args = { ',x,x', ',' },
expect = { { '', 'x', 'x' } }
},
{ name = 'split, with empty items (5)',
func = mw.text.split, args = { 'x,,x', ',' },
expect = { { 'x', '', 'x' } }
func = mw.text.split, args = { 'x,,x', ',' },
expect = { { 'x', '', 'x' } }
},
{ name = 'split, with empty items (7)',
func = mw.text.split, args = { 'x,x,', ',' },
expect = { { 'x', 'x', '' } }
func = mw.text.split, args = { 'x,x,', ',' },
expect = { { 'x', 'x', '' } }
},
{ name = 'split, with empty pattern',
func = mw.text.split, args = { 'xxx', '' },
expect = { { 'x', 'x', 'x' } }
func = mw.text.split, args = { 'xxx', '' },
expect = { { 'x', 'x', 'x' } }
},
{ name = 'split, with empty pattern (2)',
func = mw.text.split, args = { 'xxx', ',?' },
expect = { { 'x', 'x', 'x' } }
func = mw.text.split, args = { 'xxx', ',?' },
expect = { { 'x', 'x', 'x' } }
},
{ name = 'listToText (0)',
func = mw.text.listToText, args = { {} },
expect = { '' }
func = mw.text.listToText, args = { {} },
expect = { '' }
},
{ name = 'listToText (1)',
func = mw.text.listToText, args = { { 1 } },
expect = { '1' }
func = mw.text.listToText, args = { { 1 } },
expect = { '1' }
},
{ name = 'listToText (2)',
func = mw.text.listToText, args = { { 1, 2 } },
expect = { '1 and 2' }
func = mw.text.listToText, args = { { 1, 2 } },
expect = { '1 and 2' }
},
{ name = 'listToText (3)',
func = mw.text.listToText, args = { { 1, 2, 3 } },
expect = { '1, 2 and 3' }
func = mw.text.listToText, args = { { 1, 2, 3 } },
expect = { '1, 2 and 3' }
},
{ name = 'listToText (4)',
func = mw.text.listToText, args = { { 1, 2, 3, 4 } },
expect = { '1, 2, 3 and 4' }
func = mw.text.listToText, args = { { 1, 2, 3, 4 } },
expect = { '1, 2, 3 and 4' }
},
{ name = 'listToText, alternate separator',
func = mw.text.listToText, args = { { 1, 2, 3, 4 }, '; ' },
expect = { '1; 2; 3 and 4' }
func = mw.text.listToText, args = { { 1, 2, 3, 4 }, '; ' },
expect = { '1; 2; 3 and 4' }
},
{ name = 'listToText, alternate conjunction',
func = mw.text.listToText, args = { { 1, 2, 3, 4 }, nil, ' or ' },
expect = { '1, 2, 3 or 4' }
func = mw.text.listToText, args = { { 1, 2, 3, 4 }, nil, ' or ' },
expect = { '1, 2, 3 or 4' }
},
{ name = 'truncate, no truncation',
func = mw.text.truncate, args = { 'foobarbaz', 9 },
expect = { 'foobarbaz' }
func = mw.text.truncate, args = { 'foobarbaz', 9 },
expect = { 'foobarbaz' }
},
{ name = 'truncate, no truncation (2)',
func = mw.text.truncate, args = { 'foobarbaz', -9 },
expect = { 'foobarbaz' }
func = mw.text.truncate, args = { 'foobarbaz', -9 },
expect = { 'foobarbaz' }
},
{ name = 'truncate, tail truncation',
func = mw.text.truncate, args = { 'foobarbaz', 3 },
expect = { 'foo...' }
func = mw.text.truncate, args = { 'foobarbaz', 3 },
expect = { 'foo...' }
},
{ name = 'truncate, head truncation',
func = mw.text.truncate, args = { 'foobarbaz', -3 },
expect = { '...baz' }
func = mw.text.truncate, args = { 'foobarbaz', -3 },
expect = { '...baz' }
},
{ name = 'truncate, avoid silly truncation',
func = mw.text.truncate, args = { 'foobarbaz', 8 },
expect = { 'foobarbaz' }
func = mw.text.truncate, args = { 'foobarbaz', 8 },
expect = { 'foobarbaz' }
},
{ name = 'truncate, avoid silly truncation (2)',
func = mw.text.truncate, args = { 'foobarbaz', 6 },
expect = { 'foobarbaz' }
func = mw.text.truncate, args = { 'foobarbaz', 6 },
expect = { 'foobarbaz' }
},
{ name = 'truncate, alternate ellipsis',
func = mw.text.truncate, args = { 'foobarbaz', 3, '!' },
expect = { 'foo!' }
func = mw.text.truncate, args = { 'foobarbaz', 3, '!' },
expect = { 'foo!' }
},
{ name = 'truncate, with adjusted length',
func = mw.text.truncate, args = { 'foobarbaz', 6, nil, true },
expect = { 'foo...' }
func = mw.text.truncate, args = { 'foobarbaz', 6, nil, true },
expect = { 'foo...' }
},
{ name = 'truncate, with adjusted length (2)',
func = mw.text.truncate, args = { 'foobarbaz', -6, nil, true },
expect = { '...baz' }
func = mw.text.truncate, args = { 'foobarbaz', -6, nil, true },
expect = { '...baz' }
},
{ name = 'truncate, ridiculously short',
func = mw.text.truncate, args = { 'foobarbaz', 1, nil, true },
expect = { '...' }
func = mw.text.truncate, args = { 'foobarbaz', 1, nil, true },
expect = { '...' }
},
{ name = 'truncate, ridiculously short (2)',
func = mw.text.truncate, args = { 'foobarbaz', -1, nil, true },
expect = { '...' }
func = mw.text.truncate, args = { 'foobarbaz', -1, nil, true },
expect = { '...' }
},
{ name = 'json encode-decode round trip, simple object',
func = jsonRoundTripTest,
args = { {
int = 2,
string = "foo",
['true'] = true,
['false'] = false,
} },
expect = { {
int = 2,
string = "foo",
['true'] = true,
['false'] = false,
} },
func = jsonRoundTripTest,
args = { {
int = 2,
string = "foo",
['true'] = true,
['false'] = false,
} },
expect = { {
int = 2,
string = "foo",
['true'] = true,
['false'] = false,
} },
},
{ name = 'json decode, simple object',
func = mw.text.jsonDecode,
args = { '{"int":2,"string":"foo","true":true,"false":false}' },
expect = { {
int = 2,
string = "foo",
['true'] = true,
['false'] = false,
} },
func = mw.text.jsonDecode,
args = { '{"int":2,"string":"foo","true":true,"false":false}' },
expect = { {
int = 2,
string = "foo",
['true'] = true,
['false'] = false,
} },
},
{ name = 'json encode, simple array',
func = mw.text.jsonEncode,
args = { { 1, "foo", true, false } },
expect = { '[1,"foo",true,false]' }
func = mw.text.jsonEncode,
args = { { 1, "foo", true, false } },
expect = { '[1,"foo",true,false]' }
},
{ name = 'json decode, simple array',
func = mw.text.jsonDecode,
args = { '[1,"foo",true,false]' },
expect = { { 1, "foo", true, false } }
func = mw.text.jsonDecode,
args = { '[1,"foo",true,false]' },
expect = { { 1, "foo", true, false } }
},
{ name = 'json encode-decode round trip, object with numeric keys',
func = jsonRoundTripTest,
args = { { x = "x", [1] = 1, [2] = 2 } },
expect = { { x = "x", [1] = 1, [2] = 2 } }
func = jsonRoundTripTest,
args = { { x = "x", [1] = 1, [2] = 2 } },
expect = { { x = "x", [1] = 1, [2] = 2 } }
},
{ name = 'json decode, object with numeric keys',
func = mw.text.jsonDecode,
args = { '{"x":"x","1":1,"2":2}' },
expect = { { x = "x", [1] = 1, [2] = 2 } }
func = mw.text.jsonDecode,
args = { '{"x":"x","1":1,"2":2}' },
expect = { { x = "x", [1] = 1, [2] = 2 } }
},
{ name = 'json encode, simple array, preserve keys',
func = mw.text.jsonEncode,
args = { { 1, "foo", true, false }, mw.text.JSON_PRESERVE_KEYS },
expect = { '{"1":1,"2":"foo","3":true,"4":false}' }
func = mw.text.jsonEncode,
args = { { 1, "foo", true, false }, mw.text.JSON_PRESERVE_KEYS },
expect = { '{"1":1,"2":"foo","3":true,"4":false}' }
},
{ name = 'json decode, simple array, preserve keys',
func = mw.text.jsonDecode,
args = { '[1,"foo",true,false]', mw.text.JSON_PRESERVE_KEYS },
expect = { { [0] = 1, "foo", true, false } }
func = mw.text.jsonDecode,
args = { '[1,"foo",true,false]', mw.text.JSON_PRESERVE_KEYS },
expect = { { [0] = 1, "foo", true, false } }
},
{ name = 'json encode, nested arrays',
func = mw.text.jsonEncode,
args = { { 1, 2, 3, { 4, 5, { 6, 7, 8 } } } },
expect = { '[1,2,3,[4,5,[6,7,8]]]' }
func = mw.text.jsonEncode,
args = { { 1, 2, 3, { 4, 5, { 6, 7, 8 } } } },
expect = { '[1,2,3,[4,5,[6,7,8]]]' }
},
{ name = 'json decode, nested arrays',
func = mw.text.jsonDecode,
args = { '[1,2,3,[4,5,[6,7,8]]]' },
expect = { { 1, 2, 3, { 4, 5, { 6, 7, 8 } } } }
func = mw.text.jsonDecode,
args = { '[1,2,3,[4,5,[6,7,8]]]' },
expect = { { 1, 2, 3, { 4, 5, { 6, 7, 8 } } } }
},
{ name = 'json encode, array in object',
func = mw.text.jsonEncode,
args = { { x = { 1, 2, { y = { 3, 4 } } } } },
expect = { '{"x":[1,2,{"y":[3,4]}]}' }
func = mw.text.jsonEncode,
args = { { x = { 1, 2, { y = { 3, 4 } } } } },
expect = { '{"x":[1,2,{"y":[3,4]}]}' }
},
{ name = 'json decode, array in object',
func = mw.text.jsonDecode,
args = { '{"x":[1,2,{"y":[3,4]}],"z":[5,6]}' },
expect = { { x = { 1, 2, { y = { 3, 4 } } }, z = { 5, 6 } } }
func = mw.text.jsonDecode,
args = { '{"x":[1,2,{"y":[3,4]}],"z":[5,6]}' },
expect = { { x = { 1, 2, { y = { 3, 4 } } }, z = { 5, 6 } } }
},
{ name = 'json decode, empty array',
func = mw.text.jsonDecode,
args = { '[]' },
expect = { {} }
func = mw.text.jsonDecode,
args = { '[]' },
expect = { {} }
},
{ name = 'json decode, empty object',
func = mw.text.jsonDecode,
args = { '{}' },
expect = { {} }
func = mw.text.jsonDecode,
args = { '{}' },
expect = { {} }
},
{ name = 'json encode, object with one large numeric index',
func = mw.text.jsonEncode,
args = { { [1000] = 1 } },
expect = { '{"1000":1}' }
func = mw.text.jsonEncode,
args = { { [1000] = 1 } },
expect = { '{"1000":1}' }
},
{ name = 'json decode, object with one large numeric index',
func = mw.text.jsonDecode,
args = { '{"1000":1}' },
expect = { { [1000] = 1 } }
func = mw.text.jsonDecode,
args = { '{"1000":1}' },
expect = { { [1000] = 1 } }
},
{ name = 'json encode, array with holes (ideally would be "[1,2,nil,4]", but probably not worth worrying about)',
func = mw.text.jsonEncode,
args = { { 1, 2, nil, 4 } },
expect = { '{"1":1,"2":2,"4":4}' }
func = mw.text.jsonEncode,
args = { { 1, 2, nil, 4 } },
expect = { '{"1":1,"2":2,"4":4}' }
},
{ name = 'json decode, array with null (ideally would somehow insist on having a [3] = nil element, but that\'s not easily possible)',
func = mw.text.jsonDecode,
args = { '[1,2,null,4]' },
expect = { { 1, 2, [4] = 4 } }
func = mw.text.jsonDecode,
args = { '[1,2,null,4]' },
expect = { { 1, 2, [4] = 4 } }
},
{ name = 'json encode, empty table (could be either [] or {}, but change should be announced)',
func = mw.text.jsonEncode,
args = { {} },
expect = { '[]' }
func = mw.text.jsonEncode,
args = { {} },
expect = { '[]' }
},
{ name = 'json encode, table with index 0 (technically wrong, but probably not worth working around)',
func = mw.text.jsonEncode,
args = { { [0] = "zero" } },
expect = { '["zero"]' }
func = mw.text.jsonEncode,
args = { { [0] = "zero" } },
expect = { '["zero"]' }
},
{ name = 'json decode, object with index 1 (technically wrong, but probably not worth working around)',
func = mw.text.jsonDecode,
args = { '{"1":"one"}' },
expect = { { 'one' } }
func = mw.text.jsonDecode,
args = { '{"1":"one"}' },
expect = { { 'one' } }
},
{ name = 'json encode, pretty',
func = mw.text.jsonEncode,
args = { { 1, 2, 3, { 4, 5, { 6, 7, { x = 8 } } } }, mw.text.JSON_PRETTY },
expect = { [=[[
func = mw.text.jsonEncode,
args = { { 1, 2, 3, { 4, 5, { 6, 7, { x = 8 } } } }, mw.text.JSON_PRETTY },
expect = { [=[[
1,
2,
3,
@ -421,88 +421,88 @@ local tests = {
]]=] }
},
{ name = 'json encode, raw value (technically not allowed, but a common extension)',
func = mw.text.jsonEncode,
args = { "foo" },
expect = { '"foo"' }
func = mw.text.jsonEncode,
args = { "foo" },
expect = { '"foo"' }
},
{ name = 'json decode, raw value (technically not allowed, but a common extension)',
func = mw.text.jsonDecode,
args = { '"foo"' },
expect = { 'foo' }
func = mw.text.jsonDecode,
args = { '"foo"' },
expect = { 'foo' }
},
{ name = 'json encode, sneaky nil injection (object)',
func = mw.text.jsonEncode,
args = { setmetatable( {}, {
__pairs = function ( t )
return function ( t, k )
if k ~= "foo" then
return "foo", nil
end
end, t, nil
end,
} ) },
expect = { '{"foo":null}' }
func = mw.text.jsonEncode,
args = { setmetatable( {}, {
__pairs = function ( t )
return function ( t, k )
if k ~= "foo" then
return "foo", nil
end
end, t, nil
end,
} ) },
expect = { '{"foo":null}' }
},
{ name = 'json encode, sneaky nil injection (array)',
func = mw.text.jsonEncode,
args = { setmetatable( { "one", "two", nil, "four" }, {
__pairs = function ( t )
return function ( t, k )
k = k and k + 1 or 1
if k <= 4 then
return k, t[k]
end
end, t, nil
end,
} ) },
expect = { '["one","two",null,"four"]' }
func = mw.text.jsonEncode,
args = { setmetatable( { "one", "two", nil, "four" }, {
__pairs = function ( t )
return function ( t, k )
k = k and k + 1 or 1
if k <= 4 then
return k, t[k]
end
end, t, nil
end,
} ) },
expect = { '["one","two",null,"four"]' }
},
{ name = 'json encode, invalid values (inf)',
func = mw.text.jsonEncode,
args = { { 1/0 } },
expect = 'mw.text.jsonEncode: Cannot encode non-finite numbers'
func = mw.text.jsonEncode,
args = { { 1/0 } },
expect = 'mw.text.jsonEncode: Cannot encode non-finite numbers'
},
{ name = 'json encode, invalid values (nan)',
func = mw.text.jsonEncode,
args = { { 0/0 } },
expect = 'mw.text.jsonEncode: Cannot encode non-finite numbers'
func = mw.text.jsonEncode,
args = { { 0/0 } },
expect = 'mw.text.jsonEncode: Cannot encode non-finite numbers'
},
{ name = 'json encode, invalid values (function)',
func = mw.text.jsonEncode,
args = { { function () end } },
expect = 'mw.text.jsonEncode: Cannot encode type \'function\''
func = mw.text.jsonEncode,
args = { { function () end } },
expect = 'mw.text.jsonEncode: Cannot encode type \'function\''
},
{ name = 'json encode, invalid values (recursive table)',
func = mw.text.jsonEncode,
args = { { recursiveTable } },
expect = 'mw.text.jsonEncode: Cannot use recursive tables'
func = mw.text.jsonEncode,
args = { { recursiveTable } },
expect = 'mw.text.jsonEncode: Cannot use recursive tables'
},
{ name = 'json encode, invalid values (table with bool key)',
func = mw.text.jsonEncode,
args = { { [true] = 1 } },
expect = 'mw.text.jsonEncode: Cannot use type \'boolean\' as a table key'
func = mw.text.jsonEncode,
args = { { [true] = 1 } },
expect = 'mw.text.jsonEncode: Cannot use type \'boolean\' as a table key'
},
{ name = 'json encode, invalid values (table with function key)',
func = mw.text.jsonEncode,
args = { { [function() end] = 1 } },
expect = 'mw.text.jsonEncode: Cannot use type \'function\' as a table key'
func = mw.text.jsonEncode,
args = { { [function() end] = 1 } },
expect = 'mw.text.jsonEncode: Cannot use type \'function\' as a table key'
},
{ name = 'json encode, invalid values (table with inf key)',
func = mw.text.jsonEncode,
args = { { [1/0] = 1 } },
expect = 'mw.text.jsonEncode: Cannot use \'inf\' as a table key'
func = mw.text.jsonEncode,
args = { { [1/0] = 1 } },
expect = 'mw.text.jsonEncode: Cannot use \'inf\' as a table key'
},
{ name = 'json decode, invalid values (trailing comma)',
func = mw.text.jsonDecode,
args = { '{"x":1,}' },
expect = 'mw.text.jsonDecode: Syntax error'
func = mw.text.jsonDecode,
args = { '{"x":1,}' },
expect = 'mw.text.jsonDecode: Syntax error'
},
{ name = 'json decode, trailing comma with JSON_TRY_FIXING',
func = mw.text.jsonDecode,
args = { '{"x":1,}', mw.text.JSON_TRY_FIXING },
expect = { { x = 1 } }
func = mw.text.jsonDecode,
args = { '{"x":1,}', mw.text.JSON_TRY_FIXING },
expect = { { x = 1 } }
},
}

View file

@ -100,320 +100,320 @@ end
-- Tests
local tests = {
{ name = 'tostring', func = identity, type = 'ToString',
args = { title, title2, title3, title4, title5, title6u, title6s },
expect = {
'Main Page', 'Module:TestFramework', 'interwikiprefix:Module:TestFramework',
'Talk:Has/A/Subpage', 'Not/A/Subpage',
'Module talk:Test Framework', 'Module talk:Test Framework'
}
args = { title, title2, title3, title4, title5, title6u, title6s },
expect = {
'Main Page', 'Module:TestFramework', 'interwikiprefix:Module:TestFramework',
'Talk:Has/A/Subpage', 'Not/A/Subpage',
'Module talk:Test Framework', 'Module talk:Test Framework'
}
},
{ name = 'title.equal', func = mw.title.equals,
args = { title, title },
expect = { true }
args = { title, title },
expect = { true }
},
{ name = 'title.equal (2)', func = mw.title.equals,
args = { title, title_copy },
expect = { true }
args = { title, title_copy },
expect = { true }
},
{ name = 'title.equal (3)', func = mw.title.equals,
args = { title, title2 },
expect = { false }
args = { title, title2 },
expect = { false }
},
{ name = '==', func = function ()
return rawequal( title, title_copy ), title == title, title == title_copy, title == title2
end,
expect = { false, true, true, false }
end,
expect = { false, true, true, false }
},
{ name = 'title.compare', func = mw.title.compare,
args = { title, title },
expect = { 0 }
args = { title, title },
expect = { 0 }
},
{ name = 'title.compare (2)', func = mw.title.compare,
args = { title, title_copy },
expect = { 0 }
args = { title, title_copy },
expect = { 0 }
},
{ name = 'title.compare (3)', func = mw.title.compare,
args = { title, title2 },
expect = { -1 }
args = { title, title2 },
expect = { -1 }
},
{ name = 'title.compare (4)', func = mw.title.compare,
args = { title2, title },
expect = { 1 }
args = { title2, title },
expect = { 1 }
},
{ name = 'title.compare (5)', func = mw.title.compare,
args = { title2, title3 },
expect = { -1 }
args = { title2, title3 },
expect = { -1 }
},
{ name = 'title.compare (6)', func = mw.title.compare,
args = { title6s, title6u },
expect = { 0 }
args = { title6s, title6u },
expect = { 0 }
},
{ name = '<', func = function ()
return title < title, title < title_copy, title < title2, title2 < title
end,
expect = { false, false, true, false }
end,
expect = { false, false, true, false }
},
{ name = '<=', func = function ()
return title <= title, title <= title_copy, title <= title2, title2 <= title
end,
expect = { true, true, true, false }
end,
expect = { true, true, true, false }
},
{ name = 'title.new with namespace', func = mw.title.new, type = 'ToString',
args = { 'TestFramework', 'Module' },
expect = { 'Module:TestFramework' }
args = { 'TestFramework', 'Module' },
expect = { 'Module:TestFramework' }
},
{ name = 'title.new with namespace (2)', func = mw.title.new, type = 'ToString',
args = { 'TestFramework', mw.site.namespaces.Module.id },
expect = { 'Module:TestFramework' }
args = { 'TestFramework', mw.site.namespaces.Module.id },
expect = { 'Module:TestFramework' }
},
{ name = 'title.new with namespace (3)', func = mw.title.new, type = 'ToString',
args = { 'Template:TestFramework', 'Module' },
expect = { 'Template:TestFramework' }
args = { 'Template:TestFramework', 'Module' },
expect = { 'Template:TestFramework' }
},
{ name = 'title.new space normalization', func = test_space_normalization,
args = { ' __ Template __ : __ Test _ Framework __ # _ frag _ frag _ ' },
expect = { 'Template:Test Framework', ' frag frag' }
args = { ' __ Template __ : __ Test _ Framework __ # _ frag _ frag _ ' },
expect = { 'Template:Test Framework', ' frag frag' }
},
{ name = 'title.new with invalid title', func = mw.title.new,
args = { '<bad title>' },
expect = { nil }
args = { '<bad title>' },
expect = { nil }
},
{ name = 'title.new with nonexistent pageid', func = mw.title.new,
args = { -1 },
expect = { nil }
args = { -1 },
expect = { nil }
},
{ name = 'title.new with pageid 0', func = mw.title.new,
args = { 0 },
expect = { nil }
args = { 0 },
expect = { nil }
},
{ name = 'title.new with existing pageid', func = mw.title.new, type = 'ToString',
args = { mw.title.testPageId },
expect = { 'ScribuntoTestPage' }
args = { mw.title.testPageId },
expect = { 'ScribuntoTestPage' }
},
{ name = 'title.makeTitle', func = mw.title.makeTitle, type = 'ToString',
args = { 'Module', 'TestFramework' },
expect = { 'Module:TestFramework' }
args = { 'Module', 'TestFramework' },
expect = { 'Module:TestFramework' }
},
{ name = 'title.makeTitle (2)', func = mw.title.makeTitle, type = 'ToString',
args = { mw.site.namespaces.Module.id, 'TestFramework' },
expect = { 'Module:TestFramework' }
args = { mw.site.namespaces.Module.id, 'TestFramework' },
expect = { 'Module:TestFramework' }
},
{ name = 'title.makeTitle (3)', func = mw.title.makeTitle, type = 'ToString',
args = { mw.site.namespaces.Module.id, 'Template:TestFramework' },
expect = { 'Module:Template:TestFramework' }
args = { mw.site.namespaces.Module.id, 'Template:TestFramework' },
expect = { 'Module:Template:TestFramework' }
},
{ name = '.isLocal', func = prop_foreach,
args = { 'isLocal' },
expect = { true, true, false, true, true, true, true }
args = { 'isLocal' },
expect = { true, true, false, true, true, true, true }
},
{ name = '.isTalkPage', func = prop_foreach,
args = { 'isTalkPage' },
expect = { false, false, false, true, false, true, true }
args = { 'isTalkPage' },
expect = { false, false, false, true, false, true, true }
},
{ name = '.isSubpage', func = prop_foreach,
args = { 'isSubpage' },
expect = { false, false, false, true, false, false, false }
args = { 'isSubpage' },
expect = { false, false, false, true, false, false, false }
},
{ name = '.text', func = prop_foreach,
args = { 'text' },
expect = {
'Main Page', 'TestFramework', 'Module:TestFramework', 'Has/A/Subpage', 'Not/A/Subpage',
'Test Framework', 'Test Framework'
}
args = { 'text' },
expect = {
'Main Page', 'TestFramework', 'Module:TestFramework', 'Has/A/Subpage', 'Not/A/Subpage',
'Test Framework', 'Test Framework'
}
},
{ name = '.prefixedText', func = prop_foreach,
args = { 'prefixedText' },
expect = {
'Main Page', 'Module:TestFramework', 'interwikiprefix:Module:TestFramework',
'Talk:Has/A/Subpage', 'Not/A/Subpage', 'Module talk:Test Framework', 'Module talk:Test Framework',
}
args = { 'prefixedText' },
expect = {
'Main Page', 'Module:TestFramework', 'interwikiprefix:Module:TestFramework',
'Talk:Has/A/Subpage', 'Not/A/Subpage', 'Module talk:Test Framework', 'Module talk:Test Framework',
}
},
{ name = '.rootText', func = prop_foreach,
args = { 'rootText' },
expect = {
'Main Page', 'TestFramework', 'Module:TestFramework', 'Has', 'Not/A/Subpage',
'Test Framework', 'Test Framework'
}
args = { 'rootText' },
expect = {
'Main Page', 'TestFramework', 'Module:TestFramework', 'Has', 'Not/A/Subpage',
'Test Framework', 'Test Framework'
}
},
{ name = '.baseText', func = prop_foreach,
args = { 'baseText' },
expect = {
'Main Page', 'TestFramework', 'Module:TestFramework', 'Has/A', 'Not/A/Subpage',
'Test Framework', 'Test Framework'
}
args = { 'baseText' },
expect = {
'Main Page', 'TestFramework', 'Module:TestFramework', 'Has/A', 'Not/A/Subpage',
'Test Framework', 'Test Framework'
}
},
{ name = '.subpageText', func = prop_foreach,
args = { 'subpageText' },
expect = {
'Main Page', 'TestFramework', 'Module:TestFramework', 'Subpage', 'Not/A/Subpage',
'Test Framework', 'Test Framework'
}
args = { 'subpageText' },
expect = {
'Main Page', 'TestFramework', 'Module:TestFramework', 'Subpage', 'Not/A/Subpage',
'Test Framework', 'Test Framework'
}
},
{ name = '.fullText', func = prop_foreach,
args = { 'fullText' },
expect = {
'Main Page', 'Module:TestFramework', 'interwikiprefix:Module:TestFramework',
'Talk:Has/A/Subpage#frag', 'Not/A/Subpage',
'Module talk:Test Framework# frag frag', 'Module talk:Test Framework# frag frag'
}
args = { 'fullText' },
expect = {
'Main Page', 'Module:TestFramework', 'interwikiprefix:Module:TestFramework',
'Talk:Has/A/Subpage#frag', 'Not/A/Subpage',
'Module talk:Test Framework# frag frag', 'Module talk:Test Framework# frag frag'
}
},
{ name = '.subjectNsText', func = prop_foreach,
args = { 'subjectNsText' },
expect = { '', 'Module', '', '', '', 'Module', 'Module' }
args = { 'subjectNsText' },
expect = { '', 'Module', '', '', '', 'Module', 'Module' }
},
{ name = '.fragment', func = prop_foreach,
args = { 'fragment' },
expect = { '', '', '', 'frag', '', ' frag frag', ' frag frag' }
args = { 'fragment' },
expect = { '', '', '', 'frag', '', ' frag frag', ' frag frag' }
},
{ name = '.interwiki', func = prop_foreach,
args = { 'interwiki' },
expect = { '', '', 'interwikiprefix', '', '', '', '' }
args = { 'interwiki' },
expect = { '', '', 'interwikiprefix', '', '', '', '' }
},
{ name = '.namespace', func = prop_foreach,
args = { 'namespace' },
expect = {
0, mw.site.namespaces.Module.id, 0, 1, 0,
mw.site.namespaces.Module_talk.id, mw.site.namespaces.Module_talk.id
}
args = { 'namespace' },
expect = {
0, mw.site.namespaces.Module.id, 0, 1, 0,
mw.site.namespaces.Module_talk.id, mw.site.namespaces.Module_talk.id
}
},
{ name = '.protectionLevels', func = prop_foreach,
args = { 'protectionLevels' },
expect = {
{ edit = {}, move = {} }, { edit = { 'sysop', 'bogus' }, move = { 'sysop', 'bogus' } },
{}, { create = { 'sysop' } }, { edit = { 'autoconfirmed' }, move = { 'sysop' } },
{ edit = {}, move = { 'sysop' } }, { edit = {}, move = { 'sysop' } }
}
args = { 'protectionLevels' },
expect = {
{ edit = {}, move = {} }, { edit = { 'sysop', 'bogus' }, move = { 'sysop', 'bogus' } },
{}, { create = { 'sysop' } }, { edit = { 'autoconfirmed' }, move = { 'sysop' } },
{ edit = {}, move = { 'sysop' } }, { edit = {}, move = { 'sysop' } }
}
},
{ name = '.cascadingProtection', func = prop_foreach,
args = { 'cascadingProtection' },
expect = {
{ restrictions = { edit = { 'sysop' } }, sources = { 'Lockbox', 'Lockbox2' } }, { restrictions = {}, sources = {} },
{ restrictions = {}, sources = {} }, { restrictions = {}, sources = {} }, { restrictions = {}, sources = {} },
{ restrictions = {}, sources = {} }, { restrictions = {}, sources = {} }
}
args = { 'cascadingProtection' },
expect = {
{ restrictions = { edit = { 'sysop' } }, sources = { 'Lockbox', 'Lockbox2' } }, { restrictions = {}, sources = {} },
{ restrictions = {}, sources = {} }, { restrictions = {}, sources = {} }, { restrictions = {}, sources = {} },
{ restrictions = {}, sources = {} }, { restrictions = {}, sources = {} }
}
},
{ name = '.inNamespace()', func = func_foreach,
args = { 'inNamespace', 'Module' },
expect = { false, true, false, false, false, false, false }
args = { 'inNamespace', 'Module' },
expect = { false, true, false, false, false, false, false }
},
{ name = '.inNamespace() 2', func = func_foreach,
args = { 'inNamespace', mw.site.namespaces.Module.id },
expect = { false, true, false, false, false, false, false }
args = { 'inNamespace', mw.site.namespaces.Module.id },
expect = { false, true, false, false, false, false, false }
},
{ name = '.inNamespaces()', func = func_foreach,
args = { 'inNamespaces', 0, 1 },
expect = { true, false, true, true, true, false, false }
args = { 'inNamespaces', 0, 1 },
expect = { true, false, true, true, true, false, false }
},
{ name = '.hasSubjectNamespace()', func = func_foreach,
args = { 'hasSubjectNamespace', 0 },
expect = { true, false, true, true, true, false, false }
args = { 'hasSubjectNamespace', 0 },
expect = { true, false, true, true, true, false, false }
},
{ name = '.isSubpageOf() 1', func = func_foreach,
args = { 'isSubpageOf', title },
expect = { false, false, false, false, false, false, false }
args = { 'isSubpageOf', title },
expect = { false, false, false, false, false, false, false }
},
{ name = '.isSubpageOf() 2', func = func_foreach,
args = { 'isSubpageOf', title4p },
expect = { false, false, false, true, false, false, false }
args = { 'isSubpageOf', title4p },
expect = { false, false, false, true, false, false, false }
},
{ name = '.partialUrl()', func = func_foreach,
args = { 'partialUrl' },
expect = {
'Main_Page', 'TestFramework', 'Module:TestFramework', 'Has/A/Subpage', 'Not/A/Subpage',
'Test_Framework', 'Test_Framework'
}
args = { 'partialUrl' },
expect = {
'Main_Page', 'TestFramework', 'Module:TestFramework', 'Has/A/Subpage', 'Not/A/Subpage',
'Test_Framework', 'Test_Framework'
}
},
{ name = '.fullUrl()', func = func_foreach,
args = { 'fullUrl' },
expect = {
'//wiki.local/wiki/Main_Page',
'//wiki.local/wiki/Module:TestFramework',
'//test.wikipedia.org/wiki/Module:TestFramework',
'//wiki.local/wiki/Talk:Has/A/Subpage#frag',
'//wiki.local/wiki/Not/A/Subpage',
'//wiki.local/wiki/Module_talk:Test_Framework#_frag_frag',
'//wiki.local/wiki/Module_talk:Test_Framework#_frag_frag',
}
args = { 'fullUrl' },
expect = {
'//wiki.local/wiki/Main_Page',
'//wiki.local/wiki/Module:TestFramework',
'//test.wikipedia.org/wiki/Module:TestFramework',
'//wiki.local/wiki/Talk:Has/A/Subpage#frag',
'//wiki.local/wiki/Not/A/Subpage',
'//wiki.local/wiki/Module_talk:Test_Framework#_frag_frag',
'//wiki.local/wiki/Module_talk:Test_Framework#_frag_frag',
}
},
{ name = '.fullUrl() 2', func = func_foreach,
args = { 'fullUrl', { action = 'test' } },
expect = {
'//wiki.local/w/index.php?title=Main_Page&action=test',
'//wiki.local/w/index.php?title=Module:TestFramework&action=test',
'//test.wikipedia.org/wiki/Module:TestFramework?action=test',
'//wiki.local/w/index.php?title=Talk:Has/A/Subpage&action=test#frag',
'//wiki.local/w/index.php?title=Not/A/Subpage&action=test',
'//wiki.local/w/index.php?title=Module_talk:Test_Framework&action=test#_frag_frag',
'//wiki.local/w/index.php?title=Module_talk:Test_Framework&action=test#_frag_frag',
}
args = { 'fullUrl', { action = 'test' } },
expect = {
'//wiki.local/w/index.php?title=Main_Page&action=test',
'//wiki.local/w/index.php?title=Module:TestFramework&action=test',
'//test.wikipedia.org/wiki/Module:TestFramework?action=test',
'//wiki.local/w/index.php?title=Talk:Has/A/Subpage&action=test#frag',
'//wiki.local/w/index.php?title=Not/A/Subpage&action=test',
'//wiki.local/w/index.php?title=Module_talk:Test_Framework&action=test#_frag_frag',
'//wiki.local/w/index.php?title=Module_talk:Test_Framework&action=test#_frag_frag',
}
},
{ name = '.fullUrl() 3', func = func_foreach,
args = { 'fullUrl', nil, 'http' },
expect = {
'http://wiki.local/wiki/Main_Page',
'http://wiki.local/wiki/Module:TestFramework',
'http://test.wikipedia.org/wiki/Module:TestFramework',
'http://wiki.local/wiki/Talk:Has/A/Subpage#frag',
'http://wiki.local/wiki/Not/A/Subpage',
'http://wiki.local/wiki/Module_talk:Test_Framework#_frag_frag',
'http://wiki.local/wiki/Module_talk:Test_Framework#_frag_frag',
}
args = { 'fullUrl', nil, 'http' },
expect = {
'http://wiki.local/wiki/Main_Page',
'http://wiki.local/wiki/Module:TestFramework',
'http://test.wikipedia.org/wiki/Module:TestFramework',
'http://wiki.local/wiki/Talk:Has/A/Subpage#frag',
'http://wiki.local/wiki/Not/A/Subpage',
'http://wiki.local/wiki/Module_talk:Test_Framework#_frag_frag',
'http://wiki.local/wiki/Module_talk:Test_Framework#_frag_frag',
}
},
{ name = '.localUrl()', func = func_foreach,
args = { 'localUrl' },
expect = {
'/wiki/Main_Page',
'/wiki/Module:TestFramework',
'//test.wikipedia.org/wiki/Module:TestFramework',
'/wiki/Talk:Has/A/Subpage',
'/wiki/Not/A/Subpage',
'/wiki/Module_talk:Test_Framework',
'/wiki/Module_talk:Test_Framework',
}
args = { 'localUrl' },
expect = {
'/wiki/Main_Page',
'/wiki/Module:TestFramework',
'//test.wikipedia.org/wiki/Module:TestFramework',
'/wiki/Talk:Has/A/Subpage',
'/wiki/Not/A/Subpage',
'/wiki/Module_talk:Test_Framework',
'/wiki/Module_talk:Test_Framework',
}
},
{ name = '.canonicalUrl()', func = func_foreach,
args = { 'canonicalUrl' },
expect = {
'http://wiki.local/wiki/Main_Page',
'http://wiki.local/wiki/Module:TestFramework',
'http://test.wikipedia.org/wiki/Module:TestFramework',
'http://wiki.local/wiki/Talk:Has/A/Subpage#frag',
'http://wiki.local/wiki/Not/A/Subpage',
'http://wiki.local/wiki/Module_talk:Test_Framework#_frag_frag',
'http://wiki.local/wiki/Module_talk:Test_Framework#_frag_frag',
}
args = { 'canonicalUrl' },
expect = {
'http://wiki.local/wiki/Main_Page',
'http://wiki.local/wiki/Module:TestFramework',
'http://test.wikipedia.org/wiki/Module:TestFramework',
'http://wiki.local/wiki/Talk:Has/A/Subpage#frag',
'http://wiki.local/wiki/Not/A/Subpage',
'http://wiki.local/wiki/Module_talk:Test_Framework#_frag_frag',
'http://wiki.local/wiki/Module_talk:Test_Framework#_frag_frag',
}
},
{ name = '.getContent()', func = test_getContent,
expect = {
'{{int:mainpage}}<includeonly>...</includeonly><noinclude>...</noinclude>',
nil,
}
expect = {
'{{int:mainpage}}<includeonly>...</includeonly><noinclude>...</noinclude>',
nil,
}
},
{ name = '.redirectTarget', func = test_redirectTarget, type = 'ToString',
expect = { 'ScribuntoTestTarget', false, false }
expect = { 'ScribuntoTestTarget', false, false }
},
{ name = 'not quite too many expensive functions', func = test_expensive_10,
expect = { 'did not error' }
expect = { 'did not error' }
},
{ name = 'too many expensive functions', func = test_expensive_11,
expect = 'too many expensive function calls'
expect = 'too many expensive function calls'
},
{ name = "previously cached titles shouldn't count as expensive", func = test_expensive_cached,
expect = { 'did not error' }
expect = { 'did not error' }
},
{ name = "inexpensive actions shouldn't count as expensive", func = test_inexpensive,
expect = { 'did not error' }
expect = { 'did not error' }
},
{ name = "fragments don't leak via getCurrentTitle()", func = test_getCurrentTitle_fragment,
expect = { '' }
expect = { '' }
},
}

View file

@ -14,126 +14,126 @@ end
-- Tests
local tests = {
{ name = 'uri.encode', func = mw.uri.encode,
args = { '__foo b\195\161r + baz__' },
expect = { '__foo+b%C3%A1r+%2B+baz__' }
args = { '__foo b\195\161r + baz__' },
expect = { '__foo+b%C3%A1r+%2B+baz__' }
},
{ name = 'uri.encode QUERY', func = mw.uri.encode,
args = { '__foo b\195\161r + /baz/__', 'QUERY' },
expect = { '__foo+b%C3%A1r+%2B+%2Fbaz%2F__' }
args = { '__foo b\195\161r + /baz/__', 'QUERY' },
expect = { '__foo+b%C3%A1r+%2B+%2Fbaz%2F__' }
},
{ name = 'uri.encode PATH', func = mw.uri.encode,
args = { '__foo b\195\161r + /baz/__', 'PATH' },
expect = { '__foo%20b%C3%A1r%20%2B%20%2Fbaz%2F__' }
args = { '__foo b\195\161r + /baz/__', 'PATH' },
expect = { '__foo%20b%C3%A1r%20%2B%20%2Fbaz%2F__' }
},
{ name = 'uri.encode WIKI', func = mw.uri.encode,
args = { '__foo b\195\161r + /baz/__', 'WIKI' },
expect = { '__foo_b%C3%A1r_%2B_/baz/__' }
args = { '__foo b\195\161r + /baz/__', 'WIKI' },
expect = { '__foo_b%C3%A1r_%2B_/baz/__' }
},
{ name = 'uri.decode', func = mw.uri.decode,
args = { '__foo+b%C3%A1r+%2B+baz__' },
expect = { '__foo b\195\161r + baz__' }
args = { '__foo+b%C3%A1r+%2B+baz__' },
expect = { '__foo b\195\161r + baz__' }
},
{ name = 'uri.decode QUERY', func = mw.uri.decode,
args = { '__foo+b%C3%A1r+%2B+baz__', 'QUERY' },
expect = { '__foo b\195\161r + baz__' }
args = { '__foo+b%C3%A1r+%2B+baz__', 'QUERY' },
expect = { '__foo b\195\161r + baz__' }
},
{ name = 'uri.decode PATH', func = mw.uri.decode,
args = { '__foo+b%C3%A1r+%2B+baz__', 'PATH' },
expect = { '__foo+b\195\161r+++baz__' }
args = { '__foo+b%C3%A1r+%2B+baz__', 'PATH' },
expect = { '__foo+b\195\161r+++baz__' }
},
{ name = 'uri.decode WIKI', func = mw.uri.decode,
args = { '__foo+b%C3%A1r+%2B+baz__', 'WIKI' },
expect = { ' foo+b\195\161r+++baz ' }
args = { '__foo+b%C3%A1r+%2B+baz__', 'WIKI' },
expect = { ' foo+b\195\161r+++baz ' }
},
{ name = 'uri.anchorEncode', func = mw.uri.anchorEncode,
args = { '__foo b\195\161r__' },
expect = { 'foo_b.C3.A1r' }
args = { '__foo b\195\161r__' },
expect = { 'foo_b.C3.A1r' }
},
{ name = 'uri.new', func = test_new,
args = { 'http://www.example.com/test?foo=1&bar&baz=1&baz=2#fragment' },
expect = {
{
protocol = 'http',
host = 'www.example.com',
hostPort = 'www.example.com',
authority = 'www.example.com',
path = '/test',
query = {
foo = '1',
bar = false,
baz = { '1', '2' },
},
queryString = 'foo=1&bar&baz=1&baz=2',
fragment = 'fragment',
relativePath = '/test?foo=1&bar&baz=1&baz=2#fragment',
},
},
args = { 'http://www.example.com/test?foo=1&bar&baz=1&baz=2#fragment' },
expect = {
{
protocol = 'http',
host = 'www.example.com',
hostPort = 'www.example.com',
authority = 'www.example.com',
path = '/test',
query = {
foo = '1',
bar = false,
baz = { '1', '2' },
},
queryString = 'foo=1&bar&baz=1&baz=2',
fragment = 'fragment',
relativePath = '/test?foo=1&bar&baz=1&baz=2#fragment',
},
},
},
{ name = 'uri.new', func = mw.uri.new, type = 'ToString',
args = { 'http://www.example.com/test?foo=1&bar&baz=1&baz=2#fragment' },
expect = { 'http://www.example.com/test?foo=1&bar&baz=1&baz=2#fragment' },
args = { 'http://www.example.com/test?foo=1&bar&baz=1&baz=2#fragment' },
expect = { 'http://www.example.com/test?foo=1&bar&baz=1&baz=2#fragment' },
},
{ name = 'uri.localUrl( Example )', func = mw.uri.localUrl, type = 'ToString',
args = { 'Example' },
expect = { '/wiki/Example' },
args = { 'Example' },
expect = { '/wiki/Example' },
},
{ name = 'uri.localUrl( Example, string )', func = mw.uri.localUrl, type = 'ToString',
args = { 'Example', 'action=edit' },
expect = { '/w/index.php?title=Example&action=edit' },
args = { 'Example', 'action=edit' },
expect = { '/w/index.php?title=Example&action=edit' },
},
{ name = 'uri.localUrl( Example, table )', func = mw.uri.localUrl, type = 'ToString',
args = { 'Example', { action = 'edit' } },
expect = { '/w/index.php?title=Example&action=edit' },
args = { 'Example', { action = 'edit' } },
expect = { '/w/index.php?title=Example&action=edit' },
},
{ name = 'uri.fullUrl( Example )', func = mw.uri.fullUrl, type = 'ToString',
args = { 'Example' },
expect = { '//wiki.local/wiki/Example' },
args = { 'Example' },
expect = { '//wiki.local/wiki/Example' },
},
{ name = 'uri.fullUrl( Example, string )', func = mw.uri.fullUrl, type = 'ToString',
args = { 'Example', 'action=edit' },
expect = { '//wiki.local/w/index.php?title=Example&action=edit' },
args = { 'Example', 'action=edit' },
expect = { '//wiki.local/w/index.php?title=Example&action=edit' },
},
{ name = 'uri.fullUrl( Example, table )', func = mw.uri.fullUrl, type = 'ToString',
args = { 'Example', { action = 'edit' } },
expect = { '//wiki.local/w/index.php?title=Example&action=edit' },
args = { 'Example', { action = 'edit' } },
expect = { '//wiki.local/w/index.php?title=Example&action=edit' },
},
{ name = 'uri.canonicalUrl( Example )', func = mw.uri.canonicalUrl, type = 'ToString',
args = { 'Example' },
expect = { 'http://wiki.local/wiki/Example' },
args = { 'Example' },
expect = { 'http://wiki.local/wiki/Example' },
},
{ name = 'uri.canonicalUrl( Example, string )', func = mw.uri.canonicalUrl, type = 'ToString',
args = { 'Example', 'action=edit' },
expect = { 'http://wiki.local/w/index.php?title=Example&action=edit' },
args = { 'Example', 'action=edit' },
expect = { 'http://wiki.local/w/index.php?title=Example&action=edit' },
},
{ name = 'uri.canonicalUrl( Example, table )', func = mw.uri.canonicalUrl, type = 'ToString',
args = { 'Example', { action = 'edit' } },
expect = { 'http://wiki.local/w/index.php?title=Example&action=edit' },
args = { 'Example', { action = 'edit' } },
expect = { 'http://wiki.local/w/index.php?title=Example&action=edit' },
},
{ name = 'uri.new with empty query string', func = mw.uri.new, type = 'ToString',
args = { 'http://wiki.local/w/index.php?' },
expect = { 'http://wiki.local/w/index.php?' },
args = { 'http://wiki.local/w/index.php?' },
expect = { 'http://wiki.local/w/index.php?' },
},
{ name = 'uri.new with empty fragment', func = mw.uri.new, type = 'ToString',
args = { 'http://wiki.local/w/index.php#' },
expect = { 'http://wiki.local/w/index.php#' },
args = { 'http://wiki.local/w/index.php#' },
expect = { 'http://wiki.local/w/index.php#' },
},
{ name = 'uri.new with IPv6', func = mw.uri.new, type = 'ToString',
args = { 'http://[2001:db8::]' },
expect = { 'http://[2001:db8::]' },
args = { 'http://[2001:db8::]' },
expect = { 'http://[2001:db8::]' },
},
{ name = 'uri.new with IPv6 and port', func = mw.uri.new, type = 'ToString',
args = { 'http://[2001:db8::]:80' },
expect = { 'http://[2001:db8::]:80' },
args = { 'http://[2001:db8::]:80' },
expect = { 'http://[2001:db8::]:80' },
},
}
@ -175,8 +175,8 @@ while not bits[8] do
url = table.concat( url, '' )
tests[#tests+1] = { name = 'uri.new (' .. ct .. ')', func = mw.uri.new, type = 'ToString',
args = { url },
expect = { url },
args = { url },
expect = { url },
}
ct = ct + 1

File diff suppressed because it is too large Load diff

View file

@ -10,9 +10,9 @@ end
return testframework.getTestProvider( {
{ name = 'setfenv invalid level', func = setfenv1,
expect = "bad argument #1 to 'old_getfenv' (invalid level)",
expect = "bad argument #1 to 'old_getfenv' (invalid level)",
},
{ name = 'getfenv invalid level', func = getfenv1,
expect = "bad argument #1 to 'old_getfenv' (invalid level)",
expect = "bad argument #1 to 'old_getfenv' (invalid level)",
},
} )

View file

@ -20,53 +20,53 @@ end
return testframework.getTestProvider( {
{ name = 'setfenv on a C function', func = setfenv1,
expect = "'setfenv' cannot set the requested environment, it is protected",
expect = "'setfenv' cannot set the requested environment, it is protected",
},
{ name = 'getfenv on a C function', func = getfenv1,
expect = { nil },
expect = { nil },
},
{ name = 'Invalid array key (table)', func = mw.var_export,
args = { { [{}] = 1 } },
expect = 'Cannot use table as an array key when passing data from Lua to PHP',
args = { { [{}] = 1 } },
expect = 'Cannot use table as an array key when passing data from Lua to PHP',
},
{ name = 'Invalid array key (boolean)', func = mw.var_export,
args = { { [true] = 1 } },
expect = 'Cannot use boolean as an array key when passing data from Lua to PHP',
args = { { [true] = 1 } },
expect = 'Cannot use boolean as an array key when passing data from Lua to PHP',
},
{ name = 'Invalid array key (function)', func = mw.var_export,
args = { { [tostring] = 1 } },
expect = 'Cannot use function as an array key when passing data from Lua to PHP',
args = { { [tostring] = 1 } },
expect = 'Cannot use function as an array key when passing data from Lua to PHP',
},
{ name = 'Unusual array key (float)', func = mw.var_export,
args = { { [1.5] = 1 } },
expect = { "array ( '1.5' => 1, )" }
args = { { [1.5] = 1 } },
expect = { "array ( '1.5' => 1, )" }
},
{ name = 'Unusual array key (inf)', func = mw.var_export,
args = { { [math.huge] = 1 } },
expect = { "array ( 'inf' => 1, )" }
args = { { [math.huge] = 1 } },
expect = { "array ( 'inf' => 1, )" }
},
{ name = 'Unusual array key ("00")', func = mw.var_export,
args = { { ["00"] = "zero zero" } },
expect = { "array ( '00' => 'zero zero', )" }
args = { { ["00"] = "zero zero" } },
expect = { "array ( '00' => 'zero zero', )" }
},
{ name = 'Unusual array key ("0.0")', func = mw.var_export,
args = { { ["0.0"] = "zero . zero" } },
expect = { "array ( '0.0' => 'zero . zero', )" }
args = { { ["0.0"] = "zero . zero" } },
expect = { "array ( '0.0' => 'zero . zero', )" }
},
{ name = 'Unusual array key ("01")', func = mw.var_export,
args = { { ["01"] = "zero one" } },
expect = { "array ( '01' => 'zero one', )" }
args = { { ["01"] = "zero one" } },
expect = { "array ( '01' => 'zero one', )" }
},
{ name = 'Unusual array key ("-9223372036854775808")', func = mw.var_export,
args = { { ["-9223372036854775808"] = "min" } },
expect = { "array ( -9223372036854775808 => 'min', )" }
args = { { ["-9223372036854775808"] = "min" } },
expect = { "array ( -9223372036854775808 => 'min', )" }
},
{ name = 'Unusual array key (-9223372036854775808)', func = mw.var_export,
args = { { [-9223372036854775808] = "min" } },
expect = { "array ( -9223372036854775808 => 'min', )" }
args = { { [-9223372036854775808] = "min" } },
expect = { "array ( -9223372036854775808 => 'min', )" }
},
{ name = 'Unusual array key ("-9223372036854775809")', func = mw.var_export,
args = { { ["-9223372036854775809"] = "min - 1" } },
expect = { "array ( '-9223372036854775809' => 'min - 1', )" }
args = { { ["-9223372036854775809"] = "min - 1" } },
expect = { "array ( '-9223372036854775809' => 'min - 1', )" }
},
} )