Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorstarkos <none@none>2008-11-13 03:54:41 +0300
committerstarkos <none@none>2008-11-13 03:54:41 +0300
commit4539b1e1b3336b52b77b11696f9664e5ebb0d1e4 (patch)
tree0de78294ad13a7a580075d8e88b1538555e52771 /tests
parentc257e9c746f096ca4294168a8a2c26de538eb36c (diff)
** Merged branches/vstudio (r539:562) Added Visual Studio support
Diffstat (limited to 'tests')
-rw-r--r--tests/premake4.lua3
-rw-r--r--tests/test_config.lua126
-rw-r--r--tests/test_functions.lua6
-rw-r--r--tests/test_os.lua (renamed from tests/test_file.lua)31
-rw-r--r--tests/test_path.lua2
-rw-r--r--tests/test_project.lua244
-rw-r--r--tests/test_string.lua26
-rw-r--r--tests/test_template.lua18
8 files changed, 304 insertions, 152 deletions
diff --git a/tests/premake4.lua b/tests/premake4.lua
index f0bc098..a998db4 100644
--- a/tests/premake4.lua
+++ b/tests/premake4.lua
@@ -6,12 +6,13 @@
dofile("testfx.lua")
dofile("test_dofile.lua")
- dofile("test_file.lua")
+ dofile("test_os.lua")
dofile("test_path.lua")
dofile("test_string.lua")
dofile("test_table.lua")
dofile("test_template.lua")
dofile("test_premake.lua")
+ dofile("test_config.lua")
dofile("test_project.lua")
dofile("test_functions.lua")
diff --git a/tests/test_config.lua b/tests/test_config.lua
new file mode 100644
index 0000000..fa12b0f
--- /dev/null
+++ b/tests/test_config.lua
@@ -0,0 +1,126 @@
+--
+-- tests/test_config.project.lua
+-- Automated test suite for the configuration support functions.
+-- Copyright (c) 2008 Jason Perkins and the Premake project
+--
+
+ T.config = { }
+
+ local cfg
+ function T.config.setup()
+ _ACTION = "gmake"
+ cfg = { }
+ cfg.location = ""
+ cfg.targetname = "MyPackage"
+ cfg.targetdir = ""
+ end
+
+
+--
+-- premake.gettargetfile() tests
+--
+
+ function T.config.gettargetfile_IndexesFieldValues()
+ cfg.implibname = "imports"
+ test.isequal("imports.lib", premake.gettargetfile(cfg, "implib", "StaticLib", "windows"))
+ end
+
+ function T.config.gettargetfile_FallsBackToTargetValues()
+ test.isequal("MyPackage", premake.gettargetfile(cfg, "implib", "ConsoleApp", "linux"))
+ end
+
+ function T.config.gettargetfile_OnWindowsConsole()
+ test.isequal("MyPackage.exe", premake.gettargetfile(cfg, "target", "ConsoleApp", "windows"))
+ end
+
+ function T.config.gettargetfile_OnLinuxConsole()
+ test.isequal("MyPackage", premake.gettargetfile(cfg, "target", "ConsoleApp", "linux"))
+ end
+
+ function T.config.gettargetfile_OnMacOSXConsole()
+ test.isequal("MyPackage", premake.gettargetfile(cfg, "target", "ConsoleApp", "macosx"))
+ end
+
+ function T.config.gettargetfile_OnBSDConsole()
+ test.isequal("MyPackage", premake.gettargetfile(cfg, "target", "ConsoleApp", "bsd"))
+ end
+
+ function T.config.gettargetfile_OnWindowsWindowed()
+ test.isequal("MyPackage.exe", premake.gettargetfile(cfg, "target", "WindowedApp", "windows"))
+ end
+
+ function T.config.gettargetfile_OnLinuxWindowed()
+ test.isequal("MyPackage", premake.gettargetfile(cfg, "target", "WindowedApp", "linux"))
+ end
+
+ function T.config.gettargetfile_OnMacOSXWindowed()
+ test.isequal("MyPackage.app/Contents/MacOS/MyPackage", premake.gettargetfile(cfg, "target", "WindowedApp", "macosx"))
+ end
+
+ function T.config.gettargetfile_OnBSDWindowed()
+ test.isequal("MyPackage", premake.gettargetfile(cfg, "target", "WindowedApp", "bsd"))
+ end
+
+ function T.config.gettargetfile_OnWindowsShared()
+ test.isequal("MyPackage.dll", premake.gettargetfile(cfg, "target", "SharedLib", "windows"))
+ end
+
+ function T.config.gettargetfile_OnLinuxShared()
+ test.isequal("libMyPackage.so", premake.gettargetfile(cfg, "target", "SharedLib", "linux"))
+ end
+
+ function T.config.gettargetfile_OnMacOSXShared()
+ test.isequal("libMyPackage.so", premake.gettargetfile(cfg, "target", "SharedLib", "macosx"))
+ end
+
+ function T.config.gettargetfile_OnBSDShared()
+ test.isequal("libMyPackage.so", premake.gettargetfile(cfg, "target", "SharedLib", "bsd"))
+ end
+
+ function T.config.gettargetfile_OnWindowsStatic()
+ test.isequal("MyPackage.lib", premake.gettargetfile(cfg, "target", "StaticLib", "windows"))
+ end
+
+ function T.config.gettargetfile_OnLinuxStatic()
+ test.isequal("libMyPackage.a", premake.gettargetfile(cfg, "target", "StaticLib", "linux"))
+ end
+
+ function T.config.gettargetfile_OnMacOSXStatic()
+ test.isequal("libMyPackage.a", premake.gettargetfile(cfg, "target", "StaticLib", "macosx"))
+ end
+
+ function T.config.gettargetfile_OnBSDStatic()
+ test.isequal("libMyPackage.a", premake.gettargetfile(cfg, "target", "StaticLib", "bsd"))
+ end
+
+
+
+--
+-- premake.iskeywordsmatch() tests
+--
+
+ function T.config.checkterms_ReturnsTrue_OnInclusion()
+ test.istrue( premake.iskeywordsmatch( {'Debug'}, {'Debug','Windows'} ) )
+ end
+
+ function T.config.checkterms_ReturnsTrue_OnCaseMismatch()
+ test.istrue( premake.iskeywordsmatch( {'Debug'}, {'debug','Windows'} ) )
+ end
+
+ function T.config.checkterms_MatchesPatterns()
+ test.istrue( premake.iskeywordsmatch( {'vs200%d'}, {'VS2005'} ) )
+ end
+
+ function T.config.checkterms_ReturnsFalse_OnNoTermsAndKeywords()
+ test.isfalse( premake.iskeywordsmatch( {'Debug'}, {} ) )
+ end
+
+ function T.config.checkterms_ReturnsTrue_OnNoTermsOrKeywords()
+ test.istrue( premake.iskeywordsmatch( {}, {} ) )
+ end
+
+ function T.config.checkterms_ReturnsTrue_OnTermsAndNoKeywords()
+ test.istrue ( premake.iskeywordsmatch( {}, {'Debug'} ) )
+ end
+
+
diff --git a/tests/test_functions.lua b/tests/test_functions.lua
index 6396223..75ee42b 100644
--- a/tests/test_functions.lua
+++ b/tests/test_functions.lua
@@ -132,3 +132,9 @@
test.istrue(prj == project("MyProject"))
end
+ function T.functions.project_SetsUUID()
+ local prj = project "MyProject"
+ test.istrue(prj.uuid)
+ end
+
+ \ No newline at end of file
diff --git a/tests/test_file.lua b/tests/test_os.lua
index e6b1415..08dcef9 100644
--- a/tests/test_file.lua
+++ b/tests/test_os.lua
@@ -7,13 +7,13 @@
T.os = { }
-
+
--
-- os.isfile() tests
--
function T.os.isfile_ReturnsTrue_OnExistingFile()
- test.istrue(os.isfile("test_file.lua"))
+ test.istrue(os.isfile("test_os.lua"))
end
function T.os.isfile_ReturnsFalse_OnNonexistantFile()
@@ -21,6 +21,7 @@
end
+
--
-- os.pathsearch() tests
--
@@ -30,14 +31,32 @@
end
function T.os.pathsearch_ReturnsPath_OnFound()
- test.isequal(os.getcwd(), os.pathsearch("test_file.lua", os.getcwd()))
+ test.isequal(os.getcwd(), os.pathsearch("test_os.lua", os.getcwd()))
end
function T.os.pathsearch_FindsFile_OnComplexPath()
- test.isequal(os.getcwd(), os.pathsearch("test_file.lua", "aaa;"..os.getcwd()..";bbb"))
+ test.isequal(os.getcwd(), os.pathsearch("test_os.lua", "aaa;"..os.getcwd()..";bbb"))
end
function T.os.pathsearch_NilPathsAllowed()
- test.isequal(os.getcwd(), os.pathsearch("test_file.lua", nil, os.getcwd(), nil))
+ test.isequal(os.getcwd(), os.pathsearch("test_os.lua", nil, os.getcwd(), nil))
+ end
+
+
+--
+-- os.uuid() tests
+--
+
+ function T.os.guid_ReturnsValidUUID()
+ local g = os.uuid()
+ test.istrue(#g == 36)
+ for i=1,36 do
+ local ch = g:sub(i,i)
+ test.istrue(ch:find("[ABCDEF0123456789-]"))
+ end
+ test.isequal("-", g:sub(9,9))
+ test.isequal("-", g:sub(14,14))
+ test.isequal("-", g:sub(19,19))
+ test.isequal("-", g:sub(24,24))
end
- \ No newline at end of file
+
diff --git a/tests/test_path.lua b/tests/test_path.lua
index 5b6931b..944b930 100644
--- a/tests/test_path.lua
+++ b/tests/test_path.lua
@@ -134,7 +134,7 @@
function T.path.translate_ReturnsCorrectSeparator_OnMixedPath()
local actual = path.translate("dir\\dir/file")
- if (os.windows) then
+ if (os.is("windows")) then
test.isequal("dir\\dir\\file", actual)
else
test.isequal("dir/dir/file", actual)
diff --git a/tests/test_project.lua b/tests/test_project.lua
index e2a4a20..f8e5cd8 100644
--- a/tests/test_project.lua
+++ b/tests/test_project.lua
@@ -1,5 +1,5 @@
--
--- tests/test_project.lua
+-- tests/test_project.project.lua
-- Automated test suite for the project support functions.
-- Copyright (c) 2008 Jason Perkins and the Premake project
--
@@ -7,28 +7,26 @@
T.project = { }
- local cfg
+ local result
function T.project.setup()
_ACTION = "gmake"
- cfg = { }
- cfg.location = ""
- cfg.targetname = "MyPackage"
- cfg.targetdir = ""
+ result = ""
end
+
--
--- project.checkall() tests
+-- premake.checkprojects() tests
--
function T.project.checkall_Succeeds_OnValidSession()
solution "MySolution"
configurations "Default"
project "MyProject"
- kind "ConsoleExe"
+ kind "ConsoleApp"
language "C"
- ok, err = premake.project.checkall()
+ ok, err = premake.checkprojects()
test.istrue( ok )
end
@@ -37,7 +35,7 @@
solution "MySolution"
project "MyProject"
- ok, err = premake.project.checkall()
+ ok, err = premake.checkprojects()
test.isfalse( ok )
test.isequal("solution 'MySolution' needs configurations", err)
end
@@ -47,7 +45,7 @@
solution "MySolution"
configurations "Default"
- ok, err = premake.project.checkall()
+ ok, err = premake.checkprojects()
test.isfalse( ok )
test.isequal("solution 'MySolution' needs at least one project", err)
end
@@ -57,9 +55,9 @@
solution "MySolution"
configurations "Default"
project "MyProject"
- kind "ConsoleExe"
+ kind "ConsoleApp"
- ok, err = premake.project.checkall()
+ ok, err = premake.checkprojects()
test.isfalse( ok )
test.isequal("project 'MyProject' needs a language", err)
end
@@ -71,7 +69,7 @@
configurations "Default"
project "MyProject"
- ok, err = premake.project.checkall()
+ ok, err = premake.checkprojects()
test.isfalse( ok )
test.isequal("project 'MyProject' needs a kind in configuration 'Default'", err)
end
@@ -81,11 +79,11 @@
solution "MySolution"
configurations "Default"
prj = project "MyProject"
- kind "ConsoleExe"
+ kind "ConsoleApp"
prj.language = "XXX"
- ok, err = premake.project.checkall()
+ ok, err = premake.checkprojects()
test.isfalse(ok)
test.isequal("the GNU Make action does not support XXX projects", err)
end
@@ -99,7 +97,7 @@
prj.kind = "YYY"
- ok, err = premake.project.checkall()
+ ok, err = premake.checkprojects()
test.isfalse(ok)
test.isequal("the GNU Make action does not support YYY projects", err)
end
@@ -107,165 +105,57 @@
--
--- project.checkterms() tests
---
-
- function T.project.checkterms_ReturnsTrue_OnInclusion()
- test.istrue( premake.project.checkterms( {'Debug','Windows'}, {'Debug'} ) )
- end
-
- function T.project.checkterms_ReturnsTrue_OnCaseMismatch()
- test.istrue( premake.project.checkterms( {'debug','Windows'}, {'Debug'} ) )
- end
-
- function T.project.checkterms_MatchesPatterns()
- test.istrue( premake.project.checkterms( {'VS2005'}, {'vs200%d'} ) )
- end
-
- function T.project.checkterms_ReturnsFalse_OnNoTermsAndKeywords()
- test.isfalse( premake.project.checkterms( {}, {'Debug'} ) )
- end
-
- function T.project.checkterms_ReturnsTrue_OnNoTermsOrKeywords()
- test.istrue( premake.project.checkterms( {}, {} ) )
- end
-
- function T.project.checkterms_ReturnsTrue_OnTermsAndNoKeywords()
- test.istrue ( premake.project.checkterms( {'Debug'}, {} ) )
- end
-
-
---
-- project.getobject() tests
--
function T.project.getobject_RaisesError_OnNoContainer()
premake.CurrentContainer = nil
- c, err = premake.project.getobject("container")
+ c, err = premake.getobject("container")
test.istrue(c == nil)
test.isequal("no active solution or project", err)
end
function T.project.getobject_RaisesError_OnNoActiveSolution()
premake.CurrentContainer = { }
- c, err = premake.project.getobject("solution")
+ c, err = premake.getobject("solution")
test.istrue(c == nil)
test.isequal("no active solution", err)
end
function T.project.getobject_RaisesError_OnNoActiveConfig()
premake.CurrentConfiguration = nil
- c, err = premake.project.getobject("config")
+ c, err = premake.getobject("config")
test.istrue(c == nil)
test.isequal("no active solution, project, or configuration", err)
end
--
--- project.gettargetfile() tests
---
-
- function T.project.gettargetfile_IndexesFieldValues()
- cfg.implibname = "imports"
- test.isequal("imports.lib", premake.project.gettargetfile(cfg, "implib", "StaticLib", "windows"))
- end
-
- function T.project.gettargetfile_FallsBackToTargetValues()
- test.isequal("MyPackage", premake.project.gettargetfile(cfg, "implib", "ConsoleExe", "linux"))
- end
-
- function T.project.gettargetfile_OnWindowsConsole()
- test.isequal("MyPackage.exe", premake.project.gettargetfile(cfg, "target", "ConsoleExe", "windows"))
- end
-
- function T.project.gettargetfile_OnLinuxConsole()
- test.isequal("MyPackage", premake.project.gettargetfile(cfg, "target", "ConsoleExe", "linux"))
- end
-
- function T.project.gettargetfile_OnMacOSXConsole()
- test.isequal("MyPackage", premake.project.gettargetfile(cfg, "target", "ConsoleExe", "macosx"))
- end
-
- function T.project.gettargetfile_OnBSDConsole()
- test.isequal("MyPackage", premake.project.gettargetfile(cfg, "target", "ConsoleExe", "bsd"))
- end
-
- function T.project.gettargetfile_OnWindowsWindowed()
- test.isequal("MyPackage.exe", premake.project.gettargetfile(cfg, "target", "WindowedExe", "windows"))
- end
-
- function T.project.gettargetfile_OnLinuxWindowed()
- test.isequal("MyPackage", premake.project.gettargetfile(cfg, "target", "WindowedExe", "linux"))
- end
-
- function T.project.gettargetfile_OnMacOSXWindowed()
- test.isequal("MyPackage.app/Contents/MacOS/MyPackage", premake.project.gettargetfile(cfg, "target", "WindowedExe", "macosx"))
- end
-
- function T.project.gettargetfile_OnBSDWindowed()
- test.isequal("MyPackage", premake.project.gettargetfile(cfg, "target", "WindowedExe", "bsd"))
- end
-
- function T.project.gettargetfile_OnWindowsShared()
- test.isequal("MyPackage.dll", premake.project.gettargetfile(cfg, "target", "SharedLib", "windows"))
- end
-
- function T.project.gettargetfile_OnLinuxShared()
- test.isequal("libMyPackage.so", premake.project.gettargetfile(cfg, "target", "SharedLib", "linux"))
- end
-
- function T.project.gettargetfile_OnMacOSXShared()
- test.isequal("libMyPackage.so", premake.project.gettargetfile(cfg, "target", "SharedLib", "macosx"))
- end
-
- function T.project.gettargetfile_OnBSDShared()
- test.isequal("libMyPackage.so", premake.project.gettargetfile(cfg, "target", "SharedLib", "bsd"))
- end
-
- function T.project.gettargetfile_OnWindowsStatic()
- test.isequal("MyPackage.lib", premake.project.gettargetfile(cfg, "target", "StaticLib", "windows"))
- end
-
- function T.project.gettargetfile_OnLinuxStatic()
- test.isequal("libMyPackage.a", premake.project.gettargetfile(cfg, "target", "StaticLib", "linux"))
- end
-
- function T.project.gettargetfile_OnMacOSXStatic()
- test.isequal("libMyPackage.a", premake.project.gettargetfile(cfg, "target", "StaticLib", "macosx"))
- end
-
- function T.project.gettargetfile_OnBSDStatic()
- test.isequal("libMyPackage.a", premake.project.gettargetfile(cfg, "target", "StaticLib", "bsd"))
- end
-
-
-
---
-- premake.setstring() tests
--
function T.project.setstring_Sets_OnNewProperty()
premake.CurrentConfiguration = { }
- premake.project.setstring("config", "myfield", "hello")
+ premake.setstring("config", "myfield", "hello")
test.isequal("hello", premake.CurrentConfiguration.myfield)
end
function T.project.setstring_Overwrites_OnExistingProperty()
premake.CurrentConfiguration = { }
premake.CurrentConfiguration.myfield = "hello"
- premake.project.setstring("config", "myfield", "goodbye")
+ premake.setstring("config", "myfield", "goodbye")
test.isequal("goodbye", premake.CurrentConfiguration.myfield)
end
function T.project.setstring_RaisesError_OnInvalidValue()
premake.CurrentConfiguration = { }
- ok, err = pcall(function () premake.project.setstring("config", "myfield", "bad", { "Good", "Better", "Best" }) end)
+ ok, err = pcall(function () premake.setstring("config", "myfield", "bad", { "Good", "Better", "Best" }) end)
test.isfalse(ok)
end
function T.project.setstring_CorrectsCase_OnConstrainedValue()
premake.CurrentConfiguration = { }
- premake.project.setstring("config", "myfield", "better", { "Good", "Better", "Best" })
+ premake.setstring("config", "myfield", "better", { "Good", "Better", "Best" })
test.isequal("Better", premake.CurrentConfiguration.myfield)
end
@@ -277,14 +167,14 @@
function T.project.setarray_Inserts_OnStringValue()
premake.CurrentConfiguration = { }
premake.CurrentConfiguration.myfield = { }
- premake.project.setarray("config", "myfield", "hello")
+ premake.setarray("config", "myfield", "hello")
test.isequal("hello", premake.CurrentConfiguration.myfield[1])
end
function T.project.setarray_Inserts_OnTableValue()
premake.CurrentConfiguration = { }
premake.CurrentConfiguration.myfield = { }
- premake.project.setarray("config", "myfield", { "hello", "goodbye" })
+ premake.setarray("config", "myfield", { "hello", "goodbye" })
test.isequal("hello", premake.CurrentConfiguration.myfield[1])
test.isequal("goodbye", premake.CurrentConfiguration.myfield[2])
end
@@ -292,7 +182,7 @@
function T.project.setarray_Appends_OnNewValues()
premake.CurrentConfiguration = { }
premake.CurrentConfiguration.myfield = { "hello" }
- premake.project.setarray("config", "myfield", "goodbye")
+ premake.setarray("config", "myfield", "goodbye")
test.isequal("hello", premake.CurrentConfiguration.myfield[1])
test.isequal("goodbye", premake.CurrentConfiguration.myfield[2])
end
@@ -300,7 +190,7 @@
function T.project.setarray_FlattensTables()
premake.CurrentConfiguration = { }
premake.CurrentConfiguration.myfield = { }
- premake.project.setarray("config", "myfield", { {"hello"}, {"goodbye"} })
+ premake.setarray("config", "myfield", { {"hello"}, {"goodbye"} })
test.isequal("hello", premake.CurrentConfiguration.myfield[1])
test.isequal("goodbye", premake.CurrentConfiguration.myfield[2])
end
@@ -308,14 +198,92 @@
function T.project.setarray_RaisesError_OnInvalidValue()
premake.CurrentConfiguration = { }
premake.CurrentConfiguration.myfield = { }
- ok, err = pcall(function () premake.project.setarray("config", "myfield", "bad", { "Good", "Better", "Best" }) end)
+ ok, err = pcall(function () premake.setarray("config", "myfield", "bad", { "Good", "Better", "Best" }) end)
test.isfalse(ok)
end
function T.project.setarray_CorrectsCase_OnConstrainedValue()
premake.CurrentConfiguration = { }
premake.CurrentConfiguration.myfield = { }
- premake.project.setarray("config", "myfield", "better", { "Good", "Better", "Best" })
+ premake.setarray("config", "myfield", "better", { "Good", "Better", "Best" })
test.isequal("Better", premake.CurrentConfiguration.myfield[1])
end
+
+--
+-- premake.walksources() tests
+--
+
+ local function walktest(prj, fname, state, nestlevel)
+ local item
+ if (state == "GroupStart") then
+ item = "<" .. fname .. ">"
+ elseif (state == "GroupEnd") then
+ item = "</" .. fname .. ">"
+ else
+ item = fname
+ end
+ result = result .. string.rep("-", nestlevel) .. item
+ end
+
+ function T.project.walksources_OnNoFiles()
+ premake.walksources({}, {}, walktest)
+ test.isequal(
+ ""
+ ,result)
+ end
+
+ function T.project.walksources_OnSingleFile()
+ local files = {
+ "hello.cpp"
+ }
+ premake.walksources({}, files, walktest)
+ test.isequal(
+ "hello.cpp"
+ ,result)
+ end
+
+ function T.project.walksources_OnNestedGroups()
+ local files = {
+ "rootfile.c",
+ "level1/level1.c",
+ "level1/level2/level2.c"
+ }
+ premake.walksources({}, files, walktest)
+ test.isequal(""
+ .. "<level1>"
+ .. "-<level1/level2>"
+ .. "--level1/level2/level2.c"
+ .. "-</level1/level2>"
+ .. "-level1/level1.c"
+ .. "</level1>"
+ .. "rootfile.c"
+ ,result)
+ end
+
+ function T.project.walksources_OnDottedFolders()
+ local files = {
+ "src/lua-5.1.2/lapi.c"
+ }
+ premake.walksources({}, files, walktest)
+ test.isequal(""
+ .. "<src>"
+ .. "-<src/lua-5.1.2>"
+ .. "--src/lua-5.1.2/lapi.c"
+ .. "-</src/lua-5.1.2>"
+ .. "</src>"
+ ,result)
+ end
+
+ function T.project.walksources_OnDotDotLeaders()
+ local files = {
+ "../src/hello.c",
+ }
+ premake.walksources({}, files, walktest)
+ test.isequal(""
+ .. "<../src>"
+ .. "-../src/hello.c"
+ .. "</../src>"
+ ,result)
+ end
+ \ No newline at end of file
diff --git a/tests/test_string.lua b/tests/test_string.lua
index 3ce1f1f..1d8081d 100644
--- a/tests/test_string.lua
+++ b/tests/test_string.lua
@@ -41,3 +41,29 @@
function T.string.explode_ReturnsParts_OnValidCall()
test.isequal({"aaa","bbb","ccc"}, string.explode("aaa/bbb/ccc", "/", true))
end
+
+
+
+--
+-- string.startswith() tests
+--
+
+ function T.string.startswith_OnMatch()
+ test.istrue(string.startswith("Abcdef", "Abc"))
+ end
+
+ function T.string.startswith_OnMismatch()
+ test.isfalse(string.startswith("Abcdef", "ghi"))
+ end
+
+ function T.string.startswith_OnLongerNeedle()
+ test.isfalse(string.startswith("Abc", "Abcdef"))
+ end
+
+ function T.string.startswith_OnEmptyHaystack()
+ test.isfalse(string.startswith("", "Abc"))
+ end
+
+ function T.string.startswith_OnEmptyNeedle()
+ test.istrue(string.startswith("Abcdef", ""))
+ end
diff --git a/tests/test_template.lua b/tests/test_template.lua
index a11de5f..b2acf6a 100644
--- a/tests/test_template.lua
+++ b/tests/test_template.lua
@@ -16,30 +16,36 @@
--
--- template.encode() tests
+-- premake.encodetemplate() tests
--
function T.template.encode_SimpleString()
t = "Hi there"
- test.isequal("io.write[=[Hi there]=]", premake.template.encode(t))
+ test.isequal("io.write[=[Hi there]=]", premake.encodetemplate(t))
end
function T.template.encode_TrailingNewline()
t = "Line 1\n"
- test.isequal("io.write[=[Line 1]=]io.write(eol)\n", premake.template.encode(t))
+ test.isequal("io.write[=[Line 1]=]io.write(eol)\n", premake.encodetemplate(t))
end
function T.template.encode_LeadingNewlines()
t = "\nLine 1"
- test.isequal("io.write(eol)\nio.write[=[Line 1]=]", premake.template.encode(t))
+ test.isequal("io.write(eol)\nio.write[=[Line 1]=]", premake.encodetemplate(t))
end
function T.template.encode_InlineExpression()
t = "Name is <%= this.name %>\nAnother Line"
- test.isequal("io.write[=[Name is ]=]io.write( this.name )io.write(eol)\nio.write[=[Another Line]=]", premake.template.encode(t))
+ test.isequal("io.write[=[Name is ]=]io.write( this.name )io.write(eol)\nio.write[=[Another Line]=]", premake.encodetemplate(t))
end
function T.template.encode_InlineStatement()
t = "Start\n <% for i=1,10 do %> \n item\n <%end%> \nDone\n"
- test.isequal("io.write[=[Start]=]io.write(eol)\n for i=1,10 do \nio.write[=[ item]=]io.write(eol)\nend\nio.write[=[Done]=]io.write(eol)\n", premake.template.encode(t))
+ test.isequal("io.write[=[Start]=]io.write(eol)\n for i=1,10 do \nio.write[=[ item]=]io.write(eol)\nend\nio.write[=[Done]=]io.write(eol)\n", premake.encodetemplate(t))
end
+
+ function T.template.encode_DoesTrimLeadingWhitespaceOnSequentialCodeLines()
+ t = " <%i = 1%> \n <%i = 2%> \n"
+ test.isequal("i = 1\ni = 2\n", premake.encodetemplate(t))
+ end
+ \ No newline at end of file