Module:Sandbox/Nyoron/anyToString/testcases

local p = {}

local m = require('Module:Sandbox/Nyoron/anyToString')

-- Test data local var_nil          = nil local var_boolean_true = true local var_boolean_false = false local var_string       = "string-text" local var_number       = 1234.567 local var_function1 = function return "return of function1"  end local var_function2 = function return "return of function2"  end local var_function3 = function return "return of function3"  end local var_function4 = function return "return of function4"  end

local var_table8        = { } local var_table7        = { } local var_table6        = { } local var_table5        = { } local var_table4        = { [1] = true, [2] = false, [3] = "t5 value for key string", [4] = 5678,    [5]  = var_function1, [6] = var_function2, [7] = var_function3, [8] = var_function4, [9] = var_table6, ["var_table1"] = var_table1, ["var_table2"] = var_table2, ["var_table3"] = var_table3, ["var_table4"] = var_table4, -- var_table4 is not defined at this point. same as nil. ["var_table5"] = var_table5, ["var_table6"] = var_table6, ["var_table7"] = var_table7, ["var_table8"] = var_table8, }

local var_table3        = { [true]          = true, [false]         = false, ["string"]      = "t3 value for key string", [3456]          = 3456,    [var_function2]   = var_function2, [var_function3]  = var_function3, [var_function4]  = var_function4, ["var_function2"] = var_function2, ["var_function3"] = var_function3, ["var_function4"] = var_function4, ["var_table4"]  = var_table4, [var_table4]    = "t3 value for key table 4", [var_table5]    = "t3 value for key table 5", [var_table6]    = "t3 value for key table 6", [var_table7]    = "t3 value for key table 7", [var_table8]    = "t3 value for key table 8", }

local var_table2        = { ["var_nil"]          = nil,  -- setting nil value removes the key ["var_boolean_true"] = true, ["var_boolean_false"] = false, ["var_string"]       = "t2 value for key string", ["var_number"]       = 2345, ["var_function2"]     = var_function2, [var_function2]       = var_function2, ["var_table3"]       = var_table3, [var_table3]         = "t2 value for key table 3", }

local var_table1        = { [1] = true, [2] = false, [3] = "t1 value for key string", [4] = 1234,    [5]  = var_function, [6] = var_table1, -- var_table1 is not defined at this point. same as nil. [7] = var_table2, [8] = var_table3, [9] = var_table4, [10] = var_table5, --   [nil]          = "t1 value for key nil",  -- nil key is invalid in Lua [true]        = "t1 value for key boolean true", [false]       = "t1 value for key boolean false", ["string"]    = "t1 value for key string", [1234]        = "t1 value for key number", [var_function1] = "t1 value for key function1", [var_table2]  = "t1 value for key table 2", ["var_table2"] = var_table2, }

p.run_tests = function(frame) local result = '' result = " " result = mw.ustring.format("%s%s ",result,m.anyToString(var_nil)) result = mw.ustring.format("%s%s ",result,m.anyToString(var_boolean_true)) result = mw.ustring.format("%s%s ",result,m.anyToString(var_boolean_false)) result = mw.ustring.format("%s%s ",result,m.anyToString(var_string)) result = mw.ustring.format("%s%s ",result,m.anyToString(var_number)) result = mw.ustring.format("%s%s ",result,m.anyToString(var_function))

result = mw.ustring.format("%s%s ",result,m.anyToString(var_table1, false, 0, 4)) result = mw.ustring.format("%s%s ",result,m.anyToString(var_table1, true, 4, 4)) result = mw.ustring.format("%s%s ",result,mw.dumpObject(var_table1))

-- https://en.wikipedia.org/wiki/MediaWiki:Titleblacklist result = mw.ustring.format("%s%s ",result,m.anyToString( mw.ext.TitleBlacklist.test('move','Module:Sandbox/にょろん/REVISIONUSER'))) result = mw.ustring.format("%s%s ",result,m.anyToString( mw.ext.TitleBlacklist.test('move','Module:Sandbox/にょろん/anyToString'))) -- Regarding new-account, see https://meta.wikimedia.org/wiki/Title_blacklist result = mw.ustring.format("%s%s ",result,m.anyToString( mw.ext.TitleBlacklist.test('new-account','AIDS12349876')))

result = result .. " "   return result end

return p