From 0fd04fd57f8834c29c832bdab675cd1a509f27f3 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 11 Dec 2019 15:44:03 -0300 Subject: [PATCH] Add app.fs tests --- scripts/app_fs.lua | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 scripts/app_fs.lua diff --git a/scripts/app_fs.lua b/scripts/app_fs.lua new file mode 100644 index 000000000..e34c9e803 --- /dev/null +++ b/scripts/app_fs.lua @@ -0,0 +1,52 @@ +-- Copyright (C) 2019 Igara Studio S.A. +-- +-- This file is released under the terms of the MIT license. +-- Read LICENSE.txt for more information. + +local fs = app.fs +local sep = fs.pathSeparator + +assert('' == fs.filePath('first.png')) +assert('path' == fs.filePath('path/second.png')) +assert('C:\\path' == fs.filePath('C:\\path\\third.png')) + +assert('first.png' == fs.fileName('first.png')) +assert('second.png' == fs.fileName('path/second.png')) +assert('third.png' == fs.fileName('C:\\path\\third.png')) + +assert('first' == fs.fileTitle('first.png')) +assert('second' == fs.fileTitle('path/second.png')) +assert('third' == fs.fileTitle('C:\\path\\third.png')) + +assert('first' == fs.filePathAndTitle('first.png')) +assert('path/second' == fs.filePathAndTitle('path/second.png')) +assert('C:\\path\\third' == fs.filePathAndTitle('C:\\path\\third.png')) + +assert('hi/bye' == fs.joinPath('hi/', 'bye')) +assert('hi/bye' .. sep .. 'smth.png' == fs.joinPath('hi/', 'bye', 'smth.png')) + +local pwd = fs.currentPath +assert(pwd ~= nil) +assert(fs.isDirectory(pwd)) +assert(not fs.isFile(pwd)) +assert(fs.isFile(fs.joinPath(pwd, 'run-tests.sh'))) + +do + local runTestsFound = false + local readmeFound = false + local files = fs.listFiles(pwd) + for i in pairs(files) do + if files[i] == 'run-tests.sh' then + runTestsFound = true + elseif files[i] == 'README.md' then + readmeFound = true + end + + local fullFs = fs.joinPath(pwd, files[i]) + if fs.isFile(fullFs) then + assert(fs.fileSize(fullFs) > 0) + end + end + assert(runTestsFound) + assert(readmeFound) +end