summaryrefslogtreecommitdiff
path: root/test/cli/visualize/test.lua
blob: c9722c32b7b03e5778724889be0df4dbb851f7ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
local visualize = require 'cli.visualize'

local testDataDir = 'test/cli/visualize/testdata/'

local function TestVisualize(fileName)
	local inputFile = testDataDir .. fileName .. '.txt'
	local outputFile = testDataDir .. fileName .. '-expected.txt'
	local output = ''
	local writer = {}
	function writer:write(text)
		output = output .. text
	end
	visualize.visualizeAst(io.open(inputFile):read('a'), writer)
	local expectedOutput = io.open(outputFile):read('a')
	if expectedOutput ~= output then
		-- uncomment this to update reference output
		--io.open(outputFile, "w+"):write(output):close()
		error('output mismatch for test file ' .. inputFile)
	end
end

TestVisualize('all-types')
TestVisualize('shorten-names')