aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2017-03-13 15:38:23 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2017-03-13 15:38:23 -0400
commitf687e914e07094b1eef11d84dab2e069a9298df5 (patch)
treed74600b3afebd028689baa1c306432fac5030f9f /test
parentf96040eb138efdc8f13521bade5bf8bd299bb9fb (diff)
downloadglum-f687e914e07094b1eef11d84dab2e069a9298df5.tar.gz
glum-f687e914e07094b1eef11d84dab2e069a9298df5.tar.bz2
glum-f687e914e07094b1eef11d84dab2e069a9298df5.zip
Started updateing unit tests
Diffstat (limited to 'test')
-rw-r--r--test/glum_spec.lua71
-rw-r--r--test/glum_test.lua21
-rw-r--r--test/tests/call.lua4
-rw-r--r--test/tests/valid_snippits/call.lua22
-rw-r--r--test/tests/valid_snippits/forinloop.lua10
-rw-r--r--test/tests/valid_snippits/fornumloop.lua10
-rw-r--r--test/tests/valid_snippits/invoke.lua12
-rw-r--r--test/tests/valid_snippits/string.lua8
8 files changed, 122 insertions, 36 deletions
diff --git a/test/glum_spec.lua b/test/glum_spec.lua
index e4c5749..3cee0ab 100644
--- a/test/glum_spec.lua
+++ b/test/glum_spec.lua
@@ -1,31 +1,50 @@
+--Tests glum to make sure it works correctly!
+
+--Come config stuff, you can edit this to your likeing
+local config = {
+ lscmd = "ls -a \"%s\"", -- List directory contents command
+ ignoredirs = {".",".."} -- List of directories that appear in the above command that we should ignore
+}
+
local tests = {}
+describe("Finding tests",function()
+ --A function that looks for files in a directory, you might need to rewrite this for windows
+ local function scan_paths(path,tbl)
+ local pfile = io.popen(string.format(config.lscmd,path))
+ local pdata = pfile:read("*all")
+ for filename in string.gmatch(pdata,"[^\n]+") do
+ if filename:find("%.lua$") then --It's a file, include it on the path
+ tbl[path .. "/" .. filename] = true
+ else
+ local shouldignore = false
+
+ for k,v in pairs(config.ignoredirs) do
+ if filename == v then
+ shouldignore = true
+ break
+ end
+ end
+
+ if not shouldignore then
+ scan_paths(path .. "/" .. filename,tbl)
+ end
+ end
+ end
+ end
+
+ local t = {}
+ scan_paths("./tests",t)
+ tests = t
+end)
-describe("Initializeing tests",function()
- local testnames = {
- {"forinloop.lua", "forin loops"},
- {"fornumloop.lua","fornum loops"},
- {"invoke.lua","invokes"},
- {"call.lua","calls"},
- {"string.lua","strings"},
- }
- for k,v in pairs(testnames) do
- local file = io.open("./tests/"..v[1],"r")
- tests[v[2]] = file:read("*a")
- end
+local glum
+describe("Finding GLuM",function()
+ glum = dofile("../src/glum.lua")
end)
-describe("GLuM should", function()
- local glum
- it("initialize without error",function()
- glum = dofile("../src/glum.lua")
- end)
- describe("output non-erroring minified code for",function()
- for k,v in pairs(tests) do
- it(k,function()
- local miniftxt = glum.minify(v)
- local minified = loadstring(miniftxt)
- assert.has_no.errors(minified)
- end)
- end
- end)
+describe("GLuM", function()
+ for k,v in pairs(tests) do
+ local testcode = loadstring(v)
+ testcode()
+ end
end)
diff --git a/test/glum_test.lua b/test/glum_test.lua
index e9447dd..2fdceb9 100644
--- a/test/glum_test.lua
+++ b/test/glum_test.lua
@@ -871,18 +871,21 @@ local str2 = [=[
--[[/////////////////
]]
-local foo = 1
-if foo then print("bar") end
-local function something(foo, bar)
- print("foobar")
-end
-something(foo,4)
+local obj = {}
+obj.subobj = {}
+obj.bar = 1
+obj.subobj.foo = function(foo,fizz)
+ foo.bar = foo.bar + 1
+ print(fizz,foo.bar)
+end
+obj.subobj.foo(obj.subobj,"something")
]=]
-local min = glum.minify(str)
+--local min = glum.minify(str2)
--local comp = ugly.uglify(min)
-print(min)
-print(string.format("Old size:%d\nNew size:%d",#str,#min))
+--print(min)
+--print(string.format("Old size:%d\nNew size:%d",#str,#min))
+print(string.dump(CompileString(str2)()))
--[[
local fuzzel = loadstring(f)()
diff --git a/test/tests/call.lua b/test/tests/call.lua
index 8549b7f..db79cf9 100644
--- a/test/tests/call.lua
+++ b/test/tests/call.lua
@@ -1,4 +1,6 @@
-
+describe("Should minify calls to other functions correctly",function()
+ local minitxt = glum.
+end)
function afunction()
print("You called a function!")
end
diff --git a/test/tests/valid_snippits/call.lua b/test/tests/valid_snippits/call.lua
new file mode 100644
index 0000000..8549b7f
--- /dev/null
+++ b/test/tests/valid_snippits/call.lua
@@ -0,0 +1,22 @@
+
+function afunction()
+ print("You called a function!")
+end
+
+function anotherfunction(num)
+ print("Thanks, I love " .. num .. "!")
+ return num == 0 and 1 or anotherfunction(num-1)
+end
+
+local function yetanotherfunction(num)
+ print("Ew, I don't like " .. num .. ".")
+ return num <= 0 and 1 or yetanotherfunction(num/2)
+end
+
+afunction()
+
+for k = 100,1000,100 do
+ anotherfunction(k)
+end
+
+yetanotherfunction(2000)
diff --git a/test/tests/valid_snippits/forinloop.lua b/test/tests/valid_snippits/forinloop.lua
new file mode 100644
index 0000000..b9ee57b
--- /dev/null
+++ b/test/tests/valid_snippits/forinloop.lua
@@ -0,0 +1,10 @@
+
+local tbl = {
+ "Alpha",
+ "Beta",
+ "Charlie",
+}
+
+for k,v in pairs(tbl) do
+ print(v)
+end
diff --git a/test/tests/valid_snippits/fornumloop.lua b/test/tests/valid_snippits/fornumloop.lua
new file mode 100644
index 0000000..19ee201
--- /dev/null
+++ b/test/tests/valid_snippits/fornumloop.lua
@@ -0,0 +1,10 @@
+
+local tbl = {
+ "Alpha",
+ "Beta",
+ "Charlie",
+}
+
+for k = 1,#tbl do
+ print(v)
+end
diff --git a/test/tests/valid_snippits/invoke.lua b/test/tests/valid_snippits/invoke.lua
new file mode 100644
index 0000000..568bc2d
--- /dev/null
+++ b/test/tests/valid_snippits/invoke.lua
@@ -0,0 +1,12 @@
+local something = {}
+
+something.givenumber = function(self,num)
+ print("Thanks, I love " .. num .. "! It's much better than " .. self.lastnum)
+ self.lastnum = num
+end
+
+something.lastnum = 0
+
+something:givenumber(1)
+something:givenumber(2)
+something:givenumber(10)
diff --git a/test/tests/valid_snippits/string.lua b/test/tests/valid_snippits/string.lua
new file mode 100644
index 0000000..769d528
--- /dev/null
+++ b/test/tests/valid_snippits/string.lua
@@ -0,0 +1,8 @@
+local string = "what"
+
+local tbl = {}
+local tbl2 = {}
+
+tbl[string] = 10
+tbl2.what = 10
+assert(tbl.what == tbl2[string],"Not equal")