From 50fefc6d3f292763386322592965f9003f1bcf71 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Wed, 31 Jul 2019 00:10:12 -0300 Subject: Fix handling of empty files --- dirtycompiler.lua | 1 + testc.lua | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/dirtycompiler.lua b/dirtycompiler.lua index 3ece694..4d61538 100644 --- a/dirtycompiler.lua +++ b/dirtycompiler.lua @@ -122,6 +122,7 @@ defs[FINISH] = finish defs[parser.EOZ] = function(state, token) local results = state.results + if not results then return {} end -- empty, don't waste time processing unnecessary things -- flip results around local len = results.n for i=1, len do diff --git a/testc.lua b/testc.lua index 8abdcd5..eb864e1 100644 --- a/testc.lua +++ b/testc.lua @@ -23,16 +23,19 @@ end local cratera = require "dirtycratera" --- first test: does it handle lua code properly? -assert(printr(cratera.load(io.lines("dirtycompiler.lua", "*a")())))() +-- first test: does it handle empty files properly? +assert(printr(cratera.load("")))() + +-- second test: does it handle lua code properly? +assert(printr(cratera.load(io.open("dirtycompiler.lua"):read("*a"))))() print("-----------------------------------------------------------------------------------------------------------------------") print(table.concat(collect)) collect = {} --- second test: does it handle cratera tests properly? -assert(printr(cratera.load(io.lines("tests.cratera", "*a")())))() +-- third test: does it handle cratera tests properly? +assert(printr(cratera.load(io.open("tests.cratera"):read("*a"))))() print("-----------------------------------------------------------------------------------------------------------------------") print(table.concat(collect)) -- cgit 1.4.1