Module:User:JohnC5/Sandbox3

Text without index [1]------------------------------
getn output: 0
# output: 0
Add index [1]------------------------------
getn output: 3
# output: 3
1 foo
2 bar
3 baz


2 foo
6 bar
9 baz


local export = {}

local U = mw.ustring.char

local m_table = require('Module:table')

local acute = U(0x301) -- combining acute

local super_nums = {
	[1] = '¹', [2] = '²', [3] = '³', [4] = '⁴', [5] = '⁵',
	[6] = '⁶', [7] = '⁷', [8] = '⁸', [9] = '⁹', [0] = '⁰',
}

function export.to_super(frame)
    local annotation =  mw.ustring.gsub(tostring(frame.args[1]), ".", super_nums)
    return annotation
end

function export.test_pattern(frame)
    local annotation =  mw.ustring.gsub(tostring(frame.args[1]), tostring(frame.args[2]), tostring(frame.args[3]))
    return annotation
end

function export.show()
	--test table creation
	local a = {
		[2] = "bar",
		[3] = "baz",
		[5] = "quux",
	}
	local output = {}
	
	table.insert(output, "Text without index [1]------------------------------")
	table.insert(output, "getn output:     " .. table.getn(a))
	table.insert(output, "# output:     " .. #a)
	
	-- ipairs only iterates over the array until it arrives at a nil.
	for i, j in ipairs(a) do
		table.insert(output, i .. "     " .. j)	
	end
	
	--this behavior is weird
	table.insert(output, "Add index [1]------------------------------")
	a[1] = "foo"
	table.insert(output, "getn output:     " .. table.getn(a))
	table.insert(output, "# output:     " .. #a)
	
	-- ipairs only iterates over the array until it arrives at a nil.
	for i, j in ipairs(a) do
		table.insert(output, i .. "     " .. j)	
	end
	
	return table.concat(output, "<br/>")
end

function export.test_sort()
	local foo, bar = { [2] = "foo", [6] = "bar", [9] = "baz" }, {}
	for i, j in m_table.sparseIpairs(foo) do table.insert(bar, i .. " " .. j) end
	return table.concat(bar, "<br/>")
end

function export.test_fetch()
	local page = mw.title.new('api.php')
	return page:localUrl('action=parse&text={{:friend}}__TOC__&prop=sections&format=json')
end

return export